Java Spring集成MapStruct詳情
前言:
MapStruct支持Spring的依賴(lài)注入機(jī)制,只須要在@Mapper注解中添加componentModel配置項(xiàng),并設(shè)置為“spring”便可。
待轉(zhuǎn)換的類(lèi)
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Spu {
private Integer id;
private String name;
private String caption;
private String pics;
private String specs;
private String unit;
private Integer hot;
private Integer comments;
private Integer agrees;
private Integer recommend;
private Integer status;
private String service;
private String info;
private Integer countryId;
private String addr;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}目標(biāo)類(lèi)
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SpuVO {
private Integer id;
private String name;
private String caption;
private String pics;
private String specs;
private String unit;
private String service;
private String addr;
}轉(zhuǎn)換接口
@Mapper(componentModel = "spring")
public interface SpuTrans {
List<SpuVO> spuList2SpuVOList(List<Spu> spuList);
}測(cè)試類(lèi)
@Controller
@RequestMapping()
public class IndexController {
@Resource
private SpuTrans spuTrans;
@Resource
private SpuService spuService;
@GetMapping("/list")
public ModelAndView list(ModelAndView mav) {
//輪播圖
List<Spu> spuList = spuService.selectAll();
List<SpuVO> spuVOList = spuTrans.spuList2SpuVOList(spuList);
mav.addObject("spuVOList", spuVOList);
mav.setViewName("spu_list");
return mav;
}
}到此這篇關(guān)于Java Spring集成MapStruct詳情的文章就介紹到這了,更多相關(guān)Spring集成MapStruct內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java中LinkedList使用迭代器優(yōu)化移除批量元素原理
本文主要介紹了java中LinkedList使用迭代器優(yōu)化移除批量元素原理,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
動(dòng)態(tài)代理模擬實(shí)現(xiàn)aop的示例
下面小編就為大家?guī)?lái)一篇?jiǎng)討B(tài)代理模擬實(shí)現(xiàn)aop的示例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望對(duì)大家有所幫助2017-11-11
Springboot mybatis常見(jiàn)配置問(wèn)題解決
這篇文章主要介紹了Springboot mybatis常見(jiàn)配置問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11
springboot加載命令行參數(shù)ApplicationArguments的實(shí)現(xiàn)
本文主要介紹了springboot加載命令行參數(shù)ApplicationArguments的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

