SpringMVC响应之返回值是String类型
UserController.java
package cn.itcast.controller; import cn.itcast.domain.User; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/user") public class UserController { @RequestMapping("/testString") public String testString(Model model) { System.out.println("testString方法执行了..."); //模拟从数据库中取出User对象 User user = new User(); user.setUsername("美美"); user.setPassword("123"); user.setAge(30); //model对象 model.addAttribute("user",user); return "success"; } }success.jsp
<%-- Created by IntelliJ IDEA. User: hp Date: 2019/11/3 Time: 21:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h3>执行成功</h3> ${user.username} ${user.password} </body> </html>