Is the annotation @RestController used in the controller layer?
@RestController annotation is equivalent to the combined effect of @ResponseBody + @Controller. If you just use the @RestController annotation, you cannot return jsp and html pages, because the @RestController annotation is used to return JSON data or XML data, and will not parse jsp, html and other pages. The returned content is the content in return. Such as:
@RestController
public class UserController {
@Resource
private UserService userService;
//查询所有
@RequestMapping("/list")
public String userList(Model model){
List<User> users = userService.findAll();
model.addAttribute("users",users);
return "index";
}
The result after running in the browser is:
Change the @RestController annotation to @Controller page to display normally:
//@RestController
@Controller
public class UserController {
@Resource
private UserService userService;
//查询所有
@RequestMapping("/list")
public String userList(Model model){
List<User> users = userService.findAll();
model.addAttribute("users",users);
return "index";
}