chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

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

3天內(nèi)不再提示

PO VO DTO轉(zhuǎn)換神器的思路

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

掃碼添加小助手

加入工程師交流群

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

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>

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

這種異常就是lombok編譯異常導(dǎo)致缺少get setter方法造成的。還有就是缺少構(gòu)造函數(shù)也會拋異常。

@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);

}

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

然后就可以直接用mapper進行實體的轉(zhuǎn)換了

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 轉(zhuǎn)換

屬性映射基于上面的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.多對象轉(zhuǎn)換到一個對象

@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);

}

	

		

轉(zhuǎn)自:toutiao.com/i6891531055631696395

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

    關(guān)注

    27

    文章

    9361

    瀏覽量

    155047
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4940

    瀏覽量

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

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    5大理由:聲學(xué)工程師為何依賴 GRAS 40PO 系列實現(xiàn)穩(wěn)定、可擴展的測試

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

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

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

    Vishay VO1401AEF固態(tài)繼電器技術(shù)深度解析

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

    協(xié)議轉(zhuǎn)換神器!Profinet轉(zhuǎn)Devicenet秒通,數(shù)據(jù)無縫集成

    在現(xiàn)代工業(yè)自動化領(lǐng)域,不同廠商的設(shè)備往往采用不同的通信協(xié)議,導(dǎo)致系統(tǒng)集成面臨挑戰(zhàn)。尤其在新材料生產(chǎn)領(lǐng)域,如不銹鋼寬板冷軋生產(chǎn)線,高精度、高實時性的通信需求使得協(xié)議轉(zhuǎn)換成為關(guān)鍵環(huán)節(jié)。其中,將
    的頭像 發(fā)表于 09-11 16:18 ?354次閱讀
    協(xié)議<b class='flag-5'>轉(zhuǎn)換</b><b class='flag-5'>神器</b>!Profinet轉(zhuǎn)Devicenet秒通,數(shù)據(jù)無縫集成

    開關(guān)電源維修思路及常見故障

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

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

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

    CCLINKIE轉(zhuǎn)PROFINET:電機的“網(wǎng)絡(luò)沖浪神器”!

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

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

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

    計算機網(wǎng)絡(luò)排錯思路總結(jié)

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

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

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

    XTR108 Vo端可以輸出0.5-2.5V電壓,而Io端口卻無法輸出4-20mA電流,為什么?

    使用萬用表可以測到Vo端子的電壓正常,但Io端口無法輸出正常電壓,Io接的負載電阻為150Ω,斷電時測得電阻40Ω,應(yīng)該是芯片內(nèi)部有電阻與其并聯(lián),即電阻應(yīng)該是正常的。不知道是什么問題?
    發(fā)表于 01-08 07:44

    TI_SN74LVC2G125DCUR為什么會有兩個Vo輸出,每個都代表什么意思?

    如上圖紅色圓圈部分,為什么會有兩個Vo輸出,每個都代表什么意思?以及為什么沒有在手冊中看到關(guān)于輸入阻抗?
    發(fā)表于 01-07 08:15

    DAC8550輸出公式為Vo=VREF/2+VREF*D/65536,上電初始,程序沒有運行時D的值是多少?

    DAC輸出公式為Vo=VREF/2+VREF*D/65536,上電初始,程序沒有運行時D的值是多少?
    發(fā)表于 12-16 07:32

    BUCK電路占空比對轉(zhuǎn)換效率的影響

    周期T_SW的比例,計算公式為D=T_ON/T_SW。在BUCK電路中,占空比D還可以根據(jù)伏秒積平衡原理計算,即VIN*TON=VO*TOFF,從而得出D=Vo/Vin(在忽略開關(guān)管和電感等元件的壓降時)。這里的Vo是輸出電壓,
    的頭像 發(fā)表于 12-12 15:39 ?4409次閱讀

    FPGA打磚塊小游戲設(shè)計思路

    HDL,?Vivado 平臺上開發(fā)打磚塊小游戲并使用 PS2 與 VGA 的基本思路: 一、整體架構(gòu)設(shè)計 1. 輸入模塊: ? PS2 接口模塊:負責與 PS2 設(shè)備(如游戲手柄)進行通信,接收手柄
    的頭像 發(fā)表于 12-09 16:57 ?1451次閱讀