原因:使用这两个注解表示返回数据,而不是视图。
详见:https://blog.csdn.net/sunshine_YG/article/details/80461437
@GetMapping("/user/getone")
public String getOneUser(Model model){
User user = userMapper.selectOneUser(1);
model.addAttribute(user);
return "user";
}
@GetMapping("/user/getone2")
public String getOneUser2(ModelMap modelMap){
User user = userMapper.selectOneUser(1);
modelMap.addAttribute(user);
return "user";
}
@GetMapping("/user/getone3")
public ModelAndView getOneUser3(){
User user = userMapper.selectOneUser(1);
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("user");
modelAndView.addObject(user);
return modelAndView;
}
<%@ page contentType="text/html; UTF-8" language="java" %>
sunshine
${user.id}
${user.name}
${user.sex}