java使用easypoi批量导入excel
java使用easypoi批量导入excel
实体类:
import cn.afterturn.easypoi.excel.annotation.Excel;
public class InputStuEntity {
private Integer id;
@Excel(name = "姓名")
private String name;
@Excel(name = "性别",replace = {"男_1", "女_0"})
private Integer sex;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "身份证号")
private String id_card;
@Excel(name = "高中院校")
private String middleschoolName;
private Integer middleschool;
@Excel(name = "班级")
private String class_name;
@Excel(name = "班主任姓名")
private String teacherName;
private Integer teacher;
@Excel(name = "意向院校")
private String intention_schoolName;
private Integer intention_school;
@Excel(name = "生源地省")
private String provinceidName;
private Integer provinceid;
@Excel(name = "生源地市")
private String cityidName;
private Integer cityid;
@Excel(name = "生源地县")
private String countyidName;
private Integer countyid;
@Excel(name = "考生号")
private String ks_number;
@Excel(name = "学生类型",replace = {"高中_1", "职高_2","中专_3","初中_4","其他_5"})
private Integer stu_type;
@Excel(name = "QQ")
private String qq;
@Excel(name = "微信")
private String weixin;
private Long userId;
@Override
public String toString() {
return "InputStuEntity [id=" + id + ", name=" + name + ", sex=" + sex + ", mobile=" + mobile + ", id_card="
+ id_card + ", middleschoolName=" + middleschoolName + ", middleschool=" + middleschool
+ ", class_name=" + class_name + ", teacherName=" + teacherName + ", teacher=" + teacher
+ ", intention_schoolName=" + intention_schoolName + ", intention_school=" + intention_school
+ ", provinceidName=" + provinceidName + ", provinceid=" + provinceid + ", cityidName=" + cityidName
+ ", cityid=" + cityid + ", countyidName=" + countyidName + ", countyid=" + countyid + ", ks_number="
+ ks_number + ", stu_type=" + stu_type + ", qq=" + qq + ", weixin=" + weixin + ", userId=" + userId
+ "]";
}
public String getCityidName() {
return cityidName;
}
public void setCityidName(String cityidName) {
this.cityidName = cityidName;
}
public Integer getCityid() {
return cityid;
}
public void setCityid(Integer cityid) {
this.cityid = cityid;
}
public String getCountyidName() {
return countyidName;
}
public void setCountyidName(String countyidName) {
this.countyidName = countyidName;
}
public Integer getCountyid() {
return countyid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setCountyid(Integer countyid) {
this.countyid = countyid;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getId_card() {
return id_card;
}
public void setId_card(String id_card) {
this.id_card = id_card;
}
public String getMiddleschoolName() {
return middleschoolName;
}
public void setMiddleschoolName(String middleschoolName) {
this.middleschoolName = middleschoolName;
}
public Integer getMiddleschool() {
return middleschool;
}
public void setMiddleschool(Integer middleschool) {
this.middleschool = middleschool;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public Integer getTeacher() {
return teacher;
}
public void setTeacher(Integer teacher) {
this.teacher = teacher;
}
public String getIntention_schoolName() {
return intention_schoolName;
}
public void setIntention_schoolName(String intention_schoolName) {
this.intention_schoolName = intention_schoolName;
}
public Integer getIntention_school() {
return intention_school;
}
public void setIntention_school(Integer intention_school) {
this.intention_school = intention_school;
}
public String getProvinceidName() {
return provinceidName;
}
public void setProvinceidName(String provinceidName) {
this.provinceidName = provinceidName;
}
public Integer getProvinceid() {
return provinceid;
}
public void setProvinceid(Integer provinceid) {
this.provinceid = provinceid;
}
public String getKs_number() {
return ks_number;
}
public void setKs_number(String ks_number) {
this.ks_number = ks_number;
}
public Integer getStu_type() {
return stu_type;
}
public void setStu_type(Integer stu_type) {
this.stu_type = stu_type;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getWeixin() {
return weixin;
}
public void setWeixin(String weixin) {
this.weixin = weixin;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
}
控制层转换为对象
/**
* 导入
* @param file
* @return
*/
@ResponseBody
@RequestMapping("import")
public AjaxResult inputStudentMessage(@RequestParam("file")MultipartFile file) {
ImportParams params = new ImportParams();
List<InputStuEntity> list = null;
try {
params.setTitleRows(0);
params.setHeadRows(1);
params.setImportFields(new String[]{"序号", "姓名", "性别", "手机号", "身份证号", "高中院校","班级","班主任姓名","意向院校", "生源地省", "生源地市", "生源地县", "考生号", "学生类型", "QQ", "微信"});
list = ExcelImportUtil.importExcel(file.getInputStream(), InputStuEntity.class, params);
} catch (Exception e) {
e.printStackTrace();
AjaxResult.fail("文件转换异常");
}
try {
Long userId=getUserId();
String m = cjStudentService.inp(list,userId);
if(m==null) {
return AjaxResult.success("导入成功");
}else {
return AjaxResult.fail(m);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return AjaxResult.fail("导入异常");
}
}
List<InputStuEntity> list = null; 这个集合就是转换的对象
猜你喜欢
框架
1632
最近在项目中遇到了一个批量导入excel的功能,excel导入用到的是esaypoi,可以轻松将excel中的数据封装成对象,但是不知为何,突然转换对象的过程变得很慢,一万条数据得转换一分钟。无奈只
weblog
2765
java使用easypoi导出并下载excel文件简单导出测试如图:一、pom文件dependencygroupIdcn.afterturn/groupIdartifactIdeasypoi
weblog
6102
java使用easypoi导出excel时进行值替换如导出性别:数据库中储存的是数字,1代表男,2代表女。导出的时候需要是汉字。在实体类中使用@Excel注解。 @Excel(name="性别
算法基础
2268
什么是jxlsjxls是一个简单的、轻量级的excel导出库,使用特定的标记在excel模板文件中来定义输出格式和布局。其实java中成熟的excel导出工具有pol、jxl,但他们都是使用java
算法基础
3736
Pom依赖dependency
groupIdcn.afterturn/groupId
artifactIdeasypoi-base/artifactId
version4.0.0/version
/dependency
dependency
groupIdcn.afterturn/groupId
artifactIdeasypoi-web/artifactId
version4.0.0/ver
spring/springmvc
2776
1.easypoi的pom依赖dependency groupIdcn.afterturn/groupId artifactIdeasypoi-base/artifactId
blog
mybatis 批量更新数据 mysql
数据库基础
4337
mybatis批量更新数据mysql方式1简单粗暴,写一个更新的方法,循环调用就是了,但是效率就比较低了。性能较差。方式2批处理,类似于:UPDATEstuSETname='jia',score
blog
mysql批量更新生成不同的uuid
数据库
2781
mysql批量更新生成不同的uuidsql语句:UPDATEusersetuuid=UUID();去掉中间的-UPDATEusersetuuid=REPLACE(uuid,"-","");注意这两个
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。