1、Controller传值
@Controller
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("/list")
public String list(HttpServletRequest request,Model model){
model.addAttribute("msg","传值");
List<User> userList=userService.findAllUser(new User());
model.addAttribute("userList",userList);
return "user/list";
}
}
2、Thymeleaf接收值
(1)html获取
<span th:text="${msg}"></span>
<tr th:each="user : ${userList}">
<td>
<a href="#" th:text="${user.getName()}">...</a>
</td>
<td th:text="${user.getAge()}">1</td>
</tr>
(2)js获取
var msg=[[${msg}]];