0
我有一个Java新泽西端点这样的:的Jquery和Java /球衣端点绑定
public Response changeState(@HeaderParam(CLIENT_HEADER_PARAM) @NotNull Long clientId,
@FormParam("section") @NotNull String section,
@FormParam("state") @NotNull Boolean state) {
Map<String,String> result=new HashMap<>();
........
if(condition1){
result.put("key1","val1");
return Response.ok().entity(composeJson(unsuccessMap(result))).build();
}
if(condition2){
result.put("key2","val2");
return Response.ok().entity(composeJson(unsuccessMap(result))).build();
}
}
然后在jQuery的一面:
if(data.hasOwnProperty('key1') && data.key1=='val1'){
swal({
title: "Error",
text: "KEY1 ERROR",
type: "error",
allowEscapeKey: true
});
}
问题是我不喜欢它是如何工作的这办法。我需要记住魔术常量,字符串或数字,然后检查它在那里,arghhhh :)
如何做到这一点的最佳优雅的方式?