使用springboot+thymeleaf静态页面,return “xxx”无法跳转

不能使用@RestController,更换成@Controller

以下是一个简单的Spring Boot + Thymeleaf的歌单页面跳转到歌单详情页面的示例代码: 1. 在Controller中定义一个请求映射方法,用于返回歌单页面的模板名称和数据: ``` @GetMapping("/playlists") public String getPlaylists(Model model) { List<Playlist> playlists = playlistService.getAllPlaylists(); model.addAttribute("playlists", playlists); return "playlist"; } ``` 2. 在歌单页面模板中,使用Thymeleaf的循环语句将歌单列表展示出来,并为每个歌单添加一个链接,用于跳转到歌单详情页面: ``` <table> <thead> <tr> <th>歌单名称</th> <th>创建时间</th> <th>操作</th> </tr> </thead> <tbody> <tr th:each="playlist : ${playlists}"> <td th:text="${playlist.name}"></td> <td th:text="${playlist.createTime}"></td> <td> <a th:href="@{/playlist/{id}(id=${playlist.id})}">查看详情</a> </td> </tr> </tbody> </table> ``` 3. 在Controller中定义另一个请求映射方法,用于返回歌单详情页面的模板名称和数据: ``` @GetMapping("/playlist/{id}") public String getPlaylistDetail(@PathVariable Long id, Model model) { Playlist playlist = playlistService.getPlaylistById(id); model.addAttribute("playlist", playlist); return "playlistDetail"; } ``` 4. 在歌单详情页面模板中,使用Thymeleaf展示歌单的详细信息: ``` <h2 th:text="${playlist.name}"></h2> <p th:text="${playlist.createTime}"></p> <p th:text="${playlist.description}"></p> ``` 以上就是一个简单的Spring Boot + Thymeleaf的歌单页面跳转到歌单详情页面的全部代码。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值