var position ={};
position.positionName= $('#position-name').val();
这个position对象传入后端的属性名positionName一定要和后端实体类里面的对应的属性名一样
@ApiOperation(value = "新增职位")
@PostMapping("/insertPosition")
@ResponseBody
public Map<String,Object> insertPosition(@RequestParam String positionStr){
Map<String,Object> map=new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
Position position=null;
try {
position=mapper.readValue(positionStr,Position.class);
} catch (JsonProcessingException e) {
map.put("success",false);
map.put("errMsg","传入的JSON字符串格式不正确");
return map;
}
try {
positionService.insert(position);
} catch (Exception e) {
map.put("success",false);
map.put("errMsg",e.getMessage());
return map;
}
map.put("success",true);
return map;
}
这里面的positionStr里面的字段要和我Position.class里面的字段一样
public class Position implements Serializable {
private static final long serialVersionUID = 788318165769505032L;
private Integer positionId;
private String positionName;
private Date createTime;
private Integer status;
我在js部分 position.positionName= $(’#position-name’).val();写成了 position.name= $(’#position-name’).val(); 导致在控制层把捕获JSON字符串不正确运行了 这两行,因为name和实体类里面的任何一个都对不上
map.put("success",false);
map.put("errMsg","传入的JSON字符串格式不正确");
|