SpringMVC数据绑定四(自定义的类型转换器)

1、PropertyEditor

  继承PropertyEditorSupport

//controller
@Controller
public class TestController extends PropertyEditorSupport{
     //重写PropertyEditorSupport的setAsText方法
@Override
    public void setAsText(String text) throws IllegalArgumentException {
        User u = new User();
        String[] textArray = text.split(",");
        u.setName(textArray[0]);
        u.setAge(Integer.parseInt(textArray[1]));
        this.setValue(u);
    }
    
//TODO: http://127.0.0.1:8080/SpringMVC/propertyEditir?text=Tom,20 @RequestMapping(value
="propertyEditir") @ResponseBody public String propertyEditir(String text) { this.setAsText(text); return ((User)this.getValue()).toString(); } }

2、Formatter

原文地址:https://www.cnblogs.com/watermelonban/p/7698844.html