package com.ssfans.core.controller;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;
@Controller
@RequestMapping("/test")
public class TestController implements WebBindingInitializer{
@RequestMapping("/test.shtml")
public void test(Date date){
System.out.println(date);
System.out.println("hello");
}
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
}
}
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;
@Controller
@RequestMapping("/test")
public class TestController implements WebBindingInitializer{
@RequestMapping("/test.shtml")
public void test(Date date){
System.out.println(date);
System.out.println("hello");
}
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
}
}