我想像查询一样使用“赞”但是应该从开始扫描结果 例如,“以...开头”
List<Account> findByUserInfo_FirstNameRegexAndUserInfo_LastNameRegexAndEmails_EmailIDRegex(String firstName, String lastName, String emailID);
或
List<Account> findByUserInfo_FirstNameLikeAndUserInfo_LastNameLikeAndEmails_EmailIDLike(String firstName, String lastName, String emailID);
适用于我制作的API。
这是我使用Spring的控制器代码,
@RequestMapping(value = baseUrl + "/search", method = RequestMethod.GET)
public List<Account> getSimilarAccountList(@RequestParam(value = "fullName", required = false) String fullName, @RequestParam(value = "emailID", required = false) String emailID, @RequestParam(value = "mobile", required = false) String mobileNumber) {
log.info("Request to fetch all the accounts recieved.");
return accountService.getSimilarAccountList(fullName, emailID, mobileNumber);
我通过postman使用
调用APIhttp://localhost:9098/account/search?fullName=kk
给我相同的结果
"firstName": "akki"
但我希望它只适用于 http://localhost:9098/account/search?fullName=ak
我希望,我可以让我的问题更清楚。
答案 0 :(得分:0)
使用:
解决它List<Account> findByUserInfo_FirstNameRegexAndUserInfo_LastNameRegexAndEmails_EmailIDRegex(String firstName, String lastName, String emailID);
和
实施服务:
firstName = "^" + firstName;
emailID = "^" + emailID;
lastName = "^" + lastName;
repository.findByUserInfo_FirstNameRegexAndUserInfo_LastNameRegexAndEmails_EmailIDRegex(firstName, lastName, emailID);
在String的开头使用带有“^”的正则表达式。