gpt4 book ai didi

java - 当我尝试在 postman 中返回消息时出现额外的空值

转载 作者:行者123 更新时间:2023-12-01 17:42:18 28 4
gpt4 key购买 nike

当我尝试从 spring mvc Controller 请求映射返回错误消息到 postman 工具时,我还得到一个额外的空值。

我的请求映射:

@RequestMapping(value="/getcompanystatus",method=RequestMethod.GET)
public List<CompanyStatusMaster> getCompanyStatus()
{
List<CompanyStatusMaster> companyStatus=userService.getCompanyStatus();
return companyStatus;
}
@RequestMapping(value="/getstates",method=RequestMethod.GET)
public List<StatesMaster> getstates()
{
List<StatesMaster> statesList=userService.getStates();
return statesList;
}
@RequestMapping(value="/getcompanies", method=RequestMethod.POST)
public CompaniesPresenter getCompanies(@RequestBody UserDetails user)
{
String OrgLoginId=user.getOrgLoginId();
String password=user.getuPassword();
String checkLoginId=null;
String uPassword=null;
String encPassword=null;
String loginId=null;
String checkAuthorized=null;
String checkOrgloginId=userService.getLoginId(OrgLoginId);
if(checkOrgloginId==null){
return new CompaniesPresenter("Incorrect loginId..Please enter valid loginId");
}
List<Object[]> CheckIdPassword=userService.checkLoginId(OrgLoginId);
List<Object[]> results = CheckIdPassword;
for(Object[] obj:results){
checkLoginId=obj[0].toString();
if(null==obj[1]){
uPassword="";
}else{
uPassword=obj[1].toString();
}
loginId=obj[2].toString();
}
checkAuthorized=loginId.substring(0,3);
if (null != password) {
MD5 md5 = new MD5();
encPassword = md5.getPassword(password);
}

if(encPassword.equals(uPassword))
{
if (checkAuthorized.equals("STE"))
{
List<CompanyMaster> companyList=userService.getCompanyList(OrgLoginId);
if(companyList.isEmpty())
{
return new CompaniesPresenter("Sorry..No companies for the user id");
}
else
{
return new CompaniesPresenter("select company from the below list",companyList) ;
}
}
else
{
return new CompaniesPresenter("You are not Authorized");
}
}
else
{
return new CompaniesPresenter("Incorrect Password");
}


}

我的 CompaniesPresenter 类:

public class CompaniesPresenter {
private String status;
private List<CompanyMaster> companyMaster;


public CompaniesPresenter()
{

}


public CompaniesPresenter(String status) {
this.status = status;
}


public CompaniesPresenter(List<CompanyMaster> companyMaster) {
this.companyMaster = companyMaster;
}


public CompaniesPresenter(String status, List<CompanyMaster> companyMaster) {
this.status = status;
this.companyMaster = companyMaster;
}


public String getStatus() {
return status;
}


public void setStatus(String status) {
this.status = status;
}


public List<CompanyMaster> getCompanyMaster() {
return companyMaster;
}


public void setCompanyMaster(List<CompanyMaster> companyMaster) {
this.companyMaster = companyMaster;
}

}

我的 postman 工具结果:{ "status": "抱歉..该用户 ID 没有公司", “公司大师”:空}

我不想要“companyMaster”:null。我只想要“状态”:“抱歉..没有该用户 ID 的公司”。我不知道为什么我会得到这个。请帮助我..对于我得到的所有返回值。谢谢

最佳答案

@JsonInclude(Ininclude.NON_NULL)添加到您的pojo中:

@JsonInclude(Include.NON_NULL)
public class CompaniesPresenter {
private String status;
private List<CompanyMaster> companyMaster;
..}

关于java - 当我尝试在 postman 中返回消息时出现额外的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59643753/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com