SpringMVC把信息返回到view的两种方式

    @RequestMapping("/list")
    public ModelAndView list() {
        ModelAndView view = new ModelAndView("list");
        List<Task> tasks = taskService.createTaskQuery().list();
        view.addObject("tasks", tasks);
        view.addObject("message", "This is a message.");
        return view;
    }
    @RequestMapping("/list1")
    public String list(Model view) {
        List<Task> tasks = taskService.createTaskQuery().list();
        view.addAttribute("tasks", tasks);
        view.addAttribute("message", "This is a message.");
        return "list";
    }





<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
    <title></title>
</head>
<body>
${tasks}
</body>
</html>

你可能感兴趣的:(springMVC)