SpringMVC custom type conversion

There is a type conversion problem between the page and the front controller. If you want to implement a type conversion yourself:

public class StringDateConvert implements Converter<String, Date> {
    @Override
    public Date convert(String source) {
        //1.判断是否为空
        if (source == null) {
            throw new RuntimeException("请输入正常日期");
        }
        System.out.println("首先,写实现converter类的类,其次,将其加入springMvVC中,最后,通过MvC启动该类的使用");
            //2.自定义
            DateFormat df = new SimpleDateFormat("yyyy-MM-DD");
            try {
                return df.parse(source);
            } catch (ParseException e) {
                throw new RuntimeException("w,跳转错误");
            }
    }
}

[2. Configuration registration Insert picture description hereConfigure custom converter] 3. Join the container and enable
Insert picture description here

Published 12 original articles · Likes0 · Visits 148

Guess you like

Origin blog.csdn.net/weixin_44065691/article/details/105048996