简体   繁体   中英

Spring boot rest service duplicated response body

I'm using Spring Boot framework and my response returns duplicated with reversed backward. I'm asking for advices, how can i solve this situation?

Controller End Point

@GetMapping("/getPDetailsW/{W}")
public PPreviewW getPDetailsPreviewW(@PathVariable String W) {

   DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
   LocalDateTime now = LocalDateTime.now();
   String nullCheckBill = "bos";
   PPreviewW response = new PromoPreviewWGsm();

   PPreviewInfo pPreviewInfo = listRepository.findPByW(W);
   log.info(dtf.format(now) + "|getPDetailsPreviewW|" + W+ "|için istek atıldı.");

   response.setDisplayId(pPreviewInfo.getDISPLAY_ID());
   response.setAccountCode(pPreviewInfo.getACCOUNT_CODE());

   if (pPreviewInfo.W!= "bos") {
       nullCheckBill = promoPreviewInfo.W;
   }

   if (nullCheckBill == "bos") {
       response.setNEXTFLAG(Boolean.FALSE);
   } else {
       response.setNEXTFLAG(Boolean.TRUE);
   }
   return response;
}

I have @RestController annotation at top of my Controller class.

PPreviewW response class

@Getter
@Setter
public class PPreviewW implements Serializable {

    public String DisplayId;
    public String AccountCode;
}

I'm using lombok getters and setters

Repository Class

public PPreviewInfo findPByW(String W) {
    PPreviewInfo list = jdbcTemplate
            .queryForObject(QueryConstants.GET_P_PREVIEW_INFOW, new Object[]{W}, new PPreviewInfoMapper());

    return list;
}

@Repository and @Autowired annotations at top of Repository class. and QueryContants includes my sql which returns correct size for example like XXXX and YYYY PPreviewInfo Class

@Getter
@Setter
public class PPreviewInfo {

    public String CUSTOMER_ID;
    public String BILLING_ACCOUNT_CODE;
}

PPreviewInfoMapper Class

public class PPreviewInfoMapper implements RowMapper<PPreviewInfo> {
    @Override
    public PPreviewInfo mapRow(ResultSet rs, int i) throws SQLException {

        PPreviewInfo pbn = new PPreviewInfo();

        pbn.setDISPLAY_ID(rs.getString("DISPLAY_ID"));
        pbn.setACCOUNT_CODE(rs.getString("ACCOUNT_CODE"));
        return pbn;
    }
}

response

{"DisplayId":"XXXX","AccountCode":"YYYYYY","NEXTFLAG":true,"nextflag":true,"displayId":"XXXX","accountCode":"YYYYYY"}

The visibility of the attributes might be causing the issue, you can see if changing them to private might help in resolution:

@Getter
@Setter
public class PPreviewW implements Serializable {

    private String DisplayId;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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