MyBatis-Plus 是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
无侵入:只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑
损耗小:启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作
强大的 CRUD 操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求
支持 Lambda 形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需再担心字段写错
支持主键自动生成:支持多达 4 种主键策略(内含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解决主键问题
支持 ActiveRecord 模式:支持 ActiveRecord 形式调用,实体类只需继承 Model 类即可进行强大的 CRUD 操作
支持自定义全局通用操作:支持全局通用方法注入( Write once, use anywhere )
内置代码生成器:采用代码或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 层代码,支持模板引擎,更有超多自定义配置等您来使用
内置分页插件:基于 MyBatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通 List 查询
分页插件支持多种数据库:支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多种数据库
内置性能分析插件:可输出 SQL 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询
内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作
编写导出工具类中的通用导出方法时,用easyPoi导出的excel打开会出现一条绿线,一开始以为是默认style类导致的问题,后来发现是默认会窗口冻结第一行,在excel的视图里可以取消窗口冻结,但是我们要在导出的时候就去除掉
获取sheet对象,编辑createFreezePane方法,去除窗口冻结也可以加上
java
/**
* 这个是通用的easyPoi有对象导出方式
* @param response HttpServletResponse
* @param type 导出excel后缀类型
* @param fileName 导出文件名
* @param clazz 列表中的类型对象
* @param list 导出列表
* @throws Exception
*/
public static <T> void easyPoiObjectToExcel(HttpServletResponse response, String type, Class<T> clazz, String fileName, List<T> list) throws IOException {
if (type.equals("csv")) {
response.setContentType("text/csv");
} else if (type.equals("dbf")) {
response.setContentType("application/x-dbf");
} else if (type.equals("xls")) {
response.setContentType("application/vnd.ms-excel");
} else {
//默认xlsx
type = "xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + "." + type, "utf-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
try {
ExportParams exportParams = new ExportParams(fileName, "Sheel1");
exportParams.setStyle(ExcelStylesUtil.class);
// 生成workbook 并导出
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, clazz, list);
//获取sheet对象
Sheet sheet = workbook.getSheetAt(0);
//去除窗口冻结
sheet.createFreezePane(0,0);
workbook.write(response.getOutputStream());
workbook.close();
} catch (IOException e) {
e.printStackTrace();
outputErrorJson(response, e.getMessage());
}
}
使用easyexcel导出的时候,发现一直提示这个异常
javaorg.apache.poi.ss.usermodel.Cell.setCellValue(Ljava/time/LocalDateTime;)V
但是我在实体类里并没有对时间属性使用easyexcel的导出注解
1.使用@ExcelIgnore注解注释时间类型,这样导致的问题就是不能直接导出时间类型,如果还想导出时间就要加个字段转成字符串类型导出,比较麻烦
2.自定义转换类,实现对时间类型的转换
javaimport com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;
import java.util.Date;
/**
* 解决 EasyExcel 日期类型 Date 转换的问题
*/
public class DateConverter implements Converter<Date> {
private static final String formatDate = "yyyy-MM-dd HH:mm:ss";
@Override
public Class<?> supportJavaTypeKey() {
return Converter.super.supportJavaTypeKey();
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return Converter.super.supportExcelTypeKey();
}
@Override
public WriteCellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return new WriteCellData<>(DateUtils.format(value,formatDate));
}
}
SQLMERGE INTO rec_search_solution_field e1
USING (SELECT field_id, order_no
FROM rec_search_solution_field
WHERE solution_id =
'2023062616531652c6e468'
AND order_no IS NOT NULL) e2
ON (e1.field_id = e2.field_id)
WHEN MATCHED THEN
UPDATE
SET e1.order_no = e2.order_no
WHERE e1.solution_id in
('2023071916160381771c2e',
'20230724150725f378cd5f')
update子项的时候,使用in的方式会导致,只有一个子项会更新,其他子项还是原来的,因为 如果rec_search_solution_field表中有多个具有相同field_id的记录,那么这个MERGE语句将只更新第一个匹配的记录。如果需要更新所有匹配的记录,可以考虑使用其他方法,如循环或游标。