spring boot2 整合(一)Mybatis (非常完整!)

spring boot2 整合(一)Mybatis (非常完整!)

摘要 Excel文件转换为javabean日常用Apache
POI工具,那几个工具是非常操作微软办办公软件的。尽管相比简单,不过相比费时费事,未有提供xlsToBean那样给力的艺术。此次正好有这一个须要,看了同事们的方式~~Orz给跪。既然是技术员,那么就绝不用人力消除难点,而是用算法化解它,所以照旧间接写工具,方便自身,也可以有利客人。

JAVA可以使用jxl轻松便捷的读取文件的内容,可是出于版本限制,只可以读取97-03
 xls格式的Excel。

  在各个管理连串中,数据的导入导出是日常使用的效用,平时导入导出以Excel、CSV格式居多。借使是读书的历程中,最佳是协调达成数据导入与导出的功力,可是在类型中,依然调用现有的听从对比好。前段时间径直利用一款称为JeeSite的开源项目来开展一次开拓,就记录一下该类型对于Excel导入导出数据的历程。JeeSite提供了很好的Excel的导入导出功效,遮盖了底部的不菲兑现,通过简单的套路式步骤就能够成功多少的Excel数据的导入导出。对于未有采用过JeeSite的能够毫无往下看了,因为上面包车型大巴代码是跟JeeSite二遍开拓相关的代码,不做JeeSite的三回开荒,以下代码对您无用,在此处友情提醒,制止浪费您宝贵的时光。

整合Mybatis分为二种形式,一种是xml配置,一种是表明。作者在此处最重要放在xml配置上,因为如若想用注明的话,提议直接用jpa取代,因为Jpa有更成熟的CRUD接口更有益开采。作者在后文中也会把评释方式说精晓。

先看看同事的格局

本文是类别中用到的贰个实例,先经过上传xls文件(包罗日期),再经过jxl进行读取上传的xls文件(文件格式见下user.xls),分析不为空的行与列,写入数据库。

 

粗粗介绍下流程:

public static List<JavaBean> getListByExcel(String file) throws BiffException, IOException, MyException{ List<JavaBean> list=new ArrayList<JavaBean>(); Workbook rwb=Workbook.getWorkbook(new File; Sheet rs=rwb.getSheet; if { throw new MyException; } int rows=rs.getRows(); for (int i = 1; i < rows; i++) { if(rs.getCell.getContents()==null||rs.getCell.getContents().equals { break; } String name=rs.getCell.getContents(); String format=rs.getCell.getContents(); String unit=rs.getCell.getContents(); String factory=rs.getCell.getContents(); String price=rs.getCell.getContents(); String conversion=rs.getCell.getContents(); String tname=rs.getCell.getContents(); String tformat=rs.getCell.getContents(); String tunit=rs.getCell.getContents(); String tfactory=rs.getCell.getContents(); String tprice=rs.getCell.getContents(); String tendGoodsId=rs.getCell.getContents(); String goodsId=rs.getCell.getContents(); String factoryId=(rs.getCell.getContents()==null||rs.getCell.getContents().equals?"0":rs.getCell.getContents(); GoodsEntity a = new GoodsEntity(); a.setName; a.setFormat; a.setUnit; a.setFactory; a.setPrice; a.setTend_goodsId(tendGoodsId); a.setGoodsId; a.setFactoryId(factoryId); a.setUuId(UUID.randomUUID().toString; a.setTfactory; a.setTformat; a.setTname; a.setTunit; a.setConversion(conversion); a.setTprice; list.add; } return list; }

文件user.xls格式为:

导入导出步骤

  1. 借助idea达成mybatis逆向工程
  2. 用xml配置达成整合
  3. 用cmd命令行达成mybatis逆向工程
  4. 用mapping.xml配置完结数量交互
  5. 用注脚的不二秘籍贯彻数据交互

那只是内部三个javabean的转变方法。所在类里面前段时间有十三个左右的转换方法,不过代码已经有484行。那一个项目才刚启航,到中期岂不是要几千行上万行?

图片 1

  无论是JeeSite系统,还是别的的系统恐怕本身写的系统,对于数据导入导出功用来讲,首先要明确的是导入导出哪些数据的字段,然后提供多少个导入的模板,编写导入导出的功力,最终在页面上提供导入导出的操作办法来供使用者实行利用。

首先本人的付出情状:jdk1.8+maven3+IDEA

第一说说笔者的主张,直接看伪代码比较清楚

 

 

1. mybatis逆向攻城

逆向工程措施比很多,作者当下接触到的就二种,一种是借助ide开荒工具,一种是在cmd中试行命令。(其实两侧原理都一样,都以实行maven的generator命令,具体请看下文)。

File file = new File; WorkBook wb = new Workbook; //excel文件转换文档对象Row row = wb.getSheet.getRow;//读取excel一行数据//其实到这里,一行数据就是一个JavaBeanint cols = row.getLastCellNum();//获取最后一列的列号Object[] arr = new Object[cols];//遍历这行的每一个单元格,然后把单元格取到的数据添加到数组arrfor(int i = 0 ;i<cols;i++){ Cell cell = row.getCell; arr[i] = cell.getCellValue();}//ok~到此为止我们把一行数据插入到了数组。那么接下来如何把数组填充到一个javabean呢?//我的想法:数组的下标与javabean属性对应起来。就可以利用反射将数组的元素一一设置到javabean。

下边来看代码实例演示:

概念导入导出字段

1. 完善pom文件
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>springboot-mybatis</groupId> <artifactId>springboot-mybatis</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-mybatis</name> <description>Demo project for Spring Boot</description> <parent> <groupId>springboot-integration</groupId> <artifactId>springboot-integration</artifactId> <version>1.0-SNAPSHOT</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.35</version> </dependency> <!-- alibaba的druid数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.11</version> </dependency> <!-- alibaba的druid数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.4</version> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <finalName>springboot-mybatis</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin> </plugins> </build></project>

看本人的代码,不BB

一、前端jsp页面(本来内容非常多,这里精简了)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>用户列表</title>
</head>
<body>
<form:form action="${path}/user/batchadduser.do" method="post" modelAttribute="iptvuser" cssClass="form-inline">
  <label class="control-label" for="excelFile">批量导入:</label> 
  <input name="excelFile" id="fileToUpload" type="file" />
  <input name="sbmt" id="sbmt" type="submit" />
</form>
  <br />  
 </body>
<script type="text/javascript">
$('#sbmt').click(function chcekfile()
{
    var file = $("#fileToUpload").val();
     $.ajaxFileUpload  
        (  
            {  
                url: '${path}/user/batchadduser.do',  
                secureuri: false,  
                fileElementId: 'fileToUpload',  
                dataType: 'json',   
                success: function(data, status) {
                    var result = data.result;
                    if(0 == result)
                    {
                        alert('*导入成功')
                    }else if(1 == result){
                        alert('*导入的用户账户包含不符合格式的数据,请先修正这些数据再导入。');
                    }else if(2 == result){
                        alert('*导入的用户账户包含已经存在的用户账户,请先删除这些数据再导入。');

                    }
                },  
                error: function(data, status, e) {

                }  
            }  
        )  
});
</script>
</html>

  在导入导出数据时会先分明要导入导出数据的怎么重大字段,在分明好字段之后,通过数据库查询出的数目依照字段各种的导出,只怕经过读取的Excel每一种的读入。在JeeSite中,明确要导入导出的字段现在,在JeeSite的实体类中得以经过表明来进展表达,注脚方法如下:

2. 逆向所需配置文件generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration> <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包--> <classPathEntry location="E:\lib\mysql_driver\mysql-connector-java-5.1.26-bin.jar"/> <context targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库链接URL,用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/user" userId="root" password="root"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.fantj.sbmybatis.model" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.fantj.sbmybatis.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context></generatorConfiguration>

ExcelCell.java 注解

/** * @ClassName: ExcelCell * @Description: 实体字段与excel列号关联的注解* @author albert* */@Documented@Inherited@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.FIELD)public @interface ExcelCell { int col(); Class<?> Type() default String.class;}

二、实体类及sql脚本

1 @ExcelField(title="列名1", align=2, sort=10)
3. 应用IDE创立逆向工程运行类

图片 2

Excel 文件

商品名 单位 规格 生产厂家
感冒灵颗粒 3片/盒 贵州百灵

excel文件总共有4列,那么序号0-3;

1、sql脚本为

CREATE TABLE `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_code` varchar(32) NOT NULL COMMENT '用户编号',
  `districtId` varchar(32) DEFAULT NULL COMMENT '地区',
  `businessId` varchar(32) DEFAULT NULL COMMENT '业务分组',
  `access_time` date DEFAULT NULL COMMENT '访问时间',
  `cancel_account_status` varchar(10) DEFAULT NULL COMMENT '状态',
  PRIMARY KEY (`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='用户表';

  那样定义,就足以将类中的字段与Excel的列举行关联,包罗列名称和排序。例子如下:

4. add一个Maven configuration

图片 3图片 4

Goods.java 实体类

此处要给实体类属性增多表明,以便与Excel 列号对应

public class Goods{ @ExcelCell private String name; //商品名 @ExcelCell private String unit; //单位 @ExcelCell private String format; //规格 @ExcelCell private String factory;//生产厂家}

/** * */package com.sy.utils;/** * @ClassName: ExcelConveter * @Description: * @author albert* @date 2017年5月5日 下午1:19:56 * */import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.lang.reflect.Field;import java.util.ArrayList;import java.util.List;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.CellType;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import com.sy.exceptions.MyException;public class ExcelConveter { public static Workbook readFile(File file) throws MyException { try { //xls和xlsx必须不同的处理类,POI就这么规定的 if (file.getName().toLowerCase().endsWith { return readFileHSSF(new FileInputStream; } else { return readFileXSSF(new FileInputStream; } } catch (Exception e) { e.printStackTrace(); throw new MyException(e.getMessage; } } //HSSF*是处理xls格式的,XSSF是处理xlsx格式文件 private static Workbook readFileHSSF(InputStream stream) throws MyException, IOException { try { return new HSSFWorkbook; } catch (IOException e) { e.printStackTrace(); throw new MyException(e.getMessage; } finally { stream.close(); } } private static Workbook readFileXSSF(InputStream stream) throws MyException, IOException { try { return new XSSFWorkbook; } catch (IOException e) { e.printStackTrace(); throw new MyException(e.getMessage; } finally { stream.close(); } } public static Workbook readFile(String path) throws MyException { File file = new File; if (!file.exists throw new MyException; if (!file.isFile throw new MyException("不是合法的文件"); return readFile; } public static Sheet readSheet(HSSFWorkbook workbook, Integer index) { return workbook.getSheetAt; } public static Object[] convertArrayByRow { int cols = row.getLastCellNum(); Object[] arr = new Object[cols]; for (int i = 0; i < cols; i++) { Cell cell = row.getCell; if (cell == null) continue; if (cell.getCellTypeEnum() == CellType.STRING) { arr[i] = cell.getStringCellValue(); } else if (cell.getCellTypeEnum() == CellType.NUMERIC) { arr[i] = cell.getNumericCellValue(); } else { } } return arr; } public static <T extends Object> T convertBeanFromArray(Object[] arr, Class<T> clazz) throws MyException { T entity; try { entity = clazz.newInstance(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!field.isAnnotationPresent(ExcelCell.class)) continue; field.setAccessible; ExcelCell anno = field.getAnnotation(ExcelCell.class); Class<?> cellType = anno.Type(); Integer col = anno.col(); if (col >= arr.length) continue; if (arr[col] == null) continue; if (cellType == null) { field.set(entity, arr[col]); } else { field.set(entity, numericByStr(cellType, arr[col])); } } return entity; } catch (Exception e) { e.printStackTrace(); throw new MyException(e.getMessage; } } public static <T extends Object> Object numericByStr(Class<T> clazz, Object param) { if (param == null) return null; String arg = String.valueOf; if (clazz.isAssignableFrom(Double.class)) { return Double.valueOf; } else if (clazz.isAssignableFrom(Long.class)) { Double d = Double.valueOf; return d.longValue(); } else if (clazz.isAssignableFrom(Integer.class)) { return Integer.valueOf; } else { return arg; } } public static <T> List<T> getBean(String path, Class<T> clazz) throws MyException { List<T> list = new ArrayList<T>(); Workbook book = readFile; for (int i = 1; i <= book.getSheetAt.getLastRowNum { Object[] arr = convertArrayByRow(book.getSheetAt.getRow; T t = convertBeanFromArray(arr, clazz); list.add; } return list; } public static <T> List<T> getBean(File file, Class<T> clazz) throws MyException { List<T> list = new ArrayList<T>(); Workbook book = readFile; for (int i = 1; i <= book.getSheetAt.getLastRowNum { Object[] arr = convertArrayByRow(book.getSheetAt.getRow; T t = convertBeanFromArray(arr, clazz); list.add; } return list; } public static <T> List<T> getBean(InputStream stream, String excelType, Class<T> clazz) throws MyException, IOException { Workbook book; if (excelType.equals { book = readFileHSSF; } else { book = readFileXSSF; } List<T> list = new ArrayList<T>(); for (int i = 1; i <= book.getSheetAt.getLastRowNum { Object[] arr = convertArrayByRow(book.getSheetAt.getRow; T t = convertBeanFromArray(arr, clazz); list.add; } return list; }}

List<Goods> list = ExcelConveter.getBean('excel文件路径', Barcode.class);

所需jar包在apache 官方网址就能够下载

2、实体类

package com.zealer.cps.base.model.entity.customer;

import java.util.Date;

import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat;

import com.zealer.cps.base.model.entity.BaseValue;

/**
 * 用户实体类

 */

public class UserValue 
{
    private static final long serialVersionUID = 1L;

    private Integer userId;

    private String userCode;

    private String districtId;

    private String businessId;

    //访问时间
    @DateTimeFormat( pattern = "yyyy-MM-dd HH:mm:ss" )
    private Date accessTime;

    //状态
    private String cancelAccountStatus;
//set与get以及toString方法省略,大家用eclipse可以自己生成
   ...
}

 

1 @ExcelField(title="名称", align=2, sort=10) 
2 public String getName() {
3     return name;
4 }
5 
6 @ExcelField(title="年龄", align=2, sort=20)  
7 public String getAge() {
8     return age;
9 }
5. 笔者的数据库和表结构

图片 5

三、控制类

package com.zealer.cps.customer.controller;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zealer.cps.base.annotation.Log;
import com.zealer.cps.base.annotation.MarkRequest;
import com.zealer.cps.base.constant.AppConstant;
import com.zealer.cps.base.constant.ParamConstants;
import com.zealer.cps.base.controller.BaseController;
import com.zealer.cps.base.message.ErrorActionResult;
import com.zealer.cps.base.message.SuccessActionResult;
import com.zealer.cps.base.model.entity.customer.UserTagValue;
import com.zealer.cps.base.model.entity.customer.UserValue;
import com.zealer.cps.base.model.entity.customer.LabelManagerValue;
import com.zealer.cps.base.util.AssertHelper;
import com.zealer.cps.base.util.ExcelUtils;
import com.zealer.cps.base.util.FileUploadUtil;
import com.zealer.cps.base.util.HttpRequestUtils;
import com.zealer.cps.base.util.HttpUtils;
import com.zealer.cps.base.util.JSONHelper;
import com.zealer.cps.customer.service.ArrearageUserService;
import com.zealer.cps.customer.service.IptvGroupService;
import com.zealer.cps.customer.service.UserService;
import com.zealer.cps.customer.service.LabelManagerService;
import com.zealer.cps.operation.impl.OperationInterfaceImp;

@Controller
@RequestMapping( "/user" )
public class UserController extends BaseController
{
    @Resource( name = "userService" )
    private UserService userService;


    /**
     * 往某一分组里批量添加用户记录信息
     * @param id 用户id
     * @return
     *
     */
    @ResponseBody
    @RequestMapping( value = "/batchadduser", produces = "application/json" )
    @Log( "批量添加用户信息" )
    public ResponseEntity<String> batchAddUser( @RequestParam ("excelFile") MultipartFile excelFile, Model model,
                         HttpServletRequest request, Locale locale )
    {
        Map<String, Object>  jsonMap = new HashMap<String, Object>();
        String dir = FileUploadUtil.getFileRealPath( request, excelFile.getName(), "Excel" );
        String ctxPath = FileUploadUtil.getTomcatPath( request );
        String localPath = HttpRequestUtils.getContextPath( request ) + "/";
        try
        {
            Map<String, Object> resutlMap = ExcelUtils.excelImportUser( ctxPath + dir, request );
            List<UserValue> errorList = (List<UserValue>)resutlMap.get( "error" );

            /* 如果Excel中存在不符合格式的数据则返回不符合格式的数据 */
            if ( AssertHelper.isNotEmptyCollection( errorList ) )
            {
                jsonMap.put( "result", 1 );
                String jsonStr = JSONHelper.toJson( jsonMap );
                return(new ResponseEntity<String> ( jsonStr, HttpStatus.OK ) );
            }

            List<UserValue> successList  = (List<UserValue>)resutlMap.get( "success" );
            Map<String, List<UserValue> >  map  = checkUserCodeIsExist( successList );

            /* 如果导入的用户账号中存在系统中没有的账号则进行插入操作 */
            List<UserValue> notExistList = map.get( "noExistList" );

            if ( AssertHelper.isNotEmptyCollection( notExistList ) )
            {
                userService.batchInsertUser( notExistList );
            }
        }
        catch ( Exception e )
        {
            log.error( "batchadd user to group error::", e );
            jsonMap.put( "result", -1 );
            String jsonStr = JSONHelper.toJson( jsonMap );
            return(new ResponseEntity<String> ( jsonStr, HttpStatus.BAD_REQUEST ) );
        }
        jsonMap.put( "result", 0 );
        String jsonStr = JSONHelper.toJson( jsonMap );
        return(new ResponseEntity<String> ( jsonStr, HttpStatus.OK ) );
    }

    /**
     * 校验导入的用户账号是否已经存在系统中了
     * @param list 待导入的用户账号
     * @return 存在则返回存在的用户账号list,不存在则返回空的list
     */
    private Map<String, List<UserValue>> checkUserCodeIsExist(List<UserValue> list)
    {
        Map<String, List<UserValue>> map = new HashMap<String, List<UserValue>>();
        List<String> allList = UserService.getAllUsersCode();
        List<UserValue> existList = new ArrayList<UserValue>();
        List<UserValue> noExistList = new ArrayList<UserValue>();
        for (UserValue UserValue : list)
        {
            if (allList.contains(UserValue.getUserCode())) 
            {
                existList.add(UserValue);
            }
            else
            {
                noExistList.add(UserValue);
            }
        }
        map.put("existList", existList);
        map.put("noExistList", noExistList);
        return map;
    }
}

  在实体类的getter方法上加多@ExcelField评释,就做到了Excel列名称与实体类字段的涉嫌。

6. application配置文件
server: port: 8080spring: datasource: name: test url: jdbc:mysql://127.0.0.1:3306/user username: root password: root # druid 连接池 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20mybatis: mapper-locations: classpath:mapping/*.xml type-aliases-package: com.fant.model#pagehelper分页插件pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql

运作generator工程 自动生成代码

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图