The controller method returns a string to specify the logical view name, which is resolved into the physical view address by the view resolver.
Example:
/**
* 返回String
* @param model
* @return
*///指定逻辑视图名,经过视图解析器解析为 jsp 物理路径:/WEB-INF/pages/success.jsp@RequestMapping("/testString")public String testString(Model model){
System.out.println("testString方法执行了...");// 模拟从数据库中查询出User对象
User user =newUser();
user.setUsername("xww");
user.setPassword("123");
user.setAge(20);// model对象
model.addAttribute("user",user);return"success";}
<ahref="user/testString">testString</a>
38.1.2 The return value is void
If the return value of the controller method is written as void, the execution program reports a 404 exception, and the JSP page is not found by default.
By default, it will jump to the @RequestMapping(value="/initUpdate") initUpdate page.
You can use request forwarding or redirection to jump to the specified page
DispatcherServlet will intercept all resources, causing a problem that static resources (img, css, js) will also be intercepted and cannot be used. To solve the problem, you need to configure static resources without interception. Add the following configuration to the springmvc.xml configuration file:
mvc:resourcesLabel configuration does not filter
The location element represents all files under the package in the webapp directory
The mapping element represents all request paths beginning with /static, such as /static/a or /static/a/b