码迷,mamicode.com
首页 > 编程语言 > 详细

Spring boot + thymeleaf th:href带参跳转及接受

时间:2021-01-04 10:36:42      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:tail   stp   lan   epo   boot   div   ref   ppi   ble   

一、
  前端(<a th:href="@{‘/record_details/‘+${record.id}}" target="_blank"></a>:
<a th:href="@{‘/record_details/‘+${record.id}}" target="_blank">        
    <i><img th:src="@{imgs/default.jpg}" alt="标题图片"></i>
    <h2 th:text="${record.title}">Title</h2>
</a>

  后端( @PathVariable(name="recordId") int recordId ):

@GetMapping("/record_details/{recordId}")
    public String showRecordDetails(Model model, @PathVariable(name="recordId") int recordId) {
        System.out.println("_______________________"+recordId+"______________________");
        pens.Record record = recordRepository.findOne(recordId);
        System.out.println(record);
        model.addAttribute("recorddetail", record);
        return "record_details";
    }

二、

  前端(<a th:href="@{/record_details(recordId=${record.id})}" target="_blank">):

<a th:href="@{/record_details(recordId=${record.id})}" target="_blank">
    <i><img th:src="@{imgs/default.jpg}" alt="标题图片"></i>
    <h2 th:text="${record.title}">Title</h2>
</a>

 

  后端(@RequestParam(name="recordId") int recordId):

@GetMapping("/record_details")
    public String showRecordDetails(Model model, @RequestParam(name="recordId") int recordId) {
        System.out.println("_______________________"+recordId+"______________________");
        pens.Record record = recordRepository.findOne(recordId);
        System.out.println(record);
        model.addAttribute("recorddetail", record);
        return "record_details";
    }

 

Spring boot + thymeleaf th:href带参跳转及接受

标签:tail   stp   lan   epo   boot   div   ref   ppi   ble   

原文地址:https://www.cnblogs.com/Sahara-Iceland/p/14210037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!