在controller的具体类中添加:
import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "date1.do") @ResponseBody public String date1(Date date1){ return date1.toString(); } @InitBinder("date1") public void initDate1(WebDataBinder binder){ binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true)); }
访问的化就直接/date1.do?date1=2018-01-01就可以了
以上内容摘录自geely老师