这篇文章主要介绍了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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。