若依框架的导出功能
1.在单表的情况下:
直接模仿若依框架中自带的导出功能写即可
注意:需要在你所需要的实体类的字段上面添加导出表格的注解
javapublic class SysPost extends BaseEntity{
/** 岗位序号 */
@Excel(name = "岗位序号", cellType = ColumnType.NUMERIC)
private Long postId;
/** 岗位编码 */
@Excel(name = "岗位编码")
private String postCode;
/** 岗位名称 */
@Excel(name = "岗位名称")
private String postName;
/** 岗位排序 */
@Excel(name = "岗位排序")
private Integer postSort;
/** 状态(0正常 1停用) */
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private String status;
}
mapper
在这里插入代码片
public List<SysRole> selectRoleList(SysRole role);
ava<select id="selectRoleList"
<sql id="selectRoleVo">
select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
r.status, r.del_flag, r.create_time, r.remark
from sys_role r
left join sys_user_role ur on ur.role_id = r.role_id
left join sys_user u on u.user_id = ur.user_id
left join sys_dept d on u.dept_id = d.dept_id
</sql>
parameterType="SysRole" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
where r.del_flag = '0'
<if test="roleId != null and roleId != 0">
AND r.role_id = #{roleId}
</if>
<if test="roleName != null and roleName != ''">
AND r.role_name like concat('%', #{roleName}, '%')
</if>
<if test="status != null and status != ''">
AND r.status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND r.role_key like concat('%', #{roleKey}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by r.role_sort
</select>
controller
在这里插入代码片
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:role:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, SysRole role)
{
List<SysRole> list = roleService.selectRoleList(role);
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
util.exportExcel(response, list, "角色数据");
}
2.一多一或者一对多
一对一:主表与从表:主表中的一条数据对应从表中的一条数据
一对多:主表与从表:主表中的一条数据对应从表中的多条数据
两者均可以参考以下方法
注:一对多的情况下,在一个实体类中不可以使用另外一个类list集合作为属性,要用实体类对象
实体类
在这里插入代码片
public class RatingSheetAndJudeInfo extends BaseEntity {
@Excel(name = "评级单编号")
private String ratingSheetNumber;
@Excel(name = "服务类型 单品1 同类套装2 非同类套装3")
private Integer serveType;
@Excel(name = "手机号")
private String reviewerPhone;
//这里是一个对象,必须将此对象内需要导出的字段在此标出
@Excels({
@Excel(name = "姓名", targetAttr = "reviewerName", type = Excel.Type.EXPORT)
})
private Reviewer reviewer;
@Excels({
@Excel(name = "城市", targetAttr = "provincesCities", type = Excel.Type.EXPORT),
@Excel(name = "详细地址", targetAttr = "fullAddress", type = Excel.Type.EXPORT)
})
private ReviewerAddress reviewerAddress;
//这里是一个对象,必须将此对象内需要导出的字段在此标出
@Excels({
@Excel(name = "名称", targetAttr = "judeName", type = Excel.Type.EXPORT),
@Excel(name = "查询编码", targetAttr = "searchEncoding", type = Excel.Type.EXPORT),
@Excel(name = "形态", targetAttr = "judeType", type = Excel.Type.EXPORT),
@Excel(name = "赔付等级", targetAttr = "compensation", type = Excel.Type.EXPORT),
@Excel(name = "级别", targetAttr = "judeRank", type = Excel.Type.EXPORT),
@Excel(name = "分数", targetAttr = "mark", type = Excel.Type.EXPORT),
@Excel(name = "状态1", targetAttr = "status", type = Excel.Type.EXPORT),
@Excel(name = "状态2", targetAttr = "statusTwo", type = Excel.Type.EXPORT),
@Excel(name = "鉴定结果", targetAttr = "result", type = Excel.Type.EXPORT)
})
private Jude judeList;
}
public class Jude implements Serializable, Entity {
@Excel(name = "查询编码", type = Excel.Type.IMPORT)
private String searchEncoding;
@Excel(name = "名称")
private String judeName;
@Excel(name = "形态:1:单品2:同套3:非同套")
private Integer judeType;
@Excel(name = "赔付等级")
private String compensation;
@Excel(name = "级别")
private String judeRank;
@Excel(name = "分数")
private String mark;
@Excel(name = "状态1")
private String status;
@Excel(name = "状态2")
private String statusTwo;
@Excel(name = "鉴定结果")
private String result;
}
public class ReviewerAddress implements Serializable {
private Long reviewerId;
@Excel(name = "省区")
private String provincesCities;
@Excel(name = "详细地址")
private String fullAddress;
}
mapper
在这里插入代码片
List<RatingSheetAndJudeInfo> findAllList(@Param("id") Long id);
//注意此处必须做映射
<resultMap id="BaseMapInfo" type="com.xchk.pojo.dto.RatingSheetAndJudeInfo">
<result column="rating_sheet_number" property="ratingSheetNumber"/>
<result column="serve_type" property="serveType"/>
<result column="reviewer_phone" property="reviewerPhone"/>
<association property="reviewer" javaType="com.xchk.entity.Reviewer">
<result column="reviewer_name" property="reviewerName"/>
</association>
<association property="reviewerAddress" javaType="com.xchk.entity.ReviewerAddress">
<result column="provinces_cities" property="provincesCities"/>
<result column="full_address" property="fullAddress"/>
</association>
<association property="judeList" javaType="com.xchk.entity.Jude">
<result column="jude_name" property="judeName"/>
<result column="search_encoding" property="searchEncoding"/>
<result column="jude_type" property="judeType"/>
<result column="rate_consumable" property="rateConsumable"/>
<result column="detail_describe" property="detailDescribe"/>
<result column="compensation" property="compensation"/>
<result column="mark" property="mark"/>
<result column="status" property="status"/>
<result column="status_two" property="statusTwo"/>
<result column="result" property="result"/>
</association>
</resultMap>
<select id="findAllList" resultMap="BaseMapInfo">
select
r.rating_sheet_number ,r.serve_type,r.reviewer_phone,re.reviewer_name,
ra.provinces_cities,ra.full_address,
j.jude_name,j.search_encoding,j.jude_type,j.rate_consumable,j.detail_describe,j.jude_rank,
j.compensation,j.mark,j.status,j.status_two,j.result
from rating_sheet r
left join jude j on r.id=j.rating_sheet_id and j.is_deleted = 0
left join reviewer re on re.reviewer_phone =r.reviewer_phone and re.is_deleted = 0
left join reviewer_address ra on ra.reviewer_id=re.id and ra.is_deleted = 0 and ra.is_default=1
where r.is_deleted = 0
and r.id=#{id}
</select>
controller
在这里插入代码片
@Log(title = "", businessType = BusinessType.EXPORT)
@GetMapping("/export")//此处psot和get请求都可以具体的需要跟前端一起定义
public void export(HttpServletResponse response, @RequestParam("id") Long id) {
List<RatingSheetAndJudeInfo> list = ratingSheetService.findAllList(id);
ExcelUtil<RatingSheetAndJudeInfo> util = new ExcelUtil<>(RatingSheetAndJudeInfo.class);
util.exportExcel(response, list, "评级");
}
后端按照若依框架的导出,比葫芦画瓢就可以了