Python 官方文档:入门教程 => 点击学习
目录待转换的类目标类转换接口测试类前言: MapStruct支持spring的依赖注入机制,只须要在@Mapper注解中添加componentModel配置项,并设置为“
前言:
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详情的文章就介绍到这了,更多相关Spring集成MapStruct内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: JavaSpring集成MapStruct详情
本文链接: https://lsjlt.com/news/150494.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0