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

通辽网站开发浏览器游戏网址

通辽网站开发,浏览器游戏网址,网页链接怎么弄,汕头市澄海建设局门户网站这篇文章着眼于使用Orika将JAXB对象映射到业务域对象。 本月初#xff0c; 我使用基于反射的Dozer讨论 了相同的映射用例 。 在本文中#xff0c;我假设需要映射相同的示例类#xff0c;但是它们将使用Orika而不是Dozer进行映射 。 Dozer和Orika旨在解决相同类型的问题 我使用基于反射的Dozer讨论 了相同的映射用例 。 在本文中我假设需要映射相同的示例类但是它们将使用Orika而不是Dozer进行映射 。 Dozer和Orika旨在解决相同类型的问题两个“数据”对象的自动映射这些对象不共享公共继承但表示相同的数据字段。 推土机使用反射来完成此操作而Orika使用反射和字节码操作来完成此操作。 Orika的口号是“更简单更轻便更快的Java bean映射”。 Orika拥有版本2的Apache许可证可以从https://github.com/orika-mapper/orika/archive/master.zip 源或http://search.maven.org/#search下载。 | ga | 1 | orika 二进制。 Orika对Javassist 用于字节码操作 SLF4J和paranamer 用于在运行时访问方法/构造函数参数名称具有依赖性 。 这三个依赖项中的两个JavaAssist和paranamer而不是SLF4J捆绑在orika-core-1.4.4-deps-included.jar 。 如果依赖项已经可用则可以使用更薄的orika-core-1.4.4.jar 。 就像这些JAR的名称所暗示的那样在本文中我使用Orika 1.4.4作为示例。 在我的《 推土机将JAXB对象映射到业务/域对象》一文中 我讨论了通常不希望将JAXB生成的类的实例用作业务或域对象的原因。 然后我展示了JAXB生成的类和自定义数据类之间的“传统”映射方式以便可以在业务域数据对象中的整个应用程序中传递数据。 在本文中我将使用相同的方法但是使用Orika进行映射而不是进行自定义映射或使用Dozer进行映射。 为了方便起见我在此处列出了JAXB生成的类com.blogspot.marxsoftware.AddressType和com.blogspot.marxsoftware.PersonType的成本清单以及重命名的自定义数据类dustin.examples.orikademo.Address和dustin.examples.orikademo.Person 。 JAXB生成的AddressType.java // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 // See a hrefhttp://java.sun.com/xml/jaxbhttp://java.sun.com/xml/jaxb/a // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2013.12.03 at 11:44:32 PM MST //package com.blogspot.marxsoftware;import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType;/*** pJava class for AddressType complex type.* * pThe following schema fragment specifies the expected content contained within this class.* * pre* complexType nameAddressType* complexContent* restriction base{http://www.w3.org/2001/XMLSchema}anyType* attribute namestreetAddress1 userequired type{http://www.w3.org/2001/XMLSchema}string /* attribute namestreetAddress2 type{http://www.w3.org/2001/XMLSchema}string /* attribute namecity userequired type{http://www.w3.org/2001/XMLSchema}string /* attribute namestate userequired type{http://www.w3.org/2001/XMLSchema}string /* attribute namezipcode userequired type{http://www.w3.org/2001/XMLSchema}string /* /restriction* /complexContent* /complexType* /pre* * */ XmlAccessorType(XmlAccessType.FIELD) XmlType(name AddressType) public class AddressType {XmlAttribute(name streetAddress1, required true)protected String streetAddress1;XmlAttribute(name streetAddress2)protected String streetAddress2;XmlAttribute(name city, required true)protected String city;XmlAttribute(name state, required true)protected String state;XmlAttribute(name zipcode, required true)protected String zipcode;/*** Gets the value of the streetAddress1 property.* * return* possible object is* {link String }* */public String getStreetAddress1() {return streetAddress1;}/*** Sets the value of the streetAddress1 property.* * param value* allowed object is* {link String }* */public void setStreetAddress1(String value) {this.streetAddress1 value;}/*** Gets the value of the streetAddress2 property.* * return* possible object is* {link String }* */public String getStreetAddress2() {return streetAddress2;}/*** Sets the value of the streetAddress2 property.* * param value* allowed object is* {link String }* */public void setStreetAddress2(String value) {this.streetAddress2 value;}/*** Gets the value of the city property.* * return* possible object is* {link String }* */public String getCity() {return city;}/*** Sets the value of the city property.* * param value* allowed object is* {link String }* */public void setCity(String value) {this.city value;}/*** Gets the value of the state property.* * return* possible object is* {link String }* */public String getState() {return state;}/*** Sets the value of the state property.* * param value* allowed object is* {link String }* */public void setState(String value) {this.state value;}/*** Gets the value of the zipcode property.* * return* possible object is* {link String }* */public String getZipcode() {return zipcode;}/*** Sets the value of the zipcode property.* * param value* allowed object is* {link String }* */public void setZipcode(String value) {this.zipcode value;}}JAXB生成的PersonType.java // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 // See a hrefhttp://java.sun.com/xml/jaxbhttp://java.sun.com/xml/jaxb/a // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2013.12.03 at 11:44:32 PM MST //package com.blogspot.marxsoftware;import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType;/*** pJava class for PersonType complex type.* * pThe following schema fragment specifies the expected content contained within this class.* * pre* complexType namePersonType* complexContent* restriction base{http://www.w3.org/2001/XMLSchema}anyType* sequence* element nameMailingAddress type{http://marxsoftware.blogspot.com/}AddressType/* element nameResidentialAddress type{http://marxsoftware.blogspot.com/}AddressType minOccurs0/* /sequence* attribute namefirstName type{http://www.w3.org/2001/XMLSchema}string /* attribute namelastName type{http://www.w3.org/2001/XMLSchema}string /* /restriction* /complexContent* /complexType* /pre* * */ XmlAccessorType(XmlAccessType.FIELD) XmlType(name PersonType, propOrder {mailingAddress,residentialAddress }) public class PersonType {XmlElement(name MailingAddress, required true)protected AddressType mailingAddress;XmlElement(name ResidentialAddress)protected AddressType residentialAddress;XmlAttribute(name firstName)protected String firstName;XmlAttribute(name lastName)protected String lastName;/*** Gets the value of the mailingAddress property.* * return* possible object is* {link AddressType }* */public AddressType getMailingAddress() {return mailingAddress;}/*** Sets the value of the mailingAddress property.* * param value* allowed object is* {link AddressType }* */public void setMailingAddress(AddressType value) {this.mailingAddress value;}/*** Gets the value of the residentialAddress property.* * return* possible object is* {link AddressType }* */public AddressType getResidentialAddress() {return residentialAddress;}/*** Sets the value of the residentialAddress property.* * param value* allowed object is* {link AddressType }* */public void setResidentialAddress(AddressType value) {this.residentialAddress value;}/*** Gets the value of the firstName property.* * return* possible object is* {link String }* */public String getFirstName() {return firstName;}/*** Sets the value of the firstName property.* * param value* allowed object is* {link String }* */public void setFirstName(String value) {this.firstName value;}/*** Gets the value of the lastName property.* * return* possible object is* {link String }* */public String getLastName() {return lastName;}/*** Sets the value of the lastName property.* * param value* allowed object is* {link String }* */public void setLastName(String value) {this.lastName value;}}域/业务类Address.java package dustin.examples.orikademo;import java.util.Objects;/*** Address class.* * author Dustin*/ public class Address {private String streetAddress1;private String streetAddress2;private String municipality;private String state;private String zipCode;public Address() {}public Address(final String newStreetAddress1,final String newStreetAddress2,final String newMunicipality,final String newState,final String newZipCode){this.streetAddress1 newStreetAddress1;this.streetAddress2 newStreetAddress2;this.municipality newMunicipality;this.state newState;this.zipCode newZipCode;}public String getStreetAddress1(){return this.streetAddress1;}public void setStreetAddress1(String streetAddress1){this.streetAddress1 streetAddress1;}public String getStreetAddress2(){return this.streetAddress2;}public void setStreetAddress2(String streetAddress2){this.streetAddress2 streetAddress2;}public String getMunicipality(){return this.municipality;}public void setMunicipality(String municipality){this.municipality municipality;}public String getState() {return this.state;}public void setState(String state){this.state state;}public String getZipCode() {return this.zipCode;}public void setZipCode(String zipCode){this.zipCode zipCode;}Overridepublic int hashCode(){return Objects.hash(this.streetAddress1, this.streetAddress2, this.municipality,this.state, this.zipCode);}Overridepublic boolean equals(Object obj){if (obj null) {return false;}if (getClass() ! obj.getClass()) {return false;}final Address other (Address) obj;if (!Objects.equals(this.streetAddress1, other.streetAddress1)){return false;}if (!Objects.equals(this.streetAddress2, other.streetAddress2)){return false;}if (!Objects.equals(this.municipality, other.municipality)){return false;}if (!Objects.equals(this.state, other.state)){return false;}if (!Objects.equals(this.zipCode, other.zipCode)){return false;}return true;}Overridepublic String toString(){return Address{ streetAddress1 streetAddress1 , streetAddress2 streetAddress2 , municipality municipality , state state , zipCode zipCode };}}域/业务类Person.java package dustin.examples.orikademo;import java.util.Objects;/*** Person class.* * author Dustin*/ public class Person {private String lastName;private String firstName;private Address mailingAddress;private Address residentialAddress;public Person() {}public Person(final String newLastName,final String newFirstName,final Address newResidentialAddress,final Address newMailingAddress){this.lastName newLastName;this.firstName newFirstName;this.residentialAddress newResidentialAddress;this.mailingAddress newMailingAddress;}public String getLastName(){return this.lastName;}public void setLastName(String lastName) {this.lastName lastName;}public String getFirstName(){return this.firstName;}public void setFirstName(String firstName){this.firstName firstName;}public Address getMailingAddress(){return this.mailingAddress;}public void setMailingAddress(Address mailingAddress){this.mailingAddress mailingAddress;}public Address getResidentialAddress(){return this.residentialAddress;}public void setResidentialAddress(Address residentialAddress){this.residentialAddress residentialAddress;}Overridepublic int hashCode(){int hash 3;hash 19 * hash Objects.hashCode(this.lastName);hash 19 * hash Objects.hashCode(this.firstName);hash 19 * hash Objects.hashCode(this.mailingAddress);hash 19 * hash Objects.hashCode(this.residentialAddress);return hash;}Overridepublic boolean equals(Object obj){if (obj null){return false;}if (getClass() ! obj.getClass()){return false;}final Person other (Person) obj;if (!Objects.equals(this.lastName, other.lastName)){return false;}if (!Objects.equals(this.firstName, other.firstName)){return false;}if (!Objects.equals(this.mailingAddress, other.mailingAddress)){return false;}if (!Objects.equals(this.residentialAddress, other.residentialAddress)){return false;}return true;}Overridepublic String toString() {return Person{ lastName lastName , firstName firstName , mailingAddress mailingAddress , residentialAddress residentialAddress };}} 与Dozer一样要映射的类需要具有无参数的构造函数以及“ set”和“ get”方法以支持双向转换而无需任何特殊的附加配置。 此外与Dozer一样Orika会自动映射同名字段并易于配置异常的映射名称不匹配的字段。 下一个代码清单针对我称为OrikaPersonConverter的类演示了OrikaPersonConverter MapperFactory的实例化和配置以默认情况下映射大多数字段并通过显式映射来映射名称彼此不同的字段 “市政”和“城市”组态。 一旦配置了MapperFactory 就可以轻松地从一个对象复制到另一个对象并且两个方向都在copyPersonTypeFromPerson和copyPersonFromPersonType方法中进行了描述。 OrikaPersonConverter package dustin.examples.orikademo;import com.blogspot.marxsoftware.AddressType; import com.blogspot.marxsoftware.PersonType; import ma.glasnost.orika.MapperFacade; import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.impl.DefaultMapperFactory;/*** Convert between instances of {link com.blogspot.marxsoftware.PersonType}* and {link dustin.examples.orikademo.Person}.* * author Dustin*/ public class OrikaPersonConverter {/** Orika Mapper Facade. */private final static MapperFacade mapper;static{final MapperFactory mapperFactory new DefaultMapperFactory.Builder().build();mapperFactory.classMap(Address.class, AddressType.class).field(municipality, city).byDefault().register();mapper mapperFactory.getMapperFacade();}/** No-arguments constructor. */public OrikaPersonConverter() {}/*** Provide an instance of {link com.blogspot.marxsoftware.PersonType}* that corresponds with provided {link dustin.examples.orikademo.Person} as* mapped by Dozer Mapper.* * param person Instance of {link dustin.examples.orikademo.Person} from which* {link com.blogspot.marxsoftware.PersonType} will be extracted.* return Instance of {link com.blogspot.marxsoftware.PersonType} that* is based on provided {link dustin.examples.orikademo.Person} instance.*/public PersonType copyPersonTypeFromPerson(final Person person){PersonType personType mapper.map(person, PersonType.class);return personType;}/*** Provide an instance of {link dustin.examples.orikademo.Person} that corresponds* with the provided {link com.blogspot.marxsoftware.PersonType} as * mapped by Dozer Mapper.* * param personType Instance of {link com.blogspot.marxsoftware.PersonType}* from which {link dustin.examples.orikademo.Person} will be extracted.* return Instance of {link dustin.examples.orikademo.Person} that is based on the* provided {link com.blogspot.marxsoftware.PersonType}.*/public Person copyPersonFromPersonType(final PersonType personType){Person person mapper.map(personType, Person.class);return person;} } 与Dozer的情况一样两个类之间的映射是双向的因此只需要进行一次映射并将应用于从一个对象到另一个对象的复制。 结论 像推土机一样Orika提供的可定制性和灵活性比本文中演示的要好得多。 但是对于相对简单的映射在使用JAXB生成的对象的应用程序中很常见Orika非常易于使用。 《 Orika用户指南》是了解Orika的一个很好的资源。 参考 Orika来自JCG合作伙伴 Dustin Marx在实际事件启发博客上将JAXB对象映射到业务/域对象 。 翻译自: https://www.javacodegeeks.com/2013/12/orika-mapping-jaxb-objects-to-businessdomain-objects.html
http://www.zqtcl.cn/news/454055/

相关文章:

  • 做移动网站快速排名软件正能量网站网址大全
  • 网站横幅代码山东省住房和城乡建设厅电话号码
  • 营销模式有哪些seo点击软件哪个好用
  • 信息流网站建设做网站换服务器怎么整
  • html5网站编写wordpress同步到本地
  • php商城网站开发工业设计在线
  • 网站建设发布实训总结网站自适应代码
  • 网站建设与管理是什么摄影网站 蜂鸟
  • 廊坊做网站的大公司wordpress+主题加速
  • 做网站还能挣钱吗网页端
  • 自适应网站建设推荐淘宝详情页设计
  • 手机网站域名设置深圳的网站建设公司怎么样
  • 余姚网站建设设计服务cms网站源码
  • 工作是套模板做网站想做网站制作运营注册什么公司核实
  • 北京网站建设116networdpress导航栏下拉菜单
  • 医院网站建设的目标网络服务许可证
  • 市场部做网站工作职责晋江论坛网
  • 网站怎么吸引人网站优化策略分析
  • 河北建设厅网站衡水网站建设培训学校
  • 新网网站空间到期停了 咋续费网站营销推广应该怎么做
  • 网站建设和编辑实训报告安卓版网页制作软件
  • 网站模板框架站长资讯
  • 上海做网站哪家公司2022年国际国内重大新闻
  • 网站建设如何定位网站建设思路方向
  • 手机网站拦截怎么解除网站生成软件免费制作
  • 中国房地产网站茂名住房和城乡建设厅网站
  • 做网站销售工资怎么样网页设计是哪个专业
  • 吉林省住房城乡建设厅网站首页微商城模板包含哪些
  • 优秀个人网站案例wordpress 文章格式
  • 2019年做网站装修平面设计图的制作