不太可能是equals()的参数类型:String 似乎与MemberSearchRequest无关

huangapple go评论88阅读模式
英文:

Unlikely argument type for equals(): String seems to be unrelated to MemberSearchRequest

问题

@PostMapping("searchMember")
public String searchMember(
        @RequestBody(required = false) MemberSearchRequest request, 
        @RequestParam(value = "offset", required = false) @ApiParam(value = "offset") final Integer offset,
        @RequestParam(value = "limit", required = false) @ApiParam(value = "limit") final Integer limit,
        @RequestParam(value = "orderBy", required = false) @ApiParam(value = "orderBy") final String orderBy,
        @RequestParam(value = "sortOrder", required = false) @ApiParam(value = "sortOrder") final String sortOrder) {
    
    CommandProcessingResult result = null;

    if ((request.getGeneratedMemberNo() != null && this.clientRepository.getClientByMemberNo(request.getGeneratedMemberNo()) == null)
            || (request.getFirstname() != null && this.clientRepository.getClientByFirstName(request.getFirstname()) == null)
            || (request.getLastname() != null && this.clientRepository.getClientByLastName(request.getLastname()) == null)) {
        
        result = new CommandProcessingResultBuilder()
                .setStatus("Failed")
                .setMessage("MEMBER NOT FOUND")
                .setRefNo("<YYYY-MM-DD-H-M-S-Count>")
                .setPfsRefNo("1234567890")
                .build();
        
        return this.toApiJsonSerializer.serialize(result);
    }
    
    return this.searchMember(
            request.getGeneratedMemberNo(), 
            request.getFirstname(), 
            request.getLastname(),
            offset, limit, orderBy, sortOrder);
}
@Data
public class MemberSearchRequest {
    public String generatedMemberNo;
    public String firstname;
    public String lastname;
}
英文:

Hi I just want to implement this error message but it seems like it is not being processed. My goal here is to make the error message appear when either of the three requests (generatedMemberNo, firstname, lastname) have no results. Here is my code:

    public String searchMember(
@RequestBody(required = false) MemberSearchRequest request, 
@RequestParam(value = &quot;offset&quot;, required = false) @ApiParam(value = &quot;offset&quot;) final Integer offset,
@RequestParam(value = &quot;limit&quot;, required = false) @ApiParam(value = &quot;limit&quot;) final Integer limit,
@RequestParam(value = &quot;orderBy&quot;, required = false) @ApiParam(value = &quot;orderBy&quot;) final String orderBy,
@RequestParam(value = &quot;sortOrder&quot;, required = false) @ApiParam(value = &quot;sortOrder&quot;) final String sortOrder) {
CommandProcessingResult result = null;
if(request.equals(&quot;generatedMemberNo&quot;) &amp;&amp; this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null ||
request.equals(&quot;firstname&quot;) &amp;&amp; this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null ||
request.equals(&quot;lastname&quot;) &amp;&amp; this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null) {
result = new CommandProcessingResultBuilder()
.setStatus(&quot;Failed&quot;)
.setMessage(&quot;MEMBER NOT FOUND&quot;)
.setRefNo(&quot;&lt;YYYY-MM-DD-H-M-S-Count&gt;&quot;)
.setPfsRefNo(&quot;1234567890&quot;)
.build();
return this.toApiJsonSerializer.serialize(result);
}
return this.searchMember(request.getGeneratedMemberNo(), request.getFirstname(), request.getLastname(),
offset, limit, orderBy, sortOrder);
}

And this is my code for MemberSearchRequest.java

@Data
public class MemberSearchRequest {
public String generatedMemberNo;
public String firstname;
public String lastname;
}

答案1

得分: 0

你的MemberSearchRequest不是一个字符串,因此复合if语句的第一部分永远不会成立。

request.equals("generatedMemberNo") &&
request.equals("firstname") &&
request.equals("firstname") &&

看起来你可以将它们移除,空值检查仍然能够满足。

if (this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null ||
this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null ||
this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null)
英文:

Your MemberSearchRequest isn't a String so the first parts of your compound if statement will never be true.

request.equals(&quot;generatedMemberNo&quot;) &amp;&amp;
request.equals(&quot;firstname&quot;) &amp;&amp;
request.equals(&quot;firstname&quot;) &amp;&amp;

It appears that you could remove them and the null checks would be met.

if(this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null ||
this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null ||
this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null)

huangapple
  • 本文由 发表于 2020年7月23日 14:03:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63047844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定