在 spring boot 中处理请求参数中的空格
Handling white spaces in Request Parameter in springboot
在我的 HQL 中,我使用
queryListBuilder.append(" and f.nom like '%"+ nomFil +"%' ");
nomFil 是一个字符串,单词之间可能包含空格。
当我发送
http://localhost:8080/list?nom=First Last
我得到的结果是空的。
Ps:在我的数据库中,该值存在于我的目标 table 中。
有什么办法可以处理请求参数中的空格吗?
如果在 URL 中使用,您应该将 nomFil
编码为:
URLEncoder.encode(nomFil, "UTF-8");
Percent-encoding, also known as URL encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances. Although it is known as URL encoding it is, in fact, used more generally within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTML form data in HTTP requests.
您需要对查询参数进行编码和解码。
在我的 HQL 中,我使用
queryListBuilder.append(" and f.nom like '%"+ nomFil +"%' ");
nomFil 是一个字符串,单词之间可能包含空格。 当我发送
http://localhost:8080/list?nom=First Last
我得到的结果是空的。 Ps:在我的数据库中,该值存在于我的目标 table 中。 有什么办法可以处理请求参数中的空格吗?
如果在 URL 中使用,您应该将 nomFil
编码为:
URLEncoder.encode(nomFil, "UTF-8");
Percent-encoding, also known as URL encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances. Although it is known as URL encoding it is, in fact, used more generally within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTML form data in HTTP requests.
您需要对查询参数进行编码和解码。