我的實體時間欄位是date類型的,也格式化了,為什麼前台輸入日期格式報錯?
控制層的程式碼!
@ApiConfig(desc = "修改或新增活動產品", author = "cxf", status = Status.developing)
@ResponseBody
@RequestMapping(value = {"updateOrAdd"}, method = {RequestMethod.GET, RequestMethod.POST})
public String updateOrAdd(@ApiParam(name="产品json字符串")String products,@ApiParam(name="id!=null修改,id=null增加",
excludes = {"id","actiDetailsList","pic","name"})ProActivityVO proActivity){
String strs = StringEscapeUtils.unescapeJava(products);
List<ProductInfo> list = JSON.parseArray(strs, ProductInfo.class);
return WebUtils.toJson(request, productInfoService.updateOrAdd(list, proActivity));
}
實體類別的欄位
public class ProActivityVO{
@FieldDesc(name="活动开始时间")
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date onTime;
@FieldDesc(name="活动结束时间")
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date endTime;
}
測試的頁面:
products(產品json字串):
content(活動內容):
title(活動標題):
shopId(所屬店鋪id):
actityPrice(活動價格):
onTime(活動開始時間):
endTime(活動結束時間):
img(活動圖片):
phpcn_u15822017-06-12 09:21:10
spring有個訊息處理器,可以去看
/** 解析json返回数据 **/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList(converter.getSupportedMediaTypes());
converter.setSupportedMediaTypes(mediaTypes);
mediaTypes.addAll(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.TEXT_XML));
ObjectMapper objectMapper = converter.getObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
converters.add(converter);
}