springmvc类型转换

来源:互联网 发布:淘宝五星好评 编辑:程序博客网 时间:2024/06/07 23:55
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));

}
}
0 0
原创粉丝点击