Spring:ModelMap属性没有在jsp中显示

时间:2017-09-08 18:13:57

标签: spring jsp spring-mvc

我尝试从控制器传递到视图的数据显然被忽略了。控制台不输出任何错误。有人能指出我做的那个明显的错误吗?

控制器

@RequestMapping("/notes")
public String index(ModelMap model) {
    String test = "Hello Felix";
    model.addAttribute("hello", test);

    return "notes";
}

查看

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Notes</title>
</head>
<body>
    <h1>${hello}</h1>
</body>
</html>

HTML来源

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Notes</title>
</head>
<body>
    <h1></h1>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要返回模型,以下内容应该起作用:

Map model = ...
model.put(name, value);
return new ModelAndView(view, model);