|
@@ -15,26 +15,15 @@
|
|
*/
|
|
*/
|
|
package com.baomidou.mybatisplus.generator;
|
|
package com.baomidou.mybatisplus.generator;
|
|
|
|
|
|
-import java.io.BufferedWriter;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.OutputStreamWriter;
|
|
|
|
-import java.sql.Connection;
|
|
|
|
-import java.sql.DriverManager;
|
|
|
|
-import java.sql.PreparedStatement;
|
|
|
|
-import java.sql.ResultSet;
|
|
|
|
-import java.sql.SQLException;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
import com.baomidou.mybatisplus.annotations.IdType;
|
|
import com.baomidou.mybatisplus.annotations.IdType;
|
|
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
|
|
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
|
|
|
|
+import com.baomidou.mybatisplus.toolkit.DBKeywordsProcessor;
|
|
import com.baomidou.mybatisplus.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.toolkit.StringUtils;
|
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.sql.*;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 映射文件自动生成类
|
|
* 映射文件自动生成类
|
|
@@ -233,6 +222,7 @@ public class AutoGenerator {
|
|
}
|
|
}
|
|
String beanName = getBeanName(table, config.isDbPrefix());
|
|
String beanName = getBeanName(table, config.isDbPrefix());
|
|
String mapperName = String.format(config.getMapperName(), beanName);
|
|
String mapperName = String.format(config.getMapperName(), beanName);
|
|
|
|
+ String mapperXMLName = String.format(config.getMapperXMLName(), beanName);
|
|
String serviceName = String.format(config.getServiceName(), beanName);
|
|
String serviceName = String.format(config.getServiceName(), beanName);
|
|
String serviceImplName = String.format(config.getServiceImplName(), beanName);
|
|
String serviceImplName = String.format(config.getServiceImplName(), beanName);
|
|
|
|
|
|
@@ -245,8 +235,8 @@ public class AutoGenerator {
|
|
if (valideFile(PATH_MAPPER, mapperName, JAVA_SUFFIX)) {
|
|
if (valideFile(PATH_MAPPER, mapperName, JAVA_SUFFIX)) {
|
|
buildMapper(beanName, mapperName);
|
|
buildMapper(beanName, mapperName);
|
|
}
|
|
}
|
|
- if (valideFile(PATH_XML, mapperName, XML_SUFFIX)) {
|
|
|
|
- buildMapperXml(columns, types, comments, idMap, mapperName);
|
|
|
|
|
|
+ if (valideFile(PATH_XML, mapperXMLName, XML_SUFFIX)) {
|
|
|
|
+ buildMapperXml(columns, types, comments, idMap, mapperName, mapperXMLName);
|
|
}
|
|
}
|
|
if (valideFile(PATH_SERVICE, serviceName, JAVA_SUFFIX)) {
|
|
if (valideFile(PATH_SERVICE, serviceName, JAVA_SUFFIX)) {
|
|
buildService(beanName, serviceName);
|
|
buildService(beanName, serviceName);
|
|
@@ -690,8 +680,8 @@ public class AutoGenerator {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
protected void buildMapperXml(List<String> columns, List<String> types, List<String> comments,
|
|
protected void buildMapperXml(List<String> columns, List<String> types, List<String> comments,
|
|
- Map<String, IdInfo> idMap, String mapperName) throws IOException {
|
|
|
|
- File mapperXmlFile = new File(PATH_XML, mapperName + ".xml");
|
|
|
|
|
|
+ Map<String, IdInfo> idMap, String mapperName,String mapperXMLName) throws IOException {
|
|
|
|
+ File mapperXmlFile = new File(PATH_XML, mapperXMLName + ".xml");
|
|
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile)));
|
|
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile)));
|
|
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
bw.newLine();
|
|
bw.newLine();
|
|
@@ -810,12 +800,12 @@ public class AutoGenerator {
|
|
String column = columns.get(i);
|
|
String column = columns.get(i);
|
|
IdInfo idInfo = idMap.get(column);
|
|
IdInfo idInfo = idMap.get(column);
|
|
if (idInfo != null) {
|
|
if (idInfo != null) {
|
|
- bw.write("\t\t " + idInfo.getValue());
|
|
|
|
|
|
+ bw.write("\t\t " + DBKeywordsProcessor.convert(idInfo.getValue()));
|
|
if (idInfo.getValue().contains("_")) {
|
|
if (idInfo.getValue().contains("_")) {
|
|
bw.write(" AS " + processField(idInfo.getValue()));
|
|
bw.write(" AS " + processField(idInfo.getValue()));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- bw.write(" " + column);
|
|
|
|
|
|
+ bw.write(" " + DBKeywordsProcessor.convert(column));
|
|
if (column.contains("_")) {
|
|
if (column.contains("_")) {
|
|
bw.write(" AS " + processField(column));
|
|
bw.write(" AS " + processField(column));
|
|
}
|
|
}
|