这里提供三种解决方案。
一.局部转换 :只是对当前Controller类有效
springMVC.xml中添加:
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
class="org.springframework.http.converter.StringHttpMessageConverter" />
Controller 类文件中添加:
@Controller
@RequestMapping("/image")
public class ImageController {
@Autowired
private ImageService imageService;
@org.springframework.web.bind.annotation.InitBinder
public void InitBinder(WebDataBinder binder){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
CustomDateEditor dateEditor = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class,dateEditor);
}
二.全局转换
1.创建convertDate类实现WebBindingInitializer接口