java响应与定制的POJO类对象
在jersey中,我们可以返回响应对象(jax-rs)和定制的pojo类对象,我不太清楚哪种方法更好。我不知道哪条路更好,为什么。有人能建议吗?请注意这两种情况下的退货类型。这是我的两个箱子
案例1:
@POST
@Path("/authentication")
public AuthenticationResponse authenticate(@NotNull FITransXTRequest objFITransXTRequest) {
logger.debug("## entering authenticate method");
System.out.println(objFITransXTRequest);
AuthenticationResponse objAuthResponse = new AuthenticationResponse();
JsonObject objResult = objAuthentication.authenticate(objFITransXTRequest);
System.out.println(objFITransXTRequest);
if (objResult != null) {
objAuthResponse.setStan(objResult.get("stan").getAsString());
objAuthResponse.setErrorMessage(objResult.get("responseMsg").getAsString());
objAuthResponse.setStatus(objResult.get("responseCode").getAsString());
objAuthResponse.setUidNumber(objResult.get("uidNumber").getAsString());
objAuthResponse.setRrn(objResult.get("rrn").getAsString());
objAuthResponse.setRdt(objFITransXTRequest.getDt());
}
return objAuthResponse;
}
案例2:
@POST
@Path("/authentication")
public Response authenticate(FITransXTRequest objFITransXTRequest) {
AuthenticationResponse objAuthResponse = new AuthenticationResponse();
JsonObject objResult = objAuthentication.authenticate(objFITransXTRequest);
System.out.println(objFITransXTRequest);
if (objResult != null) {
objAuthResponse.setStan(objResult.get("stan").getAsString());
objAuthResponse.setErrorMessage(objResult.get("responseMsg").getAsString());
objAuthResponse.setStatus(objResult.get("responseCode").getAsString());
objAuthResponse.setUidNumber(objResult.get("uidNumber").getAsString());
objAuthResponse.setRrn(objResult.get("rrn").getAsString());
objAuthResponse.setRdt(objFITransXTRequest.getDt());
}
return Response.ok( objAuthentication.authenticate(objFITransXTRequest)).build();
}
注意:我只想返回一个200 ok的状态代码
共 (0) 个答案