这篇文章主要介绍了Java spring怎么集成MapStruct的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Java Spring怎么集成MapStruct文章都会有所收获,下面我们一起
这篇文章主要介绍了Java spring怎么集成MapStruct的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Java Spring怎么集成MapStruct文章都会有所收获,下面我们一起来看看吧。
前言:
MapStruct支持Spring的依赖注入机制,只须要在@Mapper注解中添加componentModel配置项,并设置为“spring”便可。
@Getter@Setter@ToString@Builder@AllArgsConstructor@NoArgsConstructorpublic 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@NoArgsConstructorpublic 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”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网精选频道。
--结束END--
本文标题: Java Spring怎么集成MapStruct
本文链接: https://lsjlt.com/news/330764.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0