Request 404 after spring boot creation

question

follow the online tutorial maven to create a new index.html file after creating a spring boot project jquery GET request is either 404 or failed

:@RequestMapping("/hi")  
jquery:url: "http://localhost:8888/hi",

reference is as follows: https://blog.csdn.net/webzhuc.

Mar.21,2021

whether you need to join the template engine to request the page or the restful interface


did not see your code, I boldly guess that the problem may occur in step 3. Testing the Spring Boot application, for convenience reasons in his demo, main and Ctrl are merged into one class. I give a separate way to write it here:

/**
 * Spring Boot
 */
@SpringBootApplication
public class DemoApplication{
    public static void main(String[] args){
        SpringApplication.run(DemoApplication.class, args);
    }

}

create a DemoCtrl class at the same level of the entry class or below, as follows:

@Controller
@RequestMapping("/")
public class DemoCtrl{
    /**
     * web rounter
     */
     @RequestMapping("/hi")
     public String hello(ModelMap map){
         return "index";
     }
}

then create your index.html file in the template directory under resource, start the project, and you should see hello spring boot

update . Here's a point to note: the difference between @ RestController and @ Controller facing Web.
if you use the @ RestController annotation, you should use something like this:

@RequestMapping("hi")
public ModelAndView hello(){
    return new ModelAndView("index");//index.html template
}

if you use the @ Controller annotation, you can map to view correctly in the first way.

Update again
if it is Spring MVC, you need to write all the view files when the default view engine is not configured, as follows:

/**
     * web rounter
     */
     @RequestMapping("/hi")
     public String hello(ModelMap map){
         return "index.jsp"; // jsp
     }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7abea2-1584d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7abea2-1584d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?