我常用的堆栈
-
弹簧靴1.5.6 RealEase
-
Ajax jquery 3.3.1
我的目标
我正试图将一些数据打印到Jasper报表中,因此创建了一个REST控制器,我有了从前端发送JSON数据的想法,并通过Jackson API将其解析为pojo列表,然后使用jrdatabean处理我的报表。
我的密码
当按下打印按钮时,我使用从chrome控制台获得的Ajax发送这个json数组,方法是将其设置为全局变量,然后使用副本(我在Google上搜索的atrick将变量内容设置为字符串)
.
[ {
"codeInterne": 45,
"clientName": "TalcorpDZ",
"clientPhone": "+213778217469",
"codeExterne": "CLI201801",
"email": "talcorpdz@gmail.com",
"clientType": 0,
"clientEtat": 1,
"identifiant": "TalcorpDZ",
"contacts": [
{
"nom": "Taleb",
"prenom": "Mohammed Housseyn",
"telephonePortable": "04330256699",
"email": null
}
],
"adresses": [
{
"adress": "Batiments des enseignants Mohammed Khemisti",
"ville": "Maghnia"
}
]
},
{
"codeInterne": 64,
"clientName": "lkjhgf",
"clientPhone": "+213778217469",
"codeExterne": "dfghjk",
"email": "talcorpdz@gmail.com",
"clientType": 1,
"clientEtat": 1,
"identifiant": "lkjhgf",
"contacts": [
{
"nom": "Taleb",
"prenom": "Mohammed",
"telephonePortable": "02354649",
"email": "talcorpdz@gmail.com"
}
],
"adresses": [
{
"adress": "Batiments des enseignants Mohammed Khemist",
"ville": "Maghnia"
}
]
}
]
.
$(document).on('click', '#menu0-func1-menu0-func1', function(){
console.log(printData);
var settings = {
"async" : true,
"crossDomain" : true,
"url" : "http://"+document.location.host+"/facturation/print/client",
"method" : "POST",
"headers" : {
"cache-control" : "no-cache",
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
"processData" : false,
"contentType" : "application/json",
"dataType" : "json",
"data" : printData
}
$.ajax(settings).done(function(response) {
console.log(response);
});
});
这篇文章很受我的控制器欢迎,编码如下:
@RestController
@RequestMapping(PrintController.API)
public class PrintController {
public static final String API="print";
@PostMapping("client")
public void export(@RequestBody List<ClientJsonDto> datas,HttpServletResponse response){
System.out.println(datas);
// processing the print mechanisme
}
}
最后是我的客户jsondto.java
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"codeInterne",
"clientName",
"clientPhone",
"codeExterne",
"email",
"clientType",
"clientEtat",
"identifiant",
"contacts",
"adresses"
})
public class ClientJsonDto {
@JsonProperty("codeInterne")
private Integer codeInterne;
@JsonProperty("clientName")
private String clientName;
@JsonProperty("clientPhone")
private String clientPhone;
@JsonProperty("codeExterne")
private String codeExterne;
@JsonProperty("email")
private String email;
@JsonProperty("clientType")
private Integer clientType;
@JsonProperty("clientEtat")
private Integer clientEtat;
@JsonProperty("identifiant")
private String identifiant;
@JsonProperty("contacts")
private List<Contact> contacts = null;
@JsonProperty("adresses")
private List<Adress> adresses = null;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
// getters, setters
}
爪哇
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"adress",
"ville"
})
public class Adress {
@JsonProperty("adress")
private String adress;
@JsonProperty("ville")
private String ville;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//getters, setters
}
Java语言
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"nom",
"prenom",
"telephonePortable",
"email"
})
public class Contact {
@JsonProperty("nom")
private String nom;
@JsonProperty("prenom")
private String prenom;
@JsonProperty("telephonePortable")
private String telephonePortable;
@JsonProperty("email")
private String email;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//getters setters
}
我面临的例外是:
2018-11-18 15:12:40.255警告1768--[NIO-8082-EXEC-9]
.W.S.M.S.DefaultHandlerExceptionResolver:未能读取HTTP
信息:
org.springframework.http.converter.httpmessagenotreadable异常:
JSON分析错误:无法识别的标记“object”:应为(“true”,
“false”或“null”);嵌套异常为
com.fasterxml.jackson.core.jsonParseException:无法识别的令牌
“object”:在[source:
Java.Io.PubBaskPixStudio1DF244F9;线:1,列:9
我该怎么做才能看到我的休息控制器在杰克逊试图进行编组之前接收到的请求主体?
我可以做什么来修复这个异常?