控制器:
package com.awaimai.web; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.validation.Valid; @Controller @Validated public class kzq { @RequestMapping(value = "/test3") public ModelAndView test3() { ModelAndView view = new ModelAndView(); view.addObject("name","lss"); view.setViewName("index"); //返回的文件名 return view; } }
html:
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"</html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <div> name: <span th:text="${name}"/></div> </div> </body> </html>
web访问: