@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@TableName("employer")
public class BizEmployer extends Model<BizEmployer> {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@Excel(name = "姓名",width = 25)
private String name;
private Integer sex;
@TableField(exist = false)
@ApiModelProperty(value="性别")
private String sexStr;
@TableField(exist = false)
@ApiModelProperty(value="年龄")
private String age;
@Excel(name = "身份证号",width = 25)
@TableField("id_card")
@ApiModelProperty(value="身份证号")
private String idCard;
.......
@RequestMapping(value = "/uploadExcel", method = RequestMethod.POST)
public ResponseData uploadExcel(HttpServletRequest request, MultipartFile file) {
ImportParams importParams = new ImportParams();
importParams.setTitleRows(1);
List<BizEmployer> result;
try {
result = ExcelImportUtil.importExcel(file.getInputStream(), BizEmployer.class, importParams);
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(500, "表格导入错误!");
}
if (ToolUtil.isEmpty(result)) {
throw new BusinessException(BizExceptionEnum.EXCEL_EMPTY);
}
List<BizEmployer> errorList = employerService.importExcel(result);
request.getSession().setAttribute("employerList", errorList);
return new ResponseData<>(errorList.size() == 0);
}