用beanutils操纵javabean(不含自定义字符类型转换功能)

 1 package beanutils;
 2
 3 import javax.xml.crypto.Data;
 4
 5 public class person {   //javabean
 6     private String name;//字段
 7     private int age;//字段
 8     private String password;//字段
 9
10     public String getName()
11     {
12         return name;
13
14     }
15     public int getAge()
16     {
17         return age;
18
19     }
20     public String getPassword()
21     {
22         return password;
23
24     }
25     public void setName(String name)
26     {
27         this.name=name;
28     }
29     public void setAge(int age)
30     {
31         this.age=age;
32     }
33     public void setPassword(String password)
34     {
35         this.password=password;
36     }
37
38 }
 1 package beanutils;
 2
 3 import java.lang.reflect.InvocationTargetException;
 4
 5 import org.apache.commons.beanutils.BeanUtils;
 6 import org.apache.commons.beanutils.ConvertUtils;
 7 import org.junit.Test;
 8
 9 //使用beanutils操纵bean的属性
10 public class demo {
11   @Test
12   public void test1() throws Exception, Exception
13   {
14       person p=new person();
15       BeanUtils.setProperty(p,"name","hemaoyun");//实现这个功能需要导入beanutils包(自己导入第三方jar)
16       System.out.println(p.getName());
17   }
18   @Test
19   public void test2() throws Exception, Exception
20   {
21       String name="aaaa";
22       String password="1234";
23       String age="12";
24       person p=new person();
25       BeanUtils.setProperty(p,"name",name);
26       BeanUtils.setProperty(p,"password",password);
27       BeanUtils.setProperty(p,"age",age);//只支持8种数据类型转换(beanutils自动把String类型转换成int类型)
28       System.out.println(p.getAge());
29       System.out.println(p.getName());
30       System.out.println(p.getPassword());
31   }
32  //除了8中基本数据类型的其他类型
33   @Test
34   public void test3() throws Exception, Exception
35   {
36       String name="aaaa";
37       String password="1234";
38       String age="12";
39
40               person p=new person();
41
42       BeanUtils.setProperty(p,"name",name);
43       BeanUtils.setProperty(p,"password",password);
44       BeanUtils.setProperty(p,"age",age);//只支持8种数据类型转换(beanutils自动把String类型转换成int类型)
45
46
47       System.out.println(p.getAge());
48       System.out.println(p.getName());
49       System.out.println(p.getPassword());
50
51   }
52 }
时间: 2024-07-29 07:20:21

用beanutils操纵javabean(不含自定义字符类型转换功能)的相关文章

使用beanUtils操纵javabean

Sun公司的内省API过于繁琐,所以Apache组织结合很多实际开发中的应用场景开发了一套简单.易用的API操作Bean的属性——BeanUtils,在Beanutil中可以直接进行类型的自动转换. BeanUtil工具包下载: 1,登录http://commons.apache.org/beanutils/ 2,  点击Download 3, 点击commons-beanutils-1.9.2-bin.zip(commons-logging-1.1.3-src)进行下载就OK了 使用BeanU

LCD1602 显示数字,字符,自定义字符,字符串,光标

/******************************************* 程序名:   1602液晶屏时钟程序 编写时间: 2015年10月4日 硬件支持: LCD1602液晶屏  STC12C4052AD 外部12MHZ晶振  接线定义:  DB0_DB7 --> P1^0 --P1^7 RS   = P3 ^ 2;         RW   = P3 ^ 3;   E    = P3 ^ 4;   功能:测试LCD1602的显示,显示时间,http://990487026.b

LCD1602显示,用4位总线显示数字,字符,自定义字符,字符串,光标

/******************************************* 程序名:   1602液晶屏时钟程序 编写时间: 2015年10月4日 硬件支持: LCD1602液晶屏  STC12C4052AD 外部12MHZ晶振  接线定义: DB7 --> P1^7 DB6 --> P1^6 DB5 --> P1^5 DB4 --> P1^5 RS   = P3 ^ 2;   RW   = P3 ^ 3;   E    = P3 ^ 4;   功能:LCD1602显

含重复字符的字符串的全排列问题(Java)

本代码既可以输出重复和不重复字符串的全排列 /** * 含重复字符的字符串的全排列问题 * * */ public class S_28 { public static int count = 0; public static void main(String[] args){ char[] list = {'a','b','c'}; char[] list1 = {'a','b','b'}; //permutation(list); permutation(list1); System.out

新增5 最长不含重复字符的子字符串

请从字符串中找出一个最长不含重复字符的子字符串,计算该最长子字符串的长度.例如字符串"arabcacfr"中,最长不含重复字符的子字符串是"acfr",长度为4. 思路:cur当前最长,max全局最长:hash数组记录字符对应下标:遍历字符串,如果字符对应hash值小于0,说明字符未出现,cur直接+1即可:如果大于等于0出现了说明重复字符,那就需要判断,如果两次出现长度差d大于cur说明重复字符不在当前cur长的字符串中,无需在意,cur+1即可,如果d小等于cu

最长不含重复字符的子字符串

输入一个字符串(只包含 a~z 的字符),求其最长不含重复字符的子字符串的长度.例如对于 arabcacfr,最长不含重复字符的子字符串为 acfr,长度为 4. 1 public static int longestSubStringWithoutDuplication(String str) { 2 int curLen = 0 ; 3 int maxLen = 0 ; 4 int[] preIndex = new int[26] ; 5 for(int i = 0 ; i < 26 ; i

剑指offer:最长不含重复字符的子字符串

题目:最长不含重复字符的子字符串 请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度.假设字符串中只包含从'a'到'z'的字符.例如,在字符串中"arabcacfr",最长非重复子字符串为"acfr",长度为4. # -*- coding: utf-8 -*- # @Time : 2019-07-11 10:57 # @Author : Jayce Wong # @ProjectName : job # @FileName : longes

《剑指offer》第四十八题:最长不含重复字符的子字符串

// 面试题48:最长不含重复字符的子字符串 // 题目:请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子 // 字符串的长度.假设字符串中只包含从'a'到'z'的字符. #include <string> #include <iostream> // 方法一:蛮力法 bool hasDuplication(const std::string& str, int position[]); int longestSubstringWithoutDuplicat

java web过滤器实际应用(解决中文乱码 html标签转义功能 敏感字符过滤功能)

转载地址:http://www.cnblogs.com/xdp-gacl/p/3952405.html 在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目标资源,从而实现一些特殊需求. 一.Decorator设计模式 1.1.Decorator设计模式介绍 当某个对象的方法不适应业务需求时,通常有2种方式可以对方法进行增强: 编写子类,覆盖需增强的