标签:one person ted res ons port 通过 object gis
@Controller public class TestController { @RequestMapping("/test.json") @ResponseBody public Test testJson(Integer i, Float f, String str, Date date) { Test test = new Test(); test.setI( i!=null ? i : 1); test.setF( f!=null ? f : 2.0f); test.setStr( str!=null ? str : "test"); test.setDate(date !=null ? date : new Date()); return test; } @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true)); } }
@org.springframework.format.annotation.DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date presaleStartDate;
结合下面的配置:
<mvc:annotation-driven conversion-service="conversionService"> </mvc:annotation-driven> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <list> <!-- <bean class="com.ll.model.StringToPersonConverter" /> --> </list> </property> </bean>
@com.fasterxml.jackson.annotation.JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone="CET") public Date getDate() { return date; }
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean id="messageConverters" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <property name="objectMapper"> <bean class="com.fasterxml.jackson.databind.ObjectMapper"> <property name="dateFormat"> <bean class="java.text.SimpleDateFormat"> <constructor-arg value="yyyy-MM-dd HH:mm:ss" /> </bean> </property> </bean> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
标签:one person ted res ons port 通过 object gis
原文地址:http://www.cnblogs.com/coder6/p/6738781.html