81,122
社区成员




@RequestMapping(value = "/json4",produces = "application/json;charset=utf-8") //String 的转换格式 produces = "text/html;charset=utf-8"
@ResponseBody
public String json4 () throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Date date = new Date();
return mapper.writeValueAsString(date);
}
@RequestMapping(value = "/json4",produces = "application/json;charset=utf-8") //String 的转换格式 produces = "text/html;charset=utf-8"
@ResponseBody
public String json4 () throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
//为了不返回时间戳,所以我们选择关闭它
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
//自定义日期格式问题
final SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS");
//设置mapper的指定的日期格式
mapper.setDateFormat(sdf);
Date date = new Date();
return mapper.writeValueAsString(date);
}