首页 > 编程语言 > 详细

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

时间:2017-10-20 12:54:57      阅读:240      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/watermelonban/p/7698844.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!