认清现实,放弃幻想,准备斗争
借款信息列表
需求
一、后端实现
1、扩展实体对象
列表的结果需要关联查询,数据字典的数据也需要展示对应的文本内容而不是值,除了定义VO的方式,我们也可以使用扩展实体类的方式
在BorrowInfo类中扩展以下字段
//扩展字段 @ApiModelProperty(value = "姓名") @TableField(exist = false) private String name; @ApiModelProperty(value = "手机") @TableField(exist = false) private String mobile; @ApiModelProperty(value = "其他参数") @TableField(exist = false) private Map<String,Object> param = new HashMap<>();
2、Controller
添加 AdminBorrowInfoController
@Api(tags = "借款管理") @RestController @RequestMapping("/admin/core/borrowInfo") @Slf4j public class AdminBorrowInfoController { @Resource private BorrowInfoService borrowInfoService; @ApiOperation("借款信息列表") @GetMapping("/list") public R list() { List<BorrowInfo> borrowInfoList = borrowInfoService.selectList(); return R.ok().data("list", borrowInfoList); } }
3、Service
接口:BorrowInfoService
List<BorrowInfo> selectList();
实现:BorrowInfoServiceImpl
@Resource private DictService dictService; @Override public List<BorrowInfo> selectList() { List<BorrowInfo> borrowInfoList = baseMapper.selectBorrowInfoList(); borrowInfoList.forEach(borrowInfo -> { String returnMethod = dictService.getNameByParentDictCodeAndValue("returnMethod", borrowInfo.getReturnMethod()); String moneyUse = dictService.getNameByParentDictCodeAndValue("moneyUse", borrowInfo.getMoneyUse()); String status = BorrowInfoStatusEnum.getMsgByStatus(borrowInfo.getStatus()); borrowInfo.getParam().put("returnMethod", returnMethod); borrowInfo.getParam().put("moneyUse", moneyUse); borrowInfo.getParam().put("status", status); }); return borrowInfoList; }
4、Mapper
接口:BorrowInfoMapper
<select id="selectBorrowInfoList" resultType="com.atguigu.srb.core.pojo.entity.BorrowInfo"> SELECT bi.*, b.name, b.mobile FROM borrow_info AS bi LEFT JOIN borrower AS b ON bi.user_id = b.user_id WHERE bi.is_deleted = 0 </select>
BorrowInfoStatusEnum.getMsgByStatus
@Override public String getNameByparantDictAndValue(String dictCode,Integer value) { QueryWrapper<Dict> wrapper = new QueryWrapper<>(); wrapper.eq("dict_code",dictCode); Dict dict = baseMapper.selectOne(wrapper); if(dict==null){ return ""; } wrapper=new QueryWrapper<>(); wrapper.eq("parent_id",dict.getId()) .eq("value",value); Dict dict1 = baseMapper.selectOne(wrapper); if (dict1==null){ return ""; } return dict1.getName(); }