Java SPRING MVC:返回的模型和视图/参数优先级
我是春天的新手,我正试图更好地理解MVC框架。 考虑到以下几点:Java SPRING MVC:返回的模型和视图/参数优先级,java,spring,spring-mvc,model-view-controller,Java,Spring,Spring Mvc,Model View Controller,我是春天的新手,我正试图更好地理解MVC框架。 考虑到以下几点: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Conten
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World!</title>
</head>
<body>
Welcome <%=request.getAttribute("username")%>
</body>
</html>
它使用插入到模型中的值作为用户名
值
但是,如果我同时声明模型
参数并返回模型和视图
对象,则:
@GetMapping("/EntryPoint2")
public ModelAndView helloView2(Model model) {
model.addAttribute("username", "pluto");
ModelAndView mav = new ModelAndView("HelloWorld");
mav.addObject("username", "paperino");
return mav;
}
我得到视图使用的值是mav
中包含的值,忽略model
中的值。对此是否有解释(例如,视图所考虑的对象之间有任何类型的优先级)
@GetMapping("/EntryPoint2")
public ModelAndView helloView2(Model model) {
model.addAttribute("username", "pluto");
ModelAndView mav = new ModelAndView("HelloWorld");
mav.addObject("username", "paperino");
return mav;
}