简体   繁体   English

如何在百里香中的字符串中传递参数

[英]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. 我试图通过在百里香的href链接中传递任务ID来删除列表中的项目。 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. 您应该对链接使用thymeleaf的标准URL语法 -以便可以正确对URL进行转义。 Your link should look like this: 您的链接应如下所示:

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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