【问题标题】:encode form parameter in thymeleaf + spring boot在thymeleaf + spring boot中编码表单参数
【发布时间】:2018-10-02 22:38:40
【问题描述】:

我在一个项目中使用 spring boot 和 thymeleaf,我在 URL 中发送一些参数,例如“Historique/stock?devise=EUR”
我想知道是否有一个全局配置来编码 url 和我的控制器中的参数来解码它

谢谢你:)

更新:

<tbody>
                    <tr th:each="agence : ${listeAgences}">
                        <td><input th:type="checkbox" th:name="selected"
                            th:value="${agence?.id}" /></td>
                        <td><a class="btn-outline-primary"
                            th:href="@{'/admin/Agence/visualisationAgence?id='+${agence.id}}"><th:block
                                    th:text="${agence?.nom}" /></a></td>
                    </tr>
                </tbody>

这是我的控制器

    @RequestMapping(value = "/visualisationAgence", method = RequestMethod.GET)
public ModelAndView visualisationAgence(ModelAndView modelAndView, String id) {
    AgenceDTO agence = agenceService.findAgenceById(Integer.parseInt(id));

如您所见,我正在传递未编码的 id,我不知道是否有一个全局方法如何对其进行编码然后读取它,因此用户无法在 url 中看到 id

【问题讨论】:

    标签: spring spring-boot spring-security thymeleaf


    【解决方案1】:

    像这样在 Thymeleaf 中指定 URL 参数:

    <a th:href="@{/admin/Agence/visualisationAgence(id=${agence.id})">
    

    详情请见Standard URL Syntax

    然后用@RequestParam注解在控制器中“解码”:

    public ModelAndView visualisationAgence(@RequestParam("id") String id, ...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-14
      • 2021-09-03
      • 1970-01-01
      • 2014-09-29
      • 2019-03-25
      • 2017-06-11
      • 2020-12-16
      • 2016-08-24
      相关资源
      最近更新 更多