简体   繁体   中英

How do I pass a parameter in a string in thymeleaf

I am trying to delete an item on a list by passing the task ID in an a href link in thymeleaf. This is what it looks like

<a th:href="@{'delete-task?id='${task.id}}"> 

But instead of deleting the item this is the output

delete-task?id=th:text=%27${task.id}%27

Im getting this error in the slack trace

 : Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
Can anyone tell me the correct syntax

You should be using thymeleaf's Standard URL Syntax for links -- so that parameters can be correctly url escaped. Your link should look like this:

<a th:href="@{delete-task(id=${task.id})}">

我相信您的href应该看起来像这样:

<a th:href="@{'delete-task?id=' + ${task.id}}"></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM