码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-10-20 13:31:54      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:[]   xtend   mapping   http   str   blog   style   exce   extend   

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数据绑定四(自定义的类型转换器)

标签:[]   xtend   mapping   http   str   blog   style   exce   extend   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!