当前位置: 首页 > news >正文

php网站后台入口1m宽带做网站

php网站后台入口,1m宽带做网站,织梦cms默认密码,广州百度网站建设公司BeanWrapper 是 Spring 框架中的一个接口#xff0c;它提供了一种方式来设置和获取 JavaBean 的属性。JavaBean 是一种特殊的 Java 类#xff0c;遵循特定的编码约定#xff08;例如#xff0c;私有属性和公共的 getter/setter 方法#xff09;#xff0c;通常用于封装数…BeanWrapper 是 Spring 框架中的一个接口它提供了一种方式来设置和获取 JavaBean 的属性。JavaBean 是一种特殊的 Java 类遵循特定的编码约定例如私有属性和公共的 getter/setter 方法通常用于封装数据 主要功能 1.属性访问         BeanWrapper 允许以统一的方式访问 JavaBean 对象的属性包括简单属性、复杂类型属性、集合和数组等。它支持通过属性路径property path来访问嵌套对象的属性例如 person.address.streetName。 2.类型转换         BeanWrapper 内置了对常见类型的转换支持可以自动处理不同数据类型的转换。 可以注册自定义的 PropertyEditor 或使用 ConversionService 来实现更复杂的类型转换逻辑。 3.属性编辑器         可以为特定的数据类型注册 PropertyEditor这允许在从字符串到对象或反之的转换过程中进行定制化处理。 4.错误处理         当尝试设置非法值或访问不存在的属性时BeanWrapper 可以捕获并报告这些错误。 访问简单属性  import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl;public class BeanWrapperExample {public static void main(String[] args) {// 创建一个目标对象Person person new Person();// 创建 BeanWrapper 实例BeanWrapper beanWrapper new BeanWrapperImpl(person);// 设置属性值beanWrapper.setPropertyValue(name, John Doe);beanWrapper.setPropertyValue(age, 30);// 获取属性值String name (String) beanWrapper.getPropertyValue(name);int age (Integer) beanWrapper.getPropertyValue(age);System.out.println(Name: name);System.out.println(Age: age);} }class Person {private String name;private int age;// 必须提供 getter 和 setter 方法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;} } 访问嵌套属性 import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl;public class NestedPropertyAccess {public static void main(String[] args) {Person person new Person();Address address new Address();person.setAddress(address);BeanWrapper beanWrapper new BeanWrapperImpl(person);// 设置嵌套属性beanWrapper.setPropertyValue(address.street, 123 Main St);beanWrapper.setPropertyValue(address.city, Springfield);// 获取嵌套属性String street (String) beanWrapper.getPropertyValue(address.street);String city (String) beanWrapper.getPropertyValue(address.city);System.out.println(Street: street); // 输出: Street: 123 Main StSystem.out.println(City: city); // 输出: City: Springfield} }class Person {private String name;private int age;private Address address;// Getters and Setterspublic 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; }public Address getAddress() { return address; }public void setAddress(Address address) { this.address address; } }class Address {private String street;private String city;// Getters and Setterspublic String getStreet() { return street; }public void setStreet(String street) { this.street street; }public String getCity() { return city; }public void setCity(String city) { this.city city; } } 自动类型转换 import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl;public class TypeConversion {public static void main(String[] args) {Person person new Person();BeanWrapper beanWrapper new BeanWrapperImpl(person);// 设置属性值自动类型转换beanWrapper.setPropertyValue(age, 30); // 字符串 30 转换为 int 30// 获取属性值int age (Integer) beanWrapper.getPropertyValue(age);System.out.println(Age: age); // 输出: Age: 30} }class Person {private String name;private int age;// Getters and Setterspublic 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; } } 注册自定义 PropertyEditor import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import java.beans.PropertyEditorSupport;public class CustomPropertyEditor {public static void main(String[] args) {Person person new Person();BeanWrapper beanWrapper new BeanWrapperImpl(person);// 注册自定义 PropertyEditorbeanWrapper.registerCustomEditor(Date.class, new DateEditor());// 设置日期属性beanWrapper.setPropertyValue(birthdate, 2023-01-01);// 获取日期属性Date birthdate (Date) beanWrapper.getPropertyValue(birthdate);System.out.println(Birthdate: birthdate); // 输出: Birthdate: Sun Jan 01 00:00:00 CST 2023} }class Person {private String name;private int age;private Date birthdate;// Getters and Setterspublic 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; }public Date getBirthdate() { return birthdate; }public void setBirthdate(Date birthdate) { this.birthdate birthdate; } }class DateEditor extends PropertyEditorSupport {Overridepublic void setAsText(String text) throws IllegalArgumentException {try {setValue(new SimpleDateFormat(yyyy-MM-dd).parse(text));} catch (ParseException e) {throw new IllegalArgumentException(Invalid date format);}} } 处理属性设置错误 import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.PropertyAccessException;public class ErrorHandling {public static void main(String[] args) {Person person new Person();BeanWrapper beanWrapper new BeanWrapperImpl(person);try {// 尝试设置一个不存在的属性beanWrapper.setPropertyValue(invalidProperty, value);} catch (PropertyAccessException e) {System.out.println(Error: e.getMessage()); // 输出: Error: Invalid property invalidProperty of bean class [Person]: // Bean property invalidProperty is not readable or has an invalid getter // method: Does the return type of the getter match the parameter type // of the setter?}} }class Person {private String name;private int age;// Getters and Setterspublic 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; } }
http://www.w-s-a.com/news/268320/

相关文章:

  • 网站建设需要做哪些工作网片焊接
  • 网站优化方案dedecms win8风格网站模板
  • 企业如何制作网站管理系统慈溪住房和城乡建设部网站
  • 青岛网站建设有哪些公司区块链网站开发价格
  • 怎么设置网站的logo微信公众号的h5网站开发6
  • 粉色的网站绍兴市建设局网站
  • 个人网站的基本风格是wordpress 模板选择
  • 南昌专业做网站公司有哪些广州市住房城乡建设部门户网站
  • 福州网站建设团队淘宝联盟网站怎么建设
  • 福州企业网站建站模板国内黑色风格的网站
  • 好看的网站首页设计android移动开发
  • 域名注册完成后如何做网站域名 删除 wordpress
  • wordpress xml导入大小东莞seo优化方案
  • 网站建设效益网站销售怎么做的
  • 利用网站空间做代理设计方案的格式范文
  • 无锡建设工程质量监督网站遵义做手机网站建设
  • 衡阳商城网站制作ps做网站首页规范尺寸
  • 微信网站应用开发营销推广的方案
  • 广州做网站商城的公司制作一个app的完整流程
  • 湖南城乡建设厅网站163注册企业邮箱
  • 做网站怎么调整图片间距织梦做的网站如何去掉index
  • 凡科网免费建站步骤及视频网页设计基础教程第二版课后答案
  • 建设一个旅游网站毕业设计企业网站要更新文章吗
  • 做网站需要简介中山网站设计公司
  • 网站怎么做导航栏微信公众号官网登录
  • 1_ 掌握网站开发的基本流程 要求:熟悉网站开发与设计的基本流程.电子商城网站开发
  • 百度网站怎么建设河北省工程造价信息网官网
  • 阿里云网站模板网页设计的合适尺寸是多少
  • 做小程序和做网站哪个好让别人做网站推广需要多少钱
  • 做外贸的几个网站查询网域名解析