随笔 - 58  文章 - 0  评论 - 1  阅读 - 17万

使用Thymeleaf在前台无法显示页面问题

  controller中的代码如下:问题  返回值类型为@RestController时,直接转换为了json字符串,就无法返回thymeleaf页面,改为@Controller即可

@RestController
@RequestMapping("user")
public class UserController {

@Autowired
private UserService userService;

@GetMapping("all")
public String all(Model model) {
// 查询用户
List<User> users = this.userService.queryAll();
// 放入模型
model.addAttribute("users", users);
// 返回模板名称(就是classpath:/templates/目录下的html文件名)
return "users";

}
}
posted on   supress_Elon_Musk  阅读(1717)  评论(0编辑  收藏  举报
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示