类型转换:

请求url:  http://localhost:8080/SSHDemo2/stu/pro?s=zk,19

传入参数 s=zk,19   转换为Student

public class Student {

	private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "toString - name="+name+";age="+age;
} }
public class StudentEditor extends PropertyEditorSupport{

	@Override
public void setAsText(String text) throws IllegalArgumentException {
Student s = new Student();
String[] attrs = text.split(",");
if(attrs.length==1){
s.setName(attrs[0]);
} if(attrs.length==2){
s.setName(attrs[0]);
s.setAge(Integer.parseInt(attrs[1]));
}
System.out.println("setAsText");
setValue(s);
} @Override
public String getAsText() {
System.out.println("getAsText");
return getValue().toString();
}
}
@Controller
@RequestMapping("/stu")
public class StudentController { @RequestMapping("/pro")
public String stuPropertyEditor(@RequestParam("s") Student s){
System.out.println("name="+s.getName()+";age="+s.getAge());
return "success";
} @InitBinder
public void initBinder(WebDataBinder binder){
System.out.println("init..");
binder.registerCustomEditor(Student.class, new StudentEditor());
} }

此时也可以不要@InitBinder,因为bean为Student则StudentEditor会默认为它的属性编辑器

@InitBinder的更多相关文章

  1. 类型转换器(InitBinder 初始化绑定器)

    单日期格式 导入jar包 创建FirstController.java @Controller public class FirstController { /** * @param binder * ...

  2. Spring mvc @initBinder 类型转化器的使用

    一.单日期格式 因为是用注解完完成的后台访问,所以必须在大配置中配置包扫描器: 1.applicactionContext.xml <?xml version="1.0" e ...

  3. spring类型自动转换——@InitBinder和Converter

    spring有2种类型转换器,一种是propertyEditor,一种是Converter.虽然都是类型转换,但是还是有细微差别. 所以这里以一个例子的形式来分析一下这2种类型转换的使用场景和差别. ...

  4. SpringMVC中利用@InitBinder来对页面数据进行解析绑定

    同步发布:http://www.yuanrengu.com/index.php/springmvc-user-initbinder.html 在使用SpingMVC框架的项目中,经常会遇到页面某些数据 ...

  5. spring mvc使用@InitBinder 标签对表单数据绑定

    在SpringMVC中,bean中定义了Date,double等类型,如果没有做任何处理的话,日期以及double都无法绑定. 解决的办法就是使用spring mvc提供的@InitBinder标签 ...

  6. SpringMVC使用@PathVariable,@RequestBody,@ResponseBody,@RequestParam,@InitBinder

    @Pathvariable public ResponseEntity<String> ordersBack(           @PathVariable String reqKey, ...

  7. [Spring MVC] - InitBinder验证

    Spring MVC使用InitBinder验证: 使用InitBinder做验证的情况一般会在此Controller中提交的数据需要有一些是业务性质的,也即比较复杂的验证情况下才会使用.大部份简单的 ...

  8. springMVC注解@initbinder日期类型的属性自动转换

    在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支持这个格式的转换,所以必须要手动配置, 自定义数据类型的绑定才能实现这个功能. 一 ...

  9. SpringMVC注解@initbinder解决类型转换问题

    在使用SpringMVC的时候,经常会遇到表单中的日期字符串和JavaBean的Date类型的转换,而SpringMVC默认不支持这个格式的转换,所以需要手动配置,自定义数据的绑定才能解决这个问题.在 ...

随机推荐

  1. 《腾讯敏捷框架TAPD》研究

    1         框架结构 1.1         产品 TAPD采用FDD模式开发,FDD即特征驱动开发. FDD的核心是面向产品的功能点,但这个功能点是从客户角度出发的,并不是从系统角度出来的. ...

  2. JAVA:借用OpenOffice将上传的Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  3. linux ubuntu系统下,adb不是内部命令 (如何才能让adb命令可以使用)

    linux ubuntu系统下,adb不是内部命令 原文地址 linux ubuntu系统下,adb不是内部命令 解决方法: 1.sudo gedit ~/.bashrc 2.将下面的两句加到上面打开 ...

  4. [tomcat] tomcat+nginx 负载均衡配置

    首先下载,安装tomcat. 修改tomcat端口,修改server.xml: 1.修改tomcat端口(默认8080) <Connector port="8383" pro ...

  5. 微信公众平台Php版php开发(转)

    http://www.1990c.com/?p=932 近在做微信公众平台开发,一口气写了二十几个功能,挺有意思的-  今天来分享一下开发经验~微信公众平台提供的接口很简单,先看看消息交互流程:  说 ...

  6. [转].net 使用NPOI或MyXls把DataTable导出到Excel

    本文转自:http://www.cnblogs.com/yongfa365/archive/2010/05/10/NPOI-MyXls-DataTable-To-Excel-From-Excel.ht ...

  7. C#Random()函数详解

    随机数的使用很普遍,可用它随机显示图片,用它防止无聊的人在论坛灌水还可以用来加密信息等等.本文讨论如何在一段数字区间内随机生成若干个互不相同的随机数,比如在从1到20间随机生成6个互不相同的整数,并通 ...

  8. read,for,case,while,if简单例子

    Read多用于从某文件中取出每行进行处理 $ cat read.sh #!/bin/bash echo "using read" cat name.txt | while read ...

  9. Apple dev travel

    Objective-C最基础语法之Class定义: http://mobile.51cto.com/iphone-281925.htm  Table View: http://www.appcoda. ...

  10. (C#) Action, Func, Predicate 等泛型委托

    (转载网络文章) (1). delegate delegate我们常用到的一种声明   Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型.   例:public del ...