Java Spring集成MapStruct詳情
更新時間:2022年06月02日 17:21:16 作者:梁云亮
這篇文章主要介紹了Java Spring集成MapStruct詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
前言:
MapStruct支持Spring的依賴注入機(jī)制,只須要在@Mapper注解中添加componentModel配置項,并設(shè)置為“spring”便可。
待轉(zhuǎn)換的類
@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)類
@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);
}測試類
@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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java中LinkedList使用迭代器優(yōu)化移除批量元素原理
本文主要介紹了java中LinkedList使用迭代器優(yōu)化移除批量元素原理,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-10-10
springboot加載命令行參數(shù)ApplicationArguments的實現(xiàn)
本文主要介紹了springboot加載命令行參數(shù)ApplicationArguments的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

