我是新手的球衣,而我正在尝试使用ajax从jquery接收数据到java,它不会映射pojo。
POJO: -
@XmlRootElement
public class RulesTO {
private int ruleId;
private String ruleName;
private int ruleStudioId;
private String ruleStudioName;
private String ruleDescription;
private Boolean ruleStatus;
private List<SitesTO> siteRule;
private List<IspsTO> ispRule;
private List<CountriesTO> countryRule;
private String studioDefaultRule;
//getters and setters
}
Ajax: -
var rulesTO = {
ruleName : $('#ruleName').val(),
ruleStudioId : $('#studios option:selected').attr("stream"),
ruleStudioName : $('#studios option:selected').text(),
ruleDescription : $('#ruledescription').val(),
ruleStatus : false,
siteRule : newSiteObject,
ispRule : newIspObject,
countryRule : newCountryObject,
studioDefaultRule : newStudioDefaultObject
}
$.ajax({
url : "/idns/idnsData/saveConfiguration",
type : "POST",
contentType : "application/json",
dataType : "json",
data : JSON.stringify(rulesTO),
success : function(data){
alert("success insert");
}
});
的java: -
@Path("/idnsData")
public class IdnsDataHandler {
private static Logger logger = Logger.getLogger(IdnsDataHandler.class);
private Connection connection = null;
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/saveConfiguration")
public RulesTO saveConfiguration(RulesTO rulesTO) throws Exception{
try{
logger.info("IdnsDataHandler : saveConfiguration Method start");
System.out.println("Rule Id : "+rulesTO.getRuleId());
System.out.println("Rule Name : "+rulesTO.getRuleName());
System.out.println("Studio Id : "+rulesTO.getRuleStudioId());
System.out.println("Studio Name : "+rulesTO.getRuleStudioName());
System.out.println("Rule Description : "+rulesTO.getRuleDescription());
System.out.println("Rule Status : "+rulesTO.isRuleStatus());
System.out.println("List Site : "+rulesTO.getSiteRule().size());
System.out.println("List Isp : "+rulesTO.getIspRule().size());
System.out.println("List Country : "+rulesTO.getCountryRule().size());
System.out.println("List studioDefault : "+rulesTO.getStudioDefaultRule());
List<SitesTO> takeall = rulesTO.getSiteRule();
for(int i=0;i<takeall.size();i++){
System.out.println("===="+takeall.get(i).getSiteName());
}
}
}
output :-
Rule Id : 0
Rule Name : example
Studio Id : 3
Studio Name : MAsia
Rule Description : test
Rule Status : false
List Site : 5
List Isp : 0
List Country : 0
List studioDefault : null
但我希望List站点对象和值映射到POJO,但不起作用。请帮助我,这对我的项目非常有用。谢谢
答案 0 :(得分:0)
check the dependencies for Moxy json, Thats work for me.
1.jersey-media-moxy-2.13.jar
2.jersey-entity-filtering-2.13.jar
3.org.eclipse.persistence.antlr-2.5.0.jar
4.org.eclipse.persistence.asm-2.5.0-RC2.jar
5.org.eclipse.persistence.core-2.5.0-RC2.jar
6.org.eclipse.persistence.moxy-2.5.0.jar