国产精品久久久aaaa,日日干夜夜操天天插,亚洲乱熟女香蕉一区二区三区少妇,99精品国产高清一区二区三区,国产成人精品一区二区色戒,久久久国产精品成人免费,亚洲精品毛片久久久久,99久久婷婷国产综合精品电影,国产一区二区三区任你鲁

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

PO VO DTO轉換神器的思路

Linux愛好者 ? 來源:今日頭條 ? 作者:bettermann ? 2021-10-12 11:13 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

當然有的人喜歡寫get set,或者用BeanUtils 進行復制,代碼只是工具,本文只是提供一種思路。

pom 配置:

<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<maven.compiler.source>1.8maven.compiler.source>
<maven.compiler.target>1.8maven.compiler.target>
<org.mapstruct.version>1.4.1.Finalorg.mapstruct.version>
<org.projectlombok.version>1.18.12org.projectlombok.version>
properties>

<dependencies>
<dependency>
<groupId>org.mapstructgroupId>
<artifactId>mapstructartifactId>
<version>${org.mapstruct.version}version>
dependency>


<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<version>${org.projectlombok.version}version>
<scope>providedscope>
dependency>


<dependency>
<groupId>org.mapstructgroupId>
<artifactId>mapstruct-processorartifactId>
<version>${org.mapstruct.version}version>
<scope>providedscope>
dependency>

dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<version>3.8.1version>
<configuration>
<source>1.8source>
<target>1.8target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<version>${org.projectlombok.version}version>
path>
<path>
<groupId>org.mapstructgroupId>
<artifactId>mapstruct-processorartifactId>
<version>${org.mapstruct.version}version>
path>
annotationProcessorPaths>
configuration>
plugin>
plugins>
build>

關于lombok和mapstruct的版本兼容問題多說幾句,maven插件要使用3.6.0版本以上、lombok使用1.16.16版本以上,另外編譯的lombok mapstruct的插件不要忘了加上。否則會出現下面的錯誤:No property named "aaa" exists in source parameter(s). Did you mean "null"?

這種異常就是lombok編譯異常導致缺少get setter方法造成的。還有就是缺少構造函數也會拋異常。

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
publicclassStudent{

privateStringname;
privateintage;
privateGenderEnumgender;
privateDoubleheight;
privateDatebirthday;

}
publicenumGenderEnum{
Male("1","男"),
Female("0","女");

privateStringcode;
privateStringname;

publicStringgetCode(){
returnthis.code;
}

publicStringgetName(){
returnthis.name;
}

GenderEnum(Stringcode,Stringname){
this.code=code;
this.name=name;
}
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
publicclassStudentVO{
privateStringname;
privateintage;
privateStringgender;
privateDoubleheight;
privateStringbirthday;
}
@Mapper
publicinterfaceStudentMapper{

StudentMapperINSTANCE=Mappers.getMapper(StudentMapper.class);

@Mapping(source="gender.name",target="gender")
@Mapping(source="birthday",target="birthday",dateFormat="yyyy-MM-ddHHss")
StudentVOstudent2StudentVO(Studentstudent);

}

實體類是開發過程少不了的,就算是用工具生成肯定也是要有的,需要手寫的部分就是這個Mapper的接口,編譯完成后會自動生成相應的實現類

然后就可以直接用mapper進行實體的轉換了

publicclassTest{

publicstaticvoidmain(String[]args){

Studentstudent=Student.builder().name("小明").age(6).gender(GenderEnum.Male).height(121.1).birthday(newDate()).build();
System.out.println(student);
//這行代碼便是實際要用的代碼
StudentVOstudentVO=StudentMapper.INSTANCE.student2StudentVO(student);
System.out.println(studentVO);

}

}

mapper可以進行字段映射,改變字段類型,指定格式化的方式,包括一些日期的默認處理。

可以手動指定格式化的方法:

@Mapper
publicinterfaceStudentMapper{

StudentMapperINSTANCE=Mappers.getMapper(StudentMapper.class);

@Mapping(source="gender",target="gender")
@Mapping(source="birthday",target="birthday",dateFormat="yyyy-MM-ddHHss")
StudentVOstudent2StudentVO(Studentstudent);

defaultStringgetGenderName(GenderEnumgender){
returngender.getName();
}

}

上面只是最簡單的實體映射處理,下面介紹一些高級用法

1.List 轉換

屬性映射基于上面的mapping配置

@Mapper
publicinterfaceStudentMapper{

StudentMapperINSTANCE=Mappers.getMapper(StudentMapper.class);

@Mapping(source="gender.name",target="gender")
@Mapping(source="birthday",target="birthday",dateFormat="yyyy-MM-ddHHss")
StudentVOstudent2StudentVO(Studentstudent);


Liststudents2StudentVOs(ListstudentList);

}
publicstaticvoidmain(String[]args){

Studentstudent=Student.builder().name("小明").age(6).gender(GenderEnum.Male).height(121.1).birthday(newDate()).build();

Listlist=newArrayList<>();
list.add(student);
Listresult=StudentMapper.INSTANCE.students2StudentVOs(list);
System.out.println(result);
}

2.多對象轉換到一個對象

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
publicclassStudent{

privateStringname;
privateintage;
privateGenderEnumgender;
privateDoubleheight;
privateDatebirthday;

}
@Data
@AllArgsConstructor
@Builder
@NoArgsConstructor
publicclassCourse{

privateStringcourseName;
privateintsortNo;
privatelongid;

}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
publicclassStudentVO{
privateStringname;
privateintage;
privateStringgender;
privateDoubleheight;
privateStringbirthday;
privateStringcourse;
}
@Mapper
publicinterfaceStudentMapper{

StudentMapperINSTANCE=Mappers.getMapper(StudentMapper.class);

@Mapping(source="student.gender.name",target="gender")
@Mapping(source="student.birthday",target="birthday",dateFormat="yyyy-MM-ddHHss")
@Mapping(source="course.courseName",target="course")
StudentVOstudentAndCourse2StudentVO(Studentstudent,Coursecourse);

}
publicclassTest{

publicstaticvoidmain(String[]args){

Studentstudent=Student.builder().name("小明").age(6).gender(GenderEnum.Male).height(121.1).birthday(newDate()).build();
Coursecourse=Course.builder().id(1L).courseName("語文").build();

StudentVOstudentVO=StudentMapper.INSTANCE.studentAndCourse2StudentVO(student,course);
System.out.println(studentVO);
}

}

3.默認值

@Mapper
publicinterfaceStudentMapper{

StudentMapperINSTANCE=Mappers.getMapper(StudentMapper.class);

@Mapping(source="student.gender.name",target="gender")
@Mapping(source="student.birthday",target="birthday",dateFormat="yyyy-MM-ddHHss")
@Mapping(source="course.courseName",target="course")
@Mapping(target="name",source="student.name",defaultValue="張三")
StudentVOstudentAndCourse2StudentVO(Studentstudent,Coursecourse);

}

	

		

轉自:toutiao.com/i6891531055631696395

責任編輯:haq
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 轉換器
    +關注

    關注

    27

    文章

    9418

    瀏覽量

    156355
  • 代碼
    +關注

    關注

    30

    文章

    4968

    瀏覽量

    73973
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    疆鴻智能讓PROFINET與CANopen無縫對話:揭秘智慧物流的“網關”神器

    疆鴻智能讓PROFINET與CANopen無縫對話:揭秘智慧物流的“網關”神器 隨著工業4.0和智能制造的深入推進,工業現場總線技術正在經歷一場深刻的變革。在復雜的自動化產線中,沒有任何一種通訊協議
    的頭像 發表于 02-24 15:49 ?117次閱讀
    疆鴻智能讓PROFINET與CANopen無縫對話:揭秘智慧物流的“網關”<b class='flag-5'>神器</b>

    5大理由:聲學工程師為何依賴 GRAS 40PO 系列實現穩定、可擴展的測試

    當聲學驗證需要兼顧可重復性與測量速度時,測量鏈中任何微小的低效環節都可能產生疊加影響。無論您正在驗證移動設備、音頻電子設備還是聲學傳感器,傳聲器都不應成為變量因素。GRAS40PO-L和40PO
    的頭像 發表于 11-17 09:04 ?675次閱讀
    5大理由:聲學工程師為何依賴 GRAS 40<b class='flag-5'>PO</b> 系列實現穩定、可擴展的測試

    CW32的ADC視線,DMA擴展采樣思路

    如果需要對超過 4 路的模擬量進行采樣,則需要結合 DMA 的功能,以實現較少的 CPU 參與。其思路如下: 1.ADC 配置為單通道單次轉換,完成轉換后硬件觸發 DMA; 2.DMA
    發表于 11-13 08:09

    橢偏光譜技術在VO?薄膜光誘導IMT中的應用:瞬態介電函數的動力學路徑解析

    二氧化釩(VO?)作為一種強關聯電子材料,在約68°C時會發生絕緣體-金屬相變(IMT),并伴隨晶體結構變化,這一現象使其在超快光子器件(如光開關和調制器)中具有巨大應用潛力。然而,要實現對其光誘導
    的頭像 發表于 11-12 18:02 ?481次閱讀
    橢偏光譜技術在<b class='flag-5'>VO</b>?薄膜光誘導IMT中的應用:瞬態介電函數的動力學路徑解析

    Vishay VO1401AEF固態繼電器技術深度解析

    通電阻和 3750V~RMS~ 隔離測試電壓。VO1401AEF固態繼電器提供無抖動的開關操作,并配有與TTL/CMOS兼容的輸入。該繼電器用于安防系統、儀器儀表和工業控制應用。
    的頭像 發表于 11-10 15:43 ?636次閱讀
    Vishay <b class='flag-5'>VO</b>1401AEF固態繼電器技術深度解析

    協議轉換神器!Profinet轉Devicenet秒通,數據無縫集成

    在現代工業自動化領域,不同廠商的設備往往采用不同的通信協議,導致系統集成面臨挑戰。尤其在新材料生產領域,如不銹鋼寬板冷軋生產線,高精度、高實時性的通信需求使得協議轉換成為關鍵環節。其中,將
    的頭像 發表于 09-11 16:18 ?485次閱讀
    協議<b class='flag-5'>轉換</b><b class='flag-5'>神器</b>!Profinet轉Devicenet秒通,數據無縫集成

    【精選直播】無感FOC控制中滑模觀測器估算轉子角度思路分享

    直播預告掃碼購買課程&預約直播直播亮點1、FOC無感控制框圖分析2、電機數學模型回顧3、轉子位置角求取思路4、滑模觀測器思路分享5、滑模觀測器的實現直播大綱1、無感FOC控制框圖分析2、電機
    的頭像 發表于 08-05 08:06 ?1159次閱讀
    【精選直播】無感FOC控制中滑模觀測器估算轉子角度<b class='flag-5'>思路</b>分享

    開關電源維修思路及常見故障

    開關電源的維修思路及常見故障處理是電子技術人員需要掌握的重要技能。以下是對開關電源維修思路及常見故障的詳細分析。 ? 一、開關電源維修思路 1. 斷電檢查: ? ? ● ?外觀檢查:打開電源的外殼
    的頭像 發表于 08-03 07:38 ?2476次閱讀

    流量計連接神器 CClinkie轉Modbus RTU:工程師的「斷舍離」指南

    不必要的成本。有沒有一種\"斷舍離\"的方法,讓工程師擺脫這個煩惱?答案就是耐達訊通信技術CClinkie轉Modbus RTU的轉換方案。 方案概述: CClinkie轉
    發表于 06-24 13:53

    (ST大賽三等獎作品)超聲波自拍神器實例項目

    (ST大賽三等獎作品)超聲波自拍神器電路圖:
    發表于 05-28 21:04

    CCLINKIE轉PROFINET:電機的“網絡沖浪神器”!

    PROFINET的大家庭。有了它,電機就像裝上了“智能小馬達”,和其他設備的配合那叫一個默契,生產效率直接“起飛”! 在這里,我必須給大家推薦一款“神器”——耐達訊NY-N831 -CCLINKIE網關。這
    發表于 05-28 15:21

    全屋燈光秒變聰明,這個提升幸福感的神器你還沒安排嗎?

    全屋燈光秒變聰明這個提升幸福感的神器你還沒安排嗎?我寶子們,你是否受夠了摸黑找開關的狼狽、手動調光的繁瑣,或是永遠調不出理想氛圍的無奈?作為專注智能燈控方案的我們,今天就來揭秘——如何讓家里的燈光
    的頭像 發表于 05-14 18:15 ?1287次閱讀
    全屋燈光秒變聰明,這個提升幸福感的<b class='flag-5'>神器</b>你還沒安排嗎?

    推薦兩款菲力爾氣體泄漏檢測神器

    在石化行業,氣體泄漏是安全生產的“大敵”。如何快速、精準地檢測泄漏,成了企業關注的焦點。今天,小菲就帶大家聊聊菲力爾的兩款“氣體泄漏檢測神器”——FLIR Si2x系列聲學成像儀和Gx系列光學氣體成像熱像儀。它們都能“看到”氣體泄漏的畫面,但有哪些不同呢?一起來瞧瞧吧。
    的頭像 發表于 04-07 11:22 ?1020次閱讀

    計算機網絡排錯思路總結

    明人不說暗話,這篇文章我們來聊一個非常有用,同時也是程序員必備的技能,那就是網絡排錯思路大總結。
    的頭像 發表于 04-01 17:32 ?891次閱讀
    計算機網絡排錯<b class='flag-5'>思路</b>總結

    使用nonai_2d的CRC功能進行圖像類型轉換,nonai_2d模塊的要如何使用?

    我希望使用nonai_2d的CRC功能進行圖像類型轉換,參考sample_mcm例程添加了對應的start和exit,并且做了sys_bind,也申請了vb,但是運行之后系統一直提示類似沒有緩沖區
    發表于 03-11 06:44