From 2e506b1394bfd2d27a6c4283658ba55b96e826d2 Mon Sep 17 00:00:00 2001 From: ZhiQiang Date: Fri, 6 Nov 2020 16:55:12 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=80=9A=E7=94=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=A8=A1=E6=9D=BF=EF=BC=8C=E5=B8=A6swagger?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/controller/IndexController.java | 51 ++ .../system/generator/util/FileUtils.java | 564 ++++++++++++++++++ .../src/main/resources/template.json | 114 +--- .../beetlsql/beetlcontroller.ftl | 9 +- .../code-generator/beetlsql/beetlentity.ftl | 13 +- .../code-generator/jdbc-template/jtdao.ftl | 9 +- .../jdbc-template/jtdaoimpl.ftl | 9 +- .../templates/code-generator/jpa/entity.ftl | 9 +- .../code-generator/jpa/jpacontroller.ftl | 9 +- .../code-generator/jpa/repository.ftl | 9 +- ...ntroller.ftl => mybatisPlusController.ftl} | 37 +- .../{plusentity.ftl => mybatisPlusEntity.ftl} | 9 +- .../{plusmapper.ftl => mybatisPlusMapper.ftl} | 11 +- .../mybatis/annotationMapper.ftl | 57 ++ .../code-generator/mybatis/controller.ftl | 47 +- .../templates/code-generator/mybatis/dto.ftl | 31 + .../code-generator/mybatis/mapper.ftl | 11 +- .../code-generator/mybatis/mapper2.ftl | 56 -- .../code-generator/mybatis/model.ftl | 39 -- .../{mybatis.ftl => mybatisMapper.ftl} | 2 +- .../code-generator/mybatis/service.ftl | 11 +- .../{service_impl.ftl => service.impl.ftl} | 25 +- .../templates/code-generator/mybatis/vo.ftl | 33 + .../code-generator/util/beanutil.ftl | 6 +- .../src/main/resources/templates/index.ftl | 162 ++--- pom.xml | 14 + 26 files changed, 981 insertions(+), 366 deletions(-) create mode 100644 generator-web/src/main/java/com/softdev/system/generator/util/FileUtils.java rename generator-web/src/main/resources/templates/code-generator/mybatis-plus/{pluscontroller.ftl => mybatisPlusController.ftl} (71%) rename generator-web/src/main/resources/templates/code-generator/mybatis-plus/{plusentity.ftl => mybatisPlusEntity.ftl} (87%) rename generator-web/src/main/resources/templates/code-generator/mybatis-plus/{plusmapper.ftl => mybatisPlusMapper.ftl} (85%) create mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/annotationMapper.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/dto.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl rename generator-web/src/main/resources/templates/code-generator/mybatis/{mybatis.ftl => mybatisMapper.ftl} (95%) rename generator-web/src/main/resources/templates/code-generator/mybatis/{service_impl.ftl => service.impl.ftl} (59%) create mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/vo.ftl diff --git a/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java b/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java index 43e831af..94eb4a59 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java +++ b/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java @@ -4,6 +4,7 @@ import com.softdev.system.generator.entity.ParamInfo; import com.softdev.system.generator.entity.ReturnT; import com.softdev.system.generator.service.GeneratorService; +import com.softdev.system.generator.util.FileUtils; import com.softdev.system.generator.util.TableParseUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -77,6 +78,56 @@ public ReturnT codeGenerate(@RequestBody ParamInfo paramInfo) throws Exception { //3.generate the code by freemarker template and param . Freemarker根据参数和模板生成代码 Map result = generatorService.getResultByParams(params); + + for(Map.Entry entry : result.entrySet()){ + String mapKey = entry.getKey(); + String mapValue = entry.getValue(); + if ("tableName".equals(mapKey)) { + continue; + } + System.out.println(mapKey+":\n"+mapValue); + String fileName = paramInfo.getPackageName().replace(".","/") +"/"; + + String javaFile = ""; + + switch (mapKey) { + + case "json" : + fileName += mapKey+".json"; + break; + case "sql" : + fileName += mapKey+".sql"; + break; + case "xml" : + fileName += mapKey+".xml"; + break; + case "mybatisMapper": + String[] strings2 = mapValue.split(">"); + for (String ss :strings2) { + if (ss.startsWith("\r\n
    >>> "+fileName); + FileUtils.writeStringToFile(fileName,mapValue,"utf-8",false); + + } + return ReturnT.SUCCESS(result); } diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/FileUtils.java b/generator-web/src/main/java/com/softdev/system/generator/util/FileUtils.java new file mode 100644 index 00000000..a18831d6 --- /dev/null +++ b/generator-web/src/main/java/com/softdev/system/generator/util/FileUtils.java @@ -0,0 +1,564 @@ +package com.softdev.system.generator.util; + +import org.apache.commons.io.filefilter.FileFilterUtils; + +import java.io.*; +import java.math.BigInteger; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +/** + * org.apache.commons.io.FileUtils工具类各方法使用详解,二次封装 + */ +public class FileUtils { + + /** + * 将url内容复制到文件 + * + * @param source url + * @param destination 文件目录 + * @param connectionTimeout 连接超时,单位毫秒 + * @param readTimeout 读取超时,单位毫秒 + * @throws IOException + */ + public static void copyURLToFile(String source, String destination, int connectionTimeout, int readTimeout) throws IOException { + org.apache.commons.io.FileUtils.copyURLToFile(new URL(source), new File(destination), connectionTimeout, readTimeout); + } + + /** + * 将文件A的内容复制到文件B + * + * @param fromPath + * @param toPath + * @throws IOException + */ + public static void copyToFile(String fromPath, String toPath) throws IOException { + InputStream inputStream; + File file = new File(toPath); + inputStream = new FileInputStream(fromPath);//用字节流的方式cope文件 + org.apache.commons.io.FileUtils.copyToFile(inputStream, file); + } + + /** + * 将文件A的复制到文件B + * + * @param fromPath + * @param toPath + * @param preserveFileDate 是否保留日期,true保留日期,false不保留日期 + * @throws IOException + */ + public static void copyFile(String fromPath, String toPath, boolean preserveFileDate) throws IOException { + org.apache.commons.io.FileUtils.copyFile(new File(fromPath), new File(toPath), preserveFileDate); + } + + /** + * 将文件复制到其他文件夹中 + * + * @param sourceFile + * @param destinationDir + * @param preserveFileDate 是否保留日期,true保留日期,false不保留日期 + * @throws IOException + */ + public static void copyFileToDirectory(String sourceFile, String destinationDir, boolean preserveFileDate) throws IOException { + org.apache.commons.io.FileUtils.copyFileToDirectory(new File(sourceFile), new File(destinationDir), preserveFileDate); + } + + /** + * 复制文件夹 + * + * @param srcDir 源文件夹 + * @param destDir 目标文件夹 + * @param preserveFileDate 是否保留日期,true保留日期,false不保留日期 + */ + public static void copyDirectory(String srcDir, String destDir, boolean preserveFileDate) throws IOException { + org.apache.commons.io.FileUtils.copyDirectory(new File(srcDir), new File(destDir), preserveFileDate); + } + + /** + * 在给定目录(及其子目录)中查找与扩展名数组匹配的文件 + * + * @param folderPath 文件夹路径 + * @param suffix 要查找的文件后缀名 + * @param b 是否查找子目录 + * @return 符合条件的文件路径 + */ + public static File[] listFiles_fileSuffix(String folderPath, String[] suffix, boolean b) { + File file = new File(folderPath); + return org.apache.commons.io.FileUtils.convertFileCollectionToFileArray(org.apache.commons.io.FileUtils.listFiles(file, suffix, b)); + } + + /** + * 在给定目录(及其子目录)中查找文件 + * + * @param folderPath 文件夹路径 + * @param fileName 要查找的文件名 + * @param subfolderName 如果需要在子目录查找,输入子目录的文件夹名,不需要的话传入null + * @return 符合条件的文件路径 + */ + public static File[] listFiles_fileName(String folderPath, String fileName, String subfolderName) { + File file = new File(folderPath); + if (subfolderName == null) { + return org.apache.commons.io.FileUtils.convertFileCollectionToFileArray(org.apache.commons.io.FileUtils.listFiles(file, FileFilterUtils.nameFileFilter(fileName), null)); + } + return org.apache.commons.io.FileUtils.convertFileCollectionToFileArray(org.apache.commons.io.FileUtils.listFiles(file, FileFilterUtils.nameFileFilter(fileName), FileFilterUtils.nameFileFilter(subfolderName))); + + } + + /** + * 删除目录下的所有文件及文件夹,不删除目录本身 + * + * @param folderPath 文件夹路径 + * @throws IOException 抛出io流异常 + */ + public static void cleanDirectory(String folderPath) throws IOException { + File f = new File(folderPath); + if (f.exists()) { + org.apache.commons.io.FileUtils.cleanDirectory(f); + } else { + System.out.println("目录不存在:" + folderPath); + } + } + + /** + * 删除目录本身,以及里面的所有内容:递归删除 + * + * @param folderPath + * @throws IOException + */ + public static void deleteDirectory(String folderPath) throws IOException { + File f = new File(folderPath); + if (f.exists()) { + org.apache.commons.io.FileUtils.deleteDirectory(f); + } else { + System.out.println("目录不存在:" + folderPath); + } + } + + /** + * 删除文件,会抛出异常 + * + * @param filePath + * @throws IOException + */ + public static void forceDelete(String filePath) throws IOException { + File f = new File(filePath); + if (f.exists()) { + org.apache.commons.io.FileUtils.forceDelete(f); + } else { + System.out.println("文件不存在:" + filePath); + } + } + + + /** + * 删除文件,不会抛出异常 + * + * @param filePath + * @throws IOException + */ + public static void deleteFile(String filePath) { + File file = new File(filePath); + if (file.exists()) { + org.apache.commons.io.FileUtils.deleteQuietly(file); + } else { + System.out.println("文件不存在:" + filePath); + } + } + + /** + * 确定child元素是否存在于directory目录中,child可以是文件或文件夹 + * + * @param directory + * @param child + * @return + * @throws IOException + */ + public static boolean directoryContains(String directory, String child) throws IOException { + return org.apache.commons.io.FileUtils.directoryContains(new File(directory), new File(child)); + } + + /** + * 创建文件夹,如果他的父目录不存也会创建 + * + * @param directory 文件夹路径 + * @throws IOException + */ + public static void forceMkdir(String directory) throws IOException { + org.apache.commons.io.FileUtils.forceMkdir(new File(directory)); + } + + /** + * 给文件创建父级目录 + * + * @param directory 文件路径 + * @throws IOException + */ + public static void forceMkdirParent(String directory) throws IOException { + org.apache.commons.io.FileUtils.forceMkdirParent(new File(directory)); + } + + /** + * 返回用户主目录 + * + * @return + */ + public static File getUserDirectory() { + return org.apache.commons.io.FileUtils.getUserDirectory(); + } + + /** + * 比较文件filePath的修改时间(不是创建时间)是否比object指定的时间早 + * + * @param filePath + * @param object 3种类型 Date File Long + * @return + */ + public static boolean isFileNewer(String filePath, Object object) { + if (object.getClass().equals(Date.class)) { + return org.apache.commons.io.FileUtils.isFileNewer(new File(filePath), (Date) object); + } else if (object.getClass().equals(File.class)) { + return org.apache.commons.io.FileUtils.isFileNewer(new File(filePath), (File) object); + } else if (object.getClass().equals(Long.class)) { + return org.apache.commons.io.FileUtils.isFileNewer(new File(filePath), (Long) object); + } else { + System.out.println(object.getClass().getName() + "对象类型不符合要求" + object.toString()); + } + return false; + } + + /** + * 比较文件filePath的修改时间(不是创建时间)是否比object指定的时间晚 + * + * @param filePath + * @param object 3种类型 Date File Long + * @return + */ + public static boolean isFileOlder(String filePath, Object object) { + if (object.getClass().equals(Date.class)) { + return org.apache.commons.io.FileUtils.isFileOlder(new File(filePath), (Date) object); + } else if (object.getClass().equals(File.class)) { + return org.apache.commons.io.FileUtils.isFileOlder(new File(filePath), (File) object); + } else if (object.getClass().equals(Long.class)) { + return org.apache.commons.io.FileUtils.isFileOlder(new File(filePath), (Long) object); + } else { + System.out.println(object.getClass().getName() + "对象类型不符合要求" + object.toString()); + } + return false; + } + + /** + * 比较两个文件的内容是否相同 + * + * @param path1 文件A路径 + * @param path2 文件B路径 + * @param boo 是否忽略换行符 + * @return 返回布尔值 + * @throws IOException + */ + public static boolean contentEquals(String path1, String path2, boolean boo) throws IOException { + File file1 = new File(path1); + File file2 = new File(path2); + if (file1.exists() && file2.exists()) { + if (boo) {//忽略换行符 + return org.apache.commons.io.FileUtils.contentEqualsIgnoreEOL(file1, file2, "utf-8"); + } else {//不忽略换行符 + return org.apache.commons.io.FileUtils.contentEquals(file1, file2); + } + } else { + System.out.println("有文件不存在:" + path1 + path2); + return false; + } + } + + /** + * 确定指定的文件是链接而不是实际文件 + * + * @param file + * @return + */ + public static boolean isSymlink(String file) throws IOException { + return org.apache.commons.io.FileUtils.isSymlink(new File(file)); + } + + /** + * 移动目录 新目录可以重命名,且必须是不存在的目录 + * + * @param src + * @param destDir + * @throws IOException + */ + public static void moveDirectory(String src, String destDir) throws IOException { + org.apache.commons.io.FileUtils.moveDirectory(new File(src), new File(destDir)); + } + + /** + * 将目录移动到另一个父目录下,另一个父目录必须存在 + * + * @param src + * @param destDir + * @param createDestDir + * @throws IOException + */ + public static void moveDirectoryToDirectory(String src, String destDir, boolean createDestDir) throws IOException { + org.apache.commons.io.FileUtils.moveDirectoryToDirectory(new File(src), new File(destDir), createDestDir); + } + + /** + * 移动文件 + * + * @param src 源文件,不存在会报错 + * @param destDir 目标文件,可以重命名 + * @throws IOException + */ + public static void moveFile(String src, String destDir) throws IOException { + org.apache.commons.io.FileUtils.moveFile(new File(src), new File(destDir)); + } + + /** + * 移动文件到目录 + * + * @param src 源文件,不存在会报错 + * @param destDir 目标文件夹,不存在会自动创建 + * @param createDestDir 保留日期 + * @throws IOException + */ + public static void moveFileToDirectory(String src, String destDir, boolean createDestDir) throws IOException { + org.apache.commons.io.FileUtils.moveFileToDirectory(new File(src), new File(destDir), createDestDir); + } + + /** + * 将文件或文件夹移动到目标目录 + * + * @param src 文件、文件夹,不存在会报错 + * @param destDir 目标文件夹,不存在会自动创建 + * @param createDestDir 保留日期 + * @throws IOException + */ + public static void moveToDirectory(String src, String destDir, boolean createDestDir) throws IOException { + org.apache.commons.io.FileUtils.moveToDirectory(new File(src), new File(destDir), createDestDir); + } + + /** + * 读取文件,返回字符串,继承自InputStream + * + * @param path + * @param charsetName + * @return + * @throws IOException + */ + public static String readFileToString(String path, Charset charsetName) throws IOException { + return org.apache.commons.io.FileUtils.readFileToString(new File(path), charsetName); + } + + /** + * 按行读取文件,返回一个list数组 + * + * @param path + * @param charset + * @return + * @throws IOException + */ + public static List readLines(String path, Charset charset) throws IOException { + return org.apache.commons.io.FileUtils.readLines(new File(path), charset); + } + + /** + * 返回指定文件或目录的大小(字节数) + * + * @param file + * @return 返回BigInteger类型数值,超出64位时使用 + */ + public static BigInteger sizeOfAsBigInteger(String file) { + return org.apache.commons.io.FileUtils.sizeOfAsBigInteger(new File(file)); + } + + /** + * 返回指定文件或目录的大小(字节数) + * + * @param file + * @return 返回long类型数值,未超出64位时使用 + */ + public static long sizeOf(String file) { + return org.apache.commons.io.FileUtils.sizeOf(new File(file)); + } + + /** + * 返回目录的大小(字节数) + * + * @param directory + * @return + */ + public static BigInteger sizeOfDirectoryAsBigInteger(String directory) { + return org.apache.commons.io.FileUtils.sizeOfDirectoryAsBigInteger(new File(directory)); + } + + /** + * 返回目录的大小(字节数) + * + * @param directory + * @return + */ + public static long sizeOfDirectory(String directory) { + return org.apache.commons.io.FileUtils.sizeOfDirectory(new File(directory)); + } + + /** + * 根据URL获取文件 + * 获取文件后,可以使用readFileToString方法读取文件内容 + * + * @param url 比如:file:/Users/Shared/666/selenium + * @return + * @throws MalformedURLException + */ + public static File toFile(URL url) throws MalformedURLException { + return org.apache.commons.io.FileUtils.toFile(url); + } + + /** + * 根据URL获取文件 + * + * @param url 可以传入多个new URL("file:/Users/Shared/666/selenium/api.txt")参数 + * @return 返回文件数组 + * @throws MalformedURLException + */ + public static File[] toFiles(URL... url) { + return org.apache.commons.io.FileUtils.toFiles(url); + } + + + /** + * 修改文件、文件夹的修改时间(不是创建时间) + * 文件不存在则新建 + * 文件夹不存在则新建父级目录 + * + * @param file + * @throws IOException + */ + public static void touch(String file) throws IOException { + org.apache.commons.io.FileUtils.touch(new File(file)); + } + + /** + * File转换为URL + * 可以传入多个new File() + * + * @param file + * @return + * @throws IOException + */ + public static URL[] toURLs(File... file) throws IOException { + return org.apache.commons.io.FileUtils.toURLs(file); + } + + /** + * 等待确定目标文件、文件夹是否创建 + * 在seconds秒内创建完成返回true + * + * @param file 文件、文件夹 + * @param seconds 秒 + * @return + * @throws IOException + */ + public static boolean waitFor(String file, int seconds) throws IOException { + return org.apache.commons.io.FileUtils.waitFor(new File(file), seconds); + } + + /** + * 字符流写入文件,写字符串文本,用字符流 + * 继承自Writer,将FileOutputStream字符流转换为字节流写入文件 + * FileOutputStream参数true为追加写 + * 字节流写入中文不会有乱码 + * Charset传入编码格式StandardCharsets.UTF_8 + */ + public static void writeStringToFile_io(String file, String data, String charset, boolean append) throws IOException { + OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(new File(file), append), charset); + os.write(data); + os.close(); + } + + /** + * 字符串写入文件,优先使用此方法 + * + * @param file + * @param data + * @param charset + * @param append + * @throws IOException + */ + public static void writeStringToFile(String file, String data, String charset, boolean append) throws IOException { + org.apache.commons.io.FileUtils.writeStringToFile(new File(file), data, charset, append); + } + + /** + * 字符串写入文件 + * 可以接收CharSequence类型的数据 + * + * @param file 文件不存在自动创建 + * @param data + * @param charsetName + * @param append 是否追加写入 + * @throws IOException + */ + public static void write(String file, CharSequence data, String charsetName, boolean append) throws IOException { + org.apache.commons.io.FileUtils.write(new File(file), data, charsetName, append); + } + + /** + * 字符数组写入文件 + * + * @param file + * @param data 字符数组 + * @param append 是否追加 + * @throws IOException + */ + public static void writeByteArrayToFile(String file, byte[] data, boolean append) throws IOException { + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(file), data, append); + } + + /** + * 字符数组写入文件 + * + * @param file + * @param data 字符数组 + * @param off 起始位置 + * @param len 结束位置 + * @param append 是否追加 + * @throws IOException + */ + public static void writeByteArrayToFile(String file, byte[] data, int off, int len, boolean append) throws IOException { + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(file), data, off, len, append); + } + + /** + * 将集合中的值逐行写入文件,自动换行 + * + * @param file + * @param lines 集合类型,如:List、Set 和 Queue + * @param append 是否追加 + * @throws IOException + */ + public static void writeLines(String file, String charsetName, Collection lines, boolean append) throws IOException { + org.apache.commons.io.FileUtils.writeLines(new File(file), charsetName, lines, append); + } + + /** + * 将集合中的值写入文件,不自动换行 + * + * @param file + * @param charsetName + * @param lines + * @param lineEnding 每行结尾可以自定义,如"\n"或"字符串" + * @param append 是否追加 + * @throws IOException + */ + public static void writeLines(String file, String charsetName, Collection lines, String lineEnding, boolean append) throws IOException { + org.apache.commons.io.FileUtils.writeLines(new File(file), charsetName, lines, lineEnding, append); + } + +} + + diff --git a/generator-web/src/main/resources/template.json b/generator-web/src/main/resources/template.json index ca98f76d..9ce4d709 100644 --- a/generator-web/src/main/resources/template.json +++ b/generator-web/src/main/resources/template.json @@ -1,34 +1,4 @@ [ - { - "id": "10", - "name": "swagger-ui", - "group": "ui", - "description": "swagger-ui" - }, - { - "id": "11", - "name": "element-ui", - "group": "ui", - "description": "element-ui" - }, - { - "id": "12", - "name": "bootstrap-ui", - "group": "ui", - "description": "bootstrap-ui" - }, - { - "id": "13", - "name": "layui-edit", - "group": "ui", - "description": "layui-edit" - }, - { - "id": "14", - "name": "layui-list", - "group": "ui", - "description": "layui-list" - }, { "id": "20", "name": "controller", @@ -43,9 +13,9 @@ }, { "id": "22", - "name": "service_impl", + "name": "service.impl", "group": "mybatis", - "description": "service_impl" + "description": "service impl" }, { "id": "23", @@ -55,93 +25,45 @@ }, { "id": "24", - "name": "mybatis", + "name": "mybatisMapper", "group": "mybatis", - "description": "mybatis" + "description": "mybatisMapper" }, { "id": "25", - "name": "model", + "name": "vo", "group": "mybatis", - "description": "model" + "description": "vo" }, { "id": "26", - "name": "mapper2", + "name": "dto", "group": "mybatis", - "description": "mapper annotation" - }, - { - "id": "30", - "name": "entity", - "group": "jpa", - "description": "entity" - }, - { - "id": "31", - "name": "repository", - "group": "jpa", - "description": "repository" + "description": "dto" }, { - "id": "32", - "name": "jpacontroller", - "group": "jpa", - "description": "jpacontroller" - }, - { - "id": "40", - "name": "jtdao", - "group": "jdbc-template", - "description": "jtdao" - }, - { - "id": "41", - "name": "jtdaoimpl", - "group": "jdbc-template", - "description": "jtdaoimpl" - }, - { - "id": "50", - "name": "beetlmd", - "group": "beetlsql", - "description": "beetlmd" - }, - { - "id": "51", - "name": "beetlentity", - "group": "beetlsql", - "description": "beetlentity" - }, - { - "id": "52", - "name": "beetlcontroller", - "group": "beetlsql", - "description": "beetlcontroller" + "id": "27", + "name": "annotationMapper", + "group": "mybatis", + "description": "annotationMapper" }, { "id": "60", - "name": "pluscontroller", + "name": "mybatisPlusController", "group": "mybatis-plus", - "description": "pluscontroller" + "description": "mybatisPlusController" }, { "id": "61", - "name": "plusmapper", + "name": "mybatisPlusMapper", "group": "mybatis-plus", - "description": "plusmapper" + "description": "mybatisPlusMapper" }, { "id": "62", - "name": "plusentity", + "name": "mybatisPlusEntity", "group": "mybatis-plus", - "description": "plusentity" - }, - { - "id": "70", - "name": "beanutil", - "group": "util", - "description": "beanutil" + "description": "mybatisPlusEntity" }, { "id": "71", diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl index ab7cdb6d..2ce7ee13 100644 --- a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl @@ -7,10 +7,11 @@ import java.util.List; import java.util.Map; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl index 77e2dc33..5d743369 100644 --- a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl @@ -4,13 +4,14 @@ import java.util.Date; import java.util.List; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Data<#if swagger?exists && swagger==true> @ApiModel("${classInfo.classComment}") -public class ${classInfo.className} implements Serializable { +public class ${classInfo.className}Dto implements Serializable { private static final long serialVersionUID = 1L; @@ -23,7 +24,7 @@ public class ${classInfo.className} implements Serializable { private ${fieldItem.fieldClass} ${fieldItem.fieldName}; - public ${classInfo.className}() { + public ${classInfo.className}Dto() { } diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl index ba927311..00dc8a25 100644 --- a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl @@ -2,10 +2,11 @@ import java.util.List; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ public interface I${classInfo.className}DAO { int add(${classInfo.className} ${classInfo.className?uncap_first}); diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl index 4e0da92a..1e992481 100644 --- a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl @@ -6,10 +6,11 @@ import org.springframework.stereotype.Repository; import java.util.List; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Repository public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{ diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl index ac86bab8..75c53282 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl @@ -13,10 +13,11 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Entity @Data @Table(name="${classInfo.tableName}")<#if swagger?exists && swagger==true> diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl index 6371e179..8e8b8338 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl @@ -15,10 +15,11 @@ import java.util.List; import java.util.Map; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl index 7573fad5..fa421656 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl @@ -14,10 +14,11 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Repository public interface ${classInfo.className}Repository extends JpaRepository<${classinfo.classname},integer> { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusController.ftl similarity index 71% rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl rename to generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusController.ftl index a9b13383..c6a1c0df 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusController.ftl @@ -18,9 +18,10 @@ import java.util.List; import java.util.Map; /** -* @description ${classInfo.classComment} * @author ${authorName} +* @Version 1.0.0 * @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} */ @Slf4j @RestController @@ -28,7 +29,7 @@ import java.util.Map; public class ${classInfo.className}Controller { @Autowired - private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper; + private I${classInfo.className}Mapper i${classInfo.className?uncap_first}Mapper; /** * 新增或编辑 @@ -36,12 +37,12 @@ public class ${classInfo.className}Controller { @PostMapping("/save") public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){ log.info("${classInfo.className?uncap_first}:"+JSON.toJSONString(${classInfo.className?uncap_first})); - ${classInfo.className} old${classInfo.className} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",${classInfo.className?uncap_first}.get${classInfo.className}Id())); + ${classInfo.className} old${classInfo.className} = i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",${classInfo.className?uncap_first}.get${classInfo.className}Id())); ${classInfo.className?uncap_first}.setUpdateTime(new Date()); if(old${classInfo.className}!=null){ - ${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); + i${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); }else{ - if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){ + if(i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){ return ${returnUtil}.ERROR("保存失败,名字重复"); } ${classInfo.className?uncap_first}.setCreateTime(new Date()); @@ -55,9 +56,9 @@ public class ${classInfo.className}Controller { */ @PostMapping("/delete") public Object delete(int id){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); + ${classInfo.className} ${classInfo.className?uncap_first} = i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); if(${classInfo.className?uncap_first}!=null){ - ${classInfo.className?uncap_first}Mapper.deleteById(id); + i${classInfo.className?uncap_first}Mapper.deleteById(id); return ${returnUtil}.SUCCESS("删除成功"); }else{ return ${returnUtil}.ERROR("没有找到该对象"); @@ -69,7 +70,7 @@ public class ${classInfo.className}Controller { */ @PostMapping("/find") public Object find(int id){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); + ${classInfo.className} ${classInfo.className?uncap_first} = i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); if(${classInfo.className?uncap_first}!=null){ return ${returnUtil}.SUCCESS(${classInfo.className?uncap_first}); }else{ @@ -82,8 +83,8 @@ public class ${classInfo.className}Controller { */ @PostMapping("/list") public Object list(String searchParams, - @RequestParam(required = false, defaultValue = "0") int page, - @RequestParam(required = false, defaultValue = "10") int limit) { + @RequestParam(required = false, defaultValue = "0") int page, + @RequestParam(required = false, defaultValue = "10") int limit) { log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams)); //分页构造器 Page<${classinfo.classname}> buildPage = new Page<${classinfo.classname}>(page,limit); @@ -94,7 +95,7 @@ public class ${classInfo.className}Controller { queryWrapper.eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${classInfo.className}Name()), "${classInfo.className?uncap_first}_name", ${classInfo.className?uncap_first}.get${classInfo.className}Name()); } //执行分页 - IPage<${classinfo.classname}> pageList = ${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper); + IPage<${classinfo.classname}> pageList = i${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper); //返回结果 return ${returnUtil}.PAGE(pageList.getRecords(),pageList.getTotal()); } @@ -103,8 +104,8 @@ public class ${classInfo.className}Controller { */ @PostMapping("/list2") public ReturnT list2(String searchParams, - @RequestParam(required = false, defaultValue = "0") int page, - @RequestParam(required = false, defaultValue = "10") int limit) { + @RequestParam(required = false, defaultValue = "0") int page, + @RequestParam(required = false, defaultValue = "10") int limit) { log.info("searchParams:"+ JSON.toJSONString(searchParams)); //通用模式 ${classInfo.className} queryParamDTO = JSON.parseObject(searchParams, ${classInfo.className}.class); @@ -113,8 +114,8 @@ public class ${classInfo.className}Controller { //queryParamDTO.setPage((page - 1)* limit); //queryParamDTO.setLimit(limit); //(page - 1) * limit, limit - List<${classinfo.classname}> itemList = ${classInfo.className?uncap_first}Mapper.pageAll(queryParamDTO,(page - 1)* limit,limit); - Integer itemCount = ${classInfo.className?uncap_first}Mapper.countAll(queryParamDTO); + List<${classinfo.classname}> itemList = i${classInfo.className?uncap_first}Mapper.pageAll(queryParamDTO,(page - 1)* limit,limit); + Integer itemCount = i${classInfo.className?uncap_first}Mapper.countAll(queryParamDTO); //返回结果 return ReturnT.PAGE(itemList,itemCount); } @@ -125,7 +126,7 @@ public class ${classInfo.className}Controller { @GetMapping("/edit") public ModelAndView editPage(int id){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); + ${classInfo.className} ${classInfo.className?uncap_first} = i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); return new ModelAndView("cms/${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first}); } @@ -134,11 +135,11 @@ public class ${classInfo.className}Controller { */ @PostMapping("/publish") public Object publish(int id,Integer status){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); + ${classInfo.className} ${classInfo.className?uncap_first} = i${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classinfo.classname}>().eq("${classInfo.className?uncap_first}_id",id)); if(${classInfo.className?uncap_first}!=null){ ${classInfo.className?uncap_first}.setUpdateTime(new Date()); ${classInfo.className?uncap_first}.setStatus(status); - ${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); + i ${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); return ReturnT.SUCCESS((status==1)?"已发布":"已暂停"); }else if(status.equals(${classInfo.className?uncap_first}.getStatus())){ return ReturnT.SUCCESS("状态不正确"); diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusEntity.ftl similarity index 87% rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl rename to generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusEntity.ftl index ed01b9d5..2c450c1b 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusEntity.ftl @@ -8,10 +8,11 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Data<#if swagger?exists && swagger==true> @ApiModel("${classInfo.classComment}") public class ${classInfo.className} implements Serializable { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusMapper.ftl similarity index 85% rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl rename to generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusMapper.ftl index 321b76a7..ed0a9c95 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/mybatisPlusMapper.ftl @@ -7,12 +7,13 @@ import ${packageName}.entity.${classInfo.className}; import java.util.List; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd')} - */ +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ @Mapper -public interface ${classInfo.className}Mapper extends BaseMapper<${classinfo.classname}> { +public interface I${classInfo.className}Mapper extends BaseMapper<${classinfo.classname}> { @Select( "") - List<${classinfo.classname}> pageAll(${classInfo.className} queryParamDTO,int page,int limit); +List<${classinfo.classname}> pageAll(${classInfo.className} queryParamDTO,int page,int limit); - @Select("") - int countAll(${classInfo.className} queryParamDTO); + " ") +int countAll(${classInfo.className} queryParamDTO); } diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/annotationMapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/annotationMapper.ftl index 71d83e52..c94b3b13 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/annotationMapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/annotationMapper.ftl @@ -5,32 +5,32 @@ import org.springframework.stereotype.Repository; import java.util.List; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @Mapper @Repository public interface I${classInfo.className}Mapper { - @Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}") + @Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id = 井{id}") public ${classInfo.className} getById(Integer id); - @Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first}Id") + @Options(useGeneratedKeys = true,keyProperty = "${classInfo.className?uncap_first}Id") @Insert("insert into ${classInfo.tableName}" + - " (<#list classInfo.fieldList as fieldItem>${fieldItem.columnName}<#if fieldItem_has_next>,)" + - " values(<#list classInfo.fieldList as fieldItem>${fieldItem.fieldName}<#if fieldItem_has_next>,<#else>)") + " (<#list classInfo.fieldList as fieldItem>${fieldItem.columnName}<#if fieldItem_has_next>,)" + + " values(<#list classInfo.fieldList as fieldItem>${fieldItem.fieldName}<#if fieldItem_has_next>,<#else>)") public Integer insert(${classInfo.className} ${classInfo.className?uncap_first}); - @Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id}") + @Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id = 井{${classInfo.className?uncap_first}Id}") boolean delete(Integer id); @Update(value = "update ${classInfo.tableName} set " <#list classInfo.fieldList as fieldItem> - <#if fieldItem.columnName != "id">+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>," + <#if fieldItem.columnName != "id">+ " ${fieldItem.columnName} = 井{${fieldItem.fieldName}}<#if fieldItem_has_next>," - +" where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ") + + " where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ") boolean update(${classInfo.className} ${classInfo.className?uncap_first}); @@ -39,7 +39,7 @@ public interface I${classInfo.className}Mapper { @Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>, }) - @Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{queryParam}") + @Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id = 井{queryParam}") ${classInfo.className} selectOne(String queryParam); @Results(value = { @@ -49,7 +49,7 @@ public interface I${classInfo.className}Mapper { }) @Select(value = "select * from ${classInfo.tableName} where " <#list classInfo.fieldList as fieldItem> - +" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or " + + " ${fieldItem.columnName} = 井{${fieldItem.fieldName}}<#if fieldItem_has_next> or " ) List<${classinfo.classname}> selectList(${classInfo.className} ${classInfo.className?uncap_first}); diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl index 83d59611..71428afc 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl @@ -1,9 +1,16 @@ package ${packageName}.controller; -import org.springframework.stereotype.Controller; +import ${packageName}.base.dto.*; +import ${packageName}.entity.${classInfo.className}; +import ${packageName}.service.I${classInfo.className}Service; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -11,81 +18,81 @@ import java.util.List; import java.util.Map; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @RestController @RequestMapping(value = "/${classInfo.className?uncap_first}") @Api(tags = "${classInfo.classComment}") public class ${classInfo.className}Controller { @Resource - private I${classInfo.className}Service i${classInfo.className?uncap_first}Service; + private I${classInfo.className}Service i${classInfo.className}Service; /** - * 新增 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 新增 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/insert") @ApiOperation(value = "保存${classInfo.className}",notes = "保存${classInfo.className}") <#-- @ApiImplicitParam(name = "${classInfo.className?uncap_first}",value = "${classInfo.classComment}",dataType = "${classInfo.className}",required = true)--> - public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}){ - return i${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first}); + public ResponseBaseDTO insert(${classInfo.className}Dto ${classInfo.className?uncap_first}Dto){ + return i${classInfo.className}Service.insert(${classInfo.className?uncap_first}Dto); } /** - * 刪除 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 刪除 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/delete") @ApiOperation(value = "刪除${classInfo.className}",notes = "刪除${classInfo.className}") @ApiImplicitParam(name = "${classInfo.className?uncap_first}",value = "${classInfo.classComment}",dataType = "int",required = true) - public ReturnT delete(int id){ - return i${classInfo.className?uncap_first}Service.delete(id); + public ResponseBaseDTO delete(int id){ + return i${classInfo.className}Service.delete(id); } /** - * 更新 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 更新 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/update") @ApiOperation(value = "更新${classInfo.className}",notes = "更新${classInfo.className}") <#-- @ApiImplicitParam(name = "${classInfo.className?uncap_first}",value = "${classInfo.classComment}",dataType = "${classInfo.className}",required = true)--> - public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}){ - return i${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first}); + public ResponseBaseDTO update(${classInfo.className}RequestDto ${classInfo.className?uncap_first}Dto){ + return i${classInfo.className}Service.update(${classInfo.className?uncap_first}Dto); } /** - * 查询 根据主键 id 查询 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 查询 根据主键 id 查询 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/load") @ApiOperation(value = "根据主键查询${classInfo.className}",notes = "根据主键查询${classInfo.className}") @ApiImplicitParam(name = "${classInfo.className?uncap_first}",value = "${classInfo.classComment}",dataType = "int",required = true) - public ReturnT load(int id){ - return i${classInfo.className?uncap_first}Service.load(id); + public ResponseBaseDTO load(int id){ + return i${classInfo.className}Service.load(id); } /** - * 查询 分页查询 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 查询 分页查询 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/pageList") @ApiOperation(value = "分页查询",notes = "分页查询") @ApiImplicitParams({ - @ApiImplicitParam(name="offset",value="偏移量",required=true,paramType="query"), - @ApiImplicitParam(name="pagesize",value="每页数量",required=true,paramType="query"), + @ApiImplicitParam(name="offset",value="偏移量",required=true,paramType="query"), + @ApiImplicitParam(name="pagesize",value="每页数量",required=true,paramType="query"), }) - public Map pageList(@RequestParam(required = false, defaultValue = "0") int offset, - @RequestParam(required = false, defaultValue = "10") int pagesize) { - return i${classInfo.className?uncap_first}Service.pageList(offset, pagesize); + public ResponseBaseDTO pageList(@RequestParam(required = false, defaultValue = "0") int offset, + @RequestParam(required = false, defaultValue = "10") int pagesize) { + return i${classInfo.className}Service.pageList(offset, pagesize); } } diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/dto.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/dto.ftl index 5d743369..ee54f03f 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/dto.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/dto.ftl @@ -4,11 +4,11 @@ import java.util.Date; import java.util.List; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @Data<#if swagger?exists && swagger==true> @ApiModel("${classInfo.classComment}") public class ${classInfo.className}Dto implements Serializable { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl index 473af46a..5fc60b7f 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl @@ -1,58 +1,61 @@ +package ${packageName}.base.mapper + +import ${packageName}.base.entity.${classInfo.className}; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Repository; +<#--import org.springframework.stereotype.Repository;--> import java.util.List; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @Mapper -@Repository +<#--@repository--> public interface I${classInfo.className}Mapper { /** - * 新增 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 新增 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ int insert(${classInfo.className} ${classInfo.className?uncap_first}); /** - * 刪除 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 刪除 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ int delete(int id); /** - * 更新 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 更新 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ int update(${classInfo.className} ${classInfo.className?uncap_first}); /** - * 查询 根据主键 id 查询 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ - ${classInfo.className} load(int id); + * 查询 根据主键 id 查询 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + ${classInfo.className} queryById(int id); /** - * 查询 分页查询 - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 查询 分页查询 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ List<${classinfo.classname}> pageList(int offset,int pagesize); /** - * 查询 分页查询 count - * @author ${authorName} - * @date ${.now?string('yyyy/MM/dd')} - **/ + * 查询 分页查询 count + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ int pageListCount(int offset,int pagesize); } diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mybatisMapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/mybatisMapper.ftl index 4bc568db..a26b238c 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/mybatisMapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/mybatisMapper.ftl @@ -1,12 +1,12 @@ -
      +
        - + <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> <#list classInfo.fieldList as fieldItem> - + @@ -19,39 +19,40 @@ - + INSERT INTO ${classInfo.tableName}
        <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> - <#list classInfo.fieldList as fieldItem> - <#if fieldItem.columnName != "id"> - ${r""} - ${fieldItem.columnName}<#if fieldItem_has_next>, - ${r""} - - + <#list classInfo.fieldList as fieldItem> + <#if fieldItem.columnName != "id"> + ${r""} + ${fieldItem.columnName}<#if fieldItem_has_next>, + ${r""} + +
        <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> - <#list classInfo.fieldList as fieldItem> - <#if fieldItem.columnName != "id"> - <#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime"> - ${r""} - NOW()<#if fieldItem_has_next>, - ${r""} - <#else>--> - ${r""} - ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>, - ${r""} - <#----> - - + <#list classInfo.fieldList as fieldItem> + <#if fieldItem.columnName != "id"> + <#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime"> + ${r""} + NOW()<#if fieldItem_has_next>, + ${r""} + <#else>--> + ${r""} + ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>, + ${r""} + <#----> + + - + DELETE FROM ${classInfo.tableName} WHERE id = ${r"#{id}"} @@ -61,7 +62,7 @@ <#list classInfo.fieldList as fieldItem> <#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime"> - ${r""}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,${r""} + ${r""}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,${r""} @@ -70,13 +71,15 @@ diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/requestDto.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/requestDto.ftl new file mode 100644 index 00000000..e42695ed --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/requestDto.ftl @@ -0,0 +1,34 @@ +import java.io.Serializable; +import lombok.Data; +import lombok.Builder; +import java.util.Date; +import java.util.List; + +/** +* @author ${authorName} +* @Version 1.0.0 +* @date ${.now?string('yyyy-MM-dd')} +* @description ${classInfo.classComment} +*/ +@Data<#if swagger?exists && swagger==true> + @ApiModel("${classInfo.classComment}" , description ="${classInfo.classComment}")) +@Builder +public class ${classInfo.className}RequestDto implements Serializable { + +private static final long serialVersionUID = 1L; + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + <#list classInfo.fieldList as fieldItem> + /** + * ${fieldItem.fieldComment} + */<#if swagger?exists && swagger==true> + @ApiModelProperty( value = "${fieldItem.columnName}", example = "${fieldItem.fieldComment}",required = true, dataType = "${fieldItem.fieldClass}") + private ${fieldItem.fieldClass} ${fieldItem.fieldName}; + + + public ${classInfo.className}RequestDto() { + } + + +} diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl index 3690b40c..788d59b5 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl @@ -1,36 +1,37 @@ import java.util.Map; +import ${packageName}.base.dto.${classInfo.className}Dto; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ public interface I${classInfo.className}Service { /** - * 新增 - */ - public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}); + * 新增 + */ + public ResponseBaseDTO insert(${classInfo.className}Dto ${classInfo.className?uncap_first}Dto); /** - * 删除 - */ - public ReturnT delete(int id); + * 删除 + */ + public ResponseBaseDTO delete(int id); /** - * 更新 - */ - public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}); + * 更新 + */ + public ResponseBaseDTO update(${classInfo.className}Dto ${classInfo.className?uncap_first}Dto); /** - * 根据主键 id 查询 - */ - public ${classInfo.className} load(int id); + * 根据主键 id 查询 + */ + public ResponseBaseDTO queryById(int id); /** - * 分页查询 - */ - public Map pageList(int offset, int pagesize); + * 分页查询 + */ + public ResponseBaseDTO pageList(int offset, int pagesize); } diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service.impl.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service.impl.ftl index 608cf60e..5a8a6924 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service.impl.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service.impl.ftl @@ -1,5 +1,6 @@ import org.springframework.stereotype.Service; - +import ${packageName}.mapper.I${classInfo.className}Mapper; +import ${packageName}.entity.${classInfo.className}; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; @@ -7,63 +8,79 @@ import java.util.List; import java.util.Map; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @Service -public class I${classInfo.className}ServiceImpl implements ${classInfo.className}Service { +public class I${classInfo.className}ServiceImpl implements I${classInfo.className}Service { @Resource - private I${classInfo.className}Mapper i${classInfo.className?uncap_first}Mapper; + private I${classInfo.className}Mapper i${classInfo.className}Mapper; @Override - public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}) { + public ResponseBaseDTO insert(${classInfo.className}Dto ${classInfo.className?uncap_first}Dto) { // valid - if (${classInfo.className?uncap_first} == null) { + if (${classInfo.className?uncap_first}Dto == null) { return ${returnUtil}.ERROR("必要参数缺失"); } + ${classInfo.className} ${classInfo.className?uncap_first} = new ${classInfo.className}(); + //dto convert to entity ... - i${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); - return ${returnUtil}.SUCCESS; + int ret = i${classInfo.className}Mapper.insert(${classInfo.className?uncap_first}); + return ${returnUtil}.SUCCESS(ret); } @Override - public ReturnT delete(int id) { - int ret = i${classInfo.className?uncap_first}Mapper.delete(id); - return ret>0?${returnUtil}.SUCCESS():${returnUtil}.ERROR(); + public ResponseBaseDTO delete(int id) { + int ret = i${classInfo.className}Mapper.delete(id); + return ret> 0 ? ${returnUtil}.SUCCESS(ret) : ${returnUtil}.ERROR(); } @Override - public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}) { - int ret = i${classInfo.className?uncap_first}Mapper.update(${classInfo.className?uncap_first}); - return ret>0?${returnUtil}.SUCCESS():${returnUtil}.ERROR(); + public ResponseBaseDTO update(${classInfo.className}Dto ${classInfo.className?uncap_first}Dto) { + + // valid + if (${classInfo.className?uncap_first}Dto == null) { + return ${returnUtil}.ERROR("必要参数缺失"); + } + ${classInfo.className} ${classInfo.className?uncap_first} = queryById(${classInfo.className?uncap_first}Dto.getId()); + if (${classInfo.className?uncap_first}Dto == null) { + return ${returnUtil}.ERROR("未查到相关数据!"); + } + ${classInfo.className} ${classInfo.className?uncap_first}ToUpdate = new ${classInfo.className}(); + //dto convert to entity ... + + int ret = i${classInfo.className}Mapper.update(${classInfo.className?uncap_first}ToUpdate); + + return ret> 0 ? ${returnUtil}.SUCCESS(ret) : ${returnUtil}.ERROR(); } @Override - public ${classInfo.className} load(int id) { - return i${classInfo.className?uncap_first}Mapper.load(id); + public ResponseBaseDTO queryById(int id) { + ${classInfo.className} ${classInfo.className?uncap_first} = i${classInfo.className}Mapper.queryById(id); + return ${classInfo.className?uncap_first} == null ? ResponseBaseDTO.ERROR(ErrorCodeEnum.ERROR_3000.getName()) : ResponseBaseDTO.SUCCESS(${classInfo.className?uncap_first}); } @Override - public Map pageList(int offset, int pagesize) { + public ResponseBaseDTO pageList(int offset, int pagesize) { - List<${classinfo.classname}> pageList = ${classInfo.className?uncap_first}Mapper.pageList(offset, pagesize); - int totalCount = i${classInfo.className?uncap_first}Mapper.pageListCount(offset, pagesize); + List<${classinfo.classname}> pageList = i${classInfo.className}Mapper.pageList(offset, pagesize); + int totalCount = i${classInfo.className}Mapper.pageListCount(offset, pagesize); // result - Map result = new HashMap(); + Map result = new HashMap(); result.put("pageList", pageList); result.put("totalCount", totalCount); - return result; + return ResponseBaseDTO.SUCCESS(result); } } diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/vo.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/vo.ftl index 62e2a441..46469bb2 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/vo.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/vo.ftl @@ -9,24 +9,23 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** -* @author ${authorName} -* @Version 1.0.0 -* @date ${.now?string('yyyy-MM-dd')} -* @description ${classInfo.classComment} -*/ + * @author ${authorName} + * @Version 1.0.0 + * @date ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + */ @Builder @Data @ApiModel(value = "${classInfo.tableName}", description ="${classInfo.classComment}") public class ${classInfo.className}Vo implements Serializable { -private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L; <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> <#list classInfo.fieldList as fieldItem> - @ApiModelProperty( value = "${fieldItem.columnName}", example = "${fieldItem.fieldComment}",required = true, dataType = "${fieldItem.fieldClass}") - private ${fieldItem.fieldClass} ${fieldItem.fieldName}; + @ApiModelProperty(value = "${fieldItem.columnName}", example = "${fieldItem.fieldComment}", required = true, dataType = "${fieldItem.fieldClass}") + private ${fieldItem.fieldClass} ${fieldItem.fieldName}; diff --git a/generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl b/generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl index eaefd431..a8fecce2 100644 --- a/generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl +++ b/generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl @@ -4,7 +4,8 @@ <#list classInfo.fieldList as fieldItem>
        - +
        diff --git a/generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl b/generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl index f92857ec..9ba8b797 100644 --- a/generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl +++ b/generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl @@ -1,17 +1,18 @@ - -
        ${classInfo.classComment} - 提交 + 提交 + 返回
        <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> <#list classInfo.fieldList as fieldItem> - - - + + +
        diff --git a/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl b/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl index 59571904..9e09891f 100644 --- a/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl +++ b/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl @@ -6,7 +6,8 @@ - +