首页 > 编程语言 > 详细

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

时间:2020-12-30 11:20:24      阅读:45      评论:0      收藏:0      [点我收藏+]
一、
  前端(<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带参跳转及接受

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!