您好,登錄后才能下訂單哦!
這篇文章主要介紹了Java Spring怎么集成MapStruct的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇Java Spring怎么集成MapStruct文章都會有所收獲,下面我們一起來看看吧。
前言:
MapStruct支持Spring的依賴注入機制,只須要在@Mapper注解中添加componentModel配置項,并設置為“spring”便可。
@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; }
@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; }
@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; } }
關于“Java Spring怎么集成MapStruct”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“Java Spring怎么集成MapStruct”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。