Search code examples
springspring-bootspring-securitythymeleaf

encode form parameter in thymeleaf + spring boot


i'm using spring boot and thymeleaf for a project, i send some parameters in the url like this "Historique/stock?devise=EUR"
i'm wondering if there is a global configuration to encode the parameters in the url and in my controller to decode it

thank you :)

UPDATE :

<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>

And here is my controller

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

as You can see i'm passing the id it's not encoded , i dont know if there is a global method how to encode it then read it , so the user can't see the id in the url


Solution

  • Specify URL parameter in Thymeleaf like this:

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

    See Standard URL Syntax for details.

    Then "decode" in controller with @RequestParam annotation:

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