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
}