├── .gitignore ├── README.md ├── pom.xml └── src ├── assembly └── assembly.xml └── main ├── java └── com │ └── gzz │ └── createcode │ ├── CreateCodeApplication.java │ ├── common │ ├── base │ │ ├── BaseCondition.java │ │ ├── BaseDao.java │ │ └── Page.java │ └── utils │ │ ├── FreemarkerUtils.java │ │ ├── SqlFormatterUtils.java │ │ └── Utils.java │ └── mvc │ ├── action │ ├── CodeAction.java │ └── CommonAction.java │ ├── dao │ └── CodeDao.java │ ├── model │ ├── CodeCond.java │ ├── Field.java │ ├── Table.java │ └── ValidField.java │ └── service │ └── CodeService.java └── resources ├── application.yml ├── code ├── .idea │ └── .gitignore ├── android │ ├── Model.java │ ├── ModelCond.java │ ├── ModelRequest.java │ └── ModelService.java ├── appcenter │ ├── IModelClient.java │ ├── ModelAction.java │ └── ModelBus.java ├── boot │ ├── MockMvcTestModel.java │ ├── Model.java │ ├── ModelCond.java │ ├── ModelController.java │ ├── ModelDao.java │ └── ModelService.java ├── common │ ├── Model.java │ └── ModelCond.java ├── element-list │ ├── Model.java │ ├── ModelCond.java │ ├── ModelController.java │ ├── ModelDao.java │ ├── ModelDialog.vue │ ├── ModelList.vue │ └── ModelService.java ├── mybatisplus │ ├── IModelMapper.java │ ├── IModelMapper.xml │ ├── IModelService.java │ ├── Model.java │ ├── ModelCond.java │ ├── ModelController.java │ └── ModelServiceImpl.java ├── tree │ ├── Model.java │ ├── ModelCond.java │ ├── ModelController.java │ ├── ModelDao.java │ ├── ModelDialog.vue │ ├── ModelService.java │ └── ModelTree.vue ├── vue_element_ui │ ├── ModelDialog.vue │ ├── ModelList.vue │ └── ModelMock.js ├── vue_iview_ui │ ├── ModelDialog.vue │ ├── ModelList.vue │ └── ModelListExpand.vue ├── vuex_iview_ui │ ├── Model.js │ ├── ModelDialog.vue │ ├── ModelList.vue │ ├── ModelListExpand.vue │ └── ModelRouter.js ├── webcenter │ ├── IModelClient.java │ ├── ModelAction.java │ └── ModelBus.java └── webdata │ ├── ModelController.java │ ├── ModelDao.java │ └── ModelService.java ├── logback-spring.xml ├── static ├── axios.min.js ├── element.css ├── element.min.js ├── fonts │ ├── element-icons.woff │ └── ionicons.ttf └── vue.min.js └── templates └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | /logs/ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 代码生成器 基于SpringCloud SpringBoot SpringJDBC(mybatis plus) VUE 2 | *** 3 | ## 生成Dao Service Controller全部代码及常用方法 4 | *** 5 | ## 生成实体类,查询条件类全部代码 6 | *** 7 | ## 生成前端页面全部代码 8 | *** 9 | ## 页面包括列表 所有查询条件验证及表格扩展全部增删改查页面 10 | *** 11 | ## PC web前端 12 | ### 1. 可使用 vue+element 13 | ### 2. 可使用 vue+iview 14 | ### 3. 可使用 vuex+iview 15 | *** 16 | ## 移动端生成安卓部分代码 17 | *** 18 | ## 联系方式: gzz_gzz@163.com 19 | ## [简书主页:https://www.jianshu.com/u/3bd57d5f1074](https://www.jianshu.com/u/3bd57d5f1074) 20 | ## [演示地址:http://47.104.67.56:8080//](http://47.104.67.56:8080/) 21 | *** 22 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.gzz 7 | code 8 | 1.0 9 | jar 10 | 11 | org.springframework.boot 12 | spring-boot-starter-parent 13 | 2.3.5.RELEASE 14 | 15 | 16 | 17 | UTF-8 18 | UTF-8 19 | 1.8 20 | true 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-devtools 26 | true 27 | compile 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-freemarker 36 | 37 | 38 | mysql 39 | mysql-connector-java 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-jdbc 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | 50 | 51 | com.google.guava 52 | guava 53 | 24.1.1-jre 54 | 55 | 56 | 57 | code 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-jar-plugin 68 | 69 | 70 | 71 | true 72 | com.gzz.createcode.CreateCodeApplication 73 | lib/ 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven.plugins 80 | maven-dependency-plugin 81 | 82 | 83 | copy 84 | package 85 | 86 | copy-dependencies 87 | 88 | 89 | ${project.build.directory}/lib 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | code 7 | 8 | zip 9 | 10 | 11 | 12 | ${project.build.directory}/${project.build.finalName}.jar 13 | ./ 14 | ${project.build.finalName}.jar 15 | 16 | 17 | 18 | 19 | ${project.build.directory}/lib 20 | ./lib 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/CreateCodeApplication.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 我的代码生成器 8 | * 9 | * @author Administrator 10 | * 11 | */ 12 | @SpringBootApplication 13 | public class CreateCodeApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(CreateCodeApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/base/BaseCondition.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.base; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | import org.springframework.util.CollectionUtils; 9 | import org.springframework.util.StringUtils; 10 | 11 | /** 12 | * @功能说明 拼加页面查询条件的基础类 13 | * @author https://www.jianshu.com/u/3bd57d5f1074 14 | * @date 2020-02-02 02:20:20 15 | */ 16 | public abstract class BaseCondition { 17 | 18 | private static final List paramList = new ArrayList<>();// 参数值 19 | private static final StringBuffer condition = new StringBuffer();// 条件语句 20 | private int size = 10;// 页大小(每页记录条) 21 | private int page = 0;// 当前页码 22 | 23 | /** 24 | * @功能说明: 拼加条件使用等于大于小于....运算符(String类型) 25 | */ 26 | final protected void add(final String sql, final String value) { 27 | if (!StringUtils.isEmpty(value)) { 28 | condition.append(" " + sql); 29 | paramList.add(value); 30 | } 31 | } 32 | 33 | /** 34 | * @功能说明: 拼加条件使用等于大于小于....运算符(Short类型) 35 | */ 36 | final protected void add(final String sql, final Short value) { 37 | if (value != null) { 38 | condition.append(" " + sql); 39 | paramList.add(value); 40 | } 41 | } 42 | 43 | final protected void add(final String sql, final Byte value) { 44 | if (value != null) { 45 | condition.append(" " + sql); 46 | paramList.add(value); 47 | } 48 | } 49 | 50 | /** 51 | * @功能说明 拼加条件使用等于大于小于....运算符(String类型) 52 | */ 53 | final protected void add(final String sql, final Float value) { 54 | if (value != null) { 55 | condition.append(" " + sql); 56 | paramList.add(value); 57 | } 58 | } 59 | 60 | /** 61 | * @功能说明: 拼加条件使用等于大于小于....运算符(Long类型) 62 | */ 63 | 64 | final protected void add(final String sql, final Long value) { 65 | if (value != null) { 66 | condition.append(" " + sql); 67 | paramList.add(value); 68 | } 69 | } 70 | 71 | /** 72 | * @功能说明: 拼加条件使用等于大于小于....运算符(Boolean类型) 73 | */ 74 | final protected void add(final String sql, final Boolean value) { 75 | if (value != null) { 76 | condition.append(" " + sql); 77 | paramList.add(value); 78 | } 79 | } 80 | 81 | /** 82 | * @功能说明 拼加条件使用等于大于小于....运算符(BigDecimal类型) 83 | */ 84 | final protected void add(final String sql, final BigDecimal value) { 85 | if (value != null) { 86 | condition.append(" " + sql); 87 | paramList.add(value); 88 | } 89 | } 90 | 91 | /** 92 | * @功能说明 拼加条件使用等于大于小于....运算符(Integer类型) 93 | */ 94 | final protected void add(final String sql, final Integer value) { 95 | if (value != null) { 96 | condition.append(" " + sql); 97 | paramList.add(value); 98 | } 99 | } 100 | 101 | /** 102 | * @功能说明: 拼加条件使用等于大于小于....运算符(Date类型) 103 | */ 104 | final protected void add(final String sql, final Date value) { 105 | if (value != null) { 106 | condition.append(" " + sql); 107 | paramList.add(value); 108 | } 109 | } 110 | 111 | /** 112 | * @功能说明 不使用占位符直接拼SQL(不建议使用) 113 | */ 114 | final protected void add(final String sql) { 115 | if (null != sql && !"".equals(sql)) { 116 | condition.append(" " + sql); 117 | } 118 | } 119 | 120 | /** 121 | * @功能 拼加条件in子句 122 | */ 123 | final protected void add(final String sql, final List ids) { 124 | if (!CollectionUtils.isEmpty(ids)) { 125 | condition.append(" " + sql + toIn(ids.toArray())); 126 | paramList.addAll(ids); 127 | } 128 | } 129 | 130 | /** 131 | * @功能说明 拼加条件使用like关键字模糊查询时 132 | */ 133 | final protected void add(final String sql, final String value, final int pos) { 134 | if (!StringUtils.isEmpty(value)) { 135 | condition.append(" " + sql); 136 | if (pos == 1) { 137 | paramList.add("%" + value); 138 | } else if (pos == 2) { 139 | paramList.add(value + "%"); 140 | } else if (pos == 3) { 141 | paramList.add("%" + value + "%"); 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * @功能说明 将List转为数组 148 | */ 149 | final public Object[] array() { 150 | return paramList.toArray(); 151 | } 152 | 153 | /** 154 | * @功能说明 把一个and换成where 155 | */ 156 | 157 | final public String where() { 158 | return and().replaceFirst("(?i)(AND)", "WHERE"); 159 | } 160 | 161 | /** 162 | * @功能说明 取条件字符串 163 | */ 164 | 165 | final public String and() { 166 | condition.setLength(0); // 清除查询条件 167 | paramList.clear(); 168 | addCondition(); 169 | return condition.toString(); 170 | } 171 | 172 | /** 173 | * @方法说明 把组数拼接成(?,?,?)的形式 174 | */ 175 | final public static String toIn(final Object ids[]) { 176 | StringBuffer sb = new StringBuffer(" (?"); 177 | for (int i = 1; i < ids.length; i++) { 178 | sb.append(",?"); 179 | } 180 | sb.append(")"); 181 | return sb.toString(); 182 | } 183 | 184 | /** 185 | * @功能说明 拼加条件方法 186 | */ 187 | public abstract void addCondition(); 188 | 189 | public int getSize() { 190 | return size; 191 | } 192 | 193 | public void setSize(int size) { 194 | this.size = size; 195 | } 196 | 197 | public int getPage() { 198 | return page; 199 | } 200 | 201 | public void setPage(int page) { 202 | this.page = page; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/base/BaseDao.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.base; 2 | 3 | import java.lang.reflect.Field; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Scope; 11 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 12 | import org.springframework.jdbc.core.JdbcTemplate; 13 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 14 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 15 | import org.springframework.jdbc.support.GeneratedKeyHolder; 16 | import org.springframework.jdbc.support.KeyHolder; 17 | 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | /** 21 | * @功能描述 dao类公共类 22 | * @author https://www.jianshu.com/u/3bd57d5f1074 23 | * @date 2020-02-02 02:20:20 24 | */ 25 | @Scope("prototype") 26 | @Slf4j 27 | public class BaseDao { 28 | 29 | @Autowired 30 | protected JdbcTemplate jdbcTemplate; 31 | @Autowired 32 | protected NamedParameterJdbcTemplate nameJdbcTemplate; 33 | 34 | /** 35 | * @功能描述 分页查询 36 | */ 37 | final protected Page queryPage(final String sql, C cond, final Class clazz) { 38 | // String countSQL = "SELECT count(1) FROM (" + sql + ") t"; 39 | String countSQL = sql.replaceAll("(?i)(SELECT)(.*)(?i)(FROM)", "$1 count(1) $3");// 高效不支持嵌套 40 | log.debug(sql(countSQL, cond.array())); 41 | int rowCount = jdbcTemplate.queryForObject(countSQL, cond.array(), Integer.class); 42 | int pageSize = cond.getSize(); 43 | int curPage = cond.getPage(); 44 | int pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1; 45 | StringBuffer listSQL = new StringBuffer(); 46 | listSQL.append(sql); 47 | listSQL.append(" LIMIT "); 48 | listSQL.append(curPage * pageSize); 49 | listSQL.append(","); 50 | listSQL.append(pageSize); 51 | log.debug(sql(listSQL.toString(), cond.array())); 52 | List dataList = jdbcTemplate.query(listSQL.toString(), cond.array(), new BeanPropertyRowMapper(clazz)); 53 | return new Page(dataList, pageSize, rowCount, curPage, pageCount); 54 | } 55 | 56 | /** 57 | * @功能描述 批操作 58 | */ 59 | final protected int[] batchOperate(final List list, final String sql) { 60 | return nameJdbcTemplate.batchUpdate(sql, list.stream().map(i -> new BeanPropertySqlParameterSource(i)).collect(Collectors.toList()).toArray(new BeanPropertySqlParameterSource[] {})); 61 | } 62 | 63 | /** 64 | * @功能描述 保存数据返回主键 65 | */ 66 | final protected int saveKey(final T t, String sql, final String id) { 67 | KeyHolder keyHolder = new GeneratedKeyHolder(); 68 | nameJdbcTemplate.update(sql, new BeanPropertySqlParameterSource(t), keyHolder, new String[] { id }); 69 | return keyHolder.getKey().intValue(); 70 | } 71 | 72 | /** 73 | * @方法说明:数据库中执行的SQL语句 74 | */ 75 | final protected static String sql(String sql, final Object... object) { 76 | for (Object obj : object) { 77 | String param = "NOT FOUND PARAM!!"; 78 | if (null != obj) { 79 | if (obj instanceof Date) { 80 | param = "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(obj) + "'"; 81 | } else if (obj instanceof String) { 82 | param = "'" + (String) obj + "'"; 83 | } else { 84 | param = obj.toString(); 85 | } 86 | } 87 | sql = sql.replaceFirst("[?]", param); 88 | } 89 | return sql; 90 | } 91 | 92 | /** 93 | * @方法说明 用于保存记录返回主键显示SQL(效率低用完关掉) 94 | */ 95 | final protected static String sqlp(String sql, T t) { 96 | Field[] fields = t.getClass().getDeclaredFields(); 97 | for (Field field : fields) { 98 | try { 99 | field.setAccessible(true); 100 | Object value = field.get(t); 101 | sql = sql.replaceFirst(":" + field.getName(), value == null ? "null" : value.toString()); 102 | } catch (IllegalArgumentException | IllegalAccessException e) { 103 | e.printStackTrace(); 104 | } 105 | } 106 | return sql; 107 | } 108 | 109 | /** 110 | * @方法说明 用于批操作显示SQL(效率极低用完关掉) 111 | */ 112 | final protected static String sqlp(String sql, List list) { 113 | StringBuffer sb = new StringBuffer(); 114 | for (T t : list) { 115 | sb.append(sqlp(sql, t) + "/r/n"); 116 | } 117 | return sb.toString(); 118 | } 119 | 120 | /** 121 | * @方法说明 把组数拼接成(?,?,?)的形式 122 | */ 123 | final public static String toIn(final Object ids[]) { 124 | StringBuffer sb = new StringBuffer(" (?"); 125 | for (int i = 1; i < ids.length; i++) { 126 | sb.append(",?"); 127 | } 128 | sb.append(")"); 129 | return sb.toString(); 130 | } 131 | } -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/base/Page.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.base; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | 8 | /** 9 | * @功能描述 分页数据 10 | * @author https://www.jianshu.com/u/3bd57d5f1074 11 | * @date 2020-02-02 02:20:20 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | public class Page { 16 | private List dataList; /* 数据列表 */ 17 | private int pageSize = 10; /* 页大小(每页记录条) */ 18 | private long rowCount;/* 记录总数 */ 19 | private int curpage = 0;/* 当前页码 */ 20 | private int pageCount;/* 当前页码 */ 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/utils/FreemarkerUtils.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.utils; 2 | 3 | import java.io.File; 4 | import java.nio.charset.Charset; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.springframework.boot.CommandLineRunner; 10 | import org.springframework.stereotype.Component; 11 | 12 | import com.google.common.io.Files; 13 | 14 | import freemarker.template.Configuration; 15 | import freemarker.template.Template; 16 | import lombok.extern.slf4j.Slf4j; 17 | 18 | @Slf4j 19 | @Component 20 | public final class FreemarkerUtils implements CommandLineRunner { 21 | private Configuration cfg = new Configuration(Configuration.VERSION_2_3_29); 22 | private Template template; 23 | private List templates = new ArrayList<>(); 24 | 25 | @Override 26 | public void run(String... args) throws Exception { 27 | cfg.setClassForTemplateLoading(this.getClass(), "/code/"); 28 | cfg.setDefaultEncoding("UTF-8"); 29 | templates = Utils.scanTemplate("code"); 30 | 31 | // templates.add("boot/MockMvcTestModel.java"); 32 | // templates.add("boot/ModelService.java"); 33 | // templates.add("boot/ModelDao.java"); 34 | // templates.add("boot/ModelController.java"); 35 | // templates.add("boot/ModelCond.java"); 36 | // templates.add("boot/Model.java"); 37 | 38 | } 39 | 40 | public void process(String templateName, Map params) { 41 | try { 42 | String[] split = templateName.split("/"); 43 | File file = new File(params.get("path") + split[1].replace("Model", params.get("upp").toString())); 44 | template = cfg.getTemplate(templateName); 45 | Files.createParentDirs(file); 46 | template.process(params, Files.newWriter(file, Charset.forName("utf-8"))); 47 | } catch (Exception e) { 48 | log.error("生成代码时出显异常!", e); 49 | } 50 | 51 | } 52 | 53 | public List getTemplates() { 54 | return templates; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/utils/SqlFormatterUtils.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.utils; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedList; 5 | import java.util.Set; 6 | import java.util.StringTokenizer; 7 | 8 | public class SqlFormatterUtils { 9 | 10 | private static final Set BEGIN_CLAUSES = new HashSet(); 11 | private static final Set END_CLAUSES = new HashSet(); 12 | private static final Set LOGICAL = new HashSet(); 13 | private static final Set QUANTIFIERS = new HashSet(); 14 | private static final Set DML = new HashSet(); 15 | private static final Set MISC = new HashSet(); 16 | static final String indentString = " "; 17 | static final String initial = "\n "; 18 | 19 | public static String format(String source) { 20 | return new FormatProcess(source).perform().trim(); 21 | } 22 | 23 | static { 24 | BEGIN_CLAUSES.add("left"); 25 | BEGIN_CLAUSES.add("right"); 26 | BEGIN_CLAUSES.add("inner"); 27 | BEGIN_CLAUSES.add("outer"); 28 | BEGIN_CLAUSES.add("group"); 29 | BEGIN_CLAUSES.add("order"); 30 | 31 | END_CLAUSES.add("where"); 32 | END_CLAUSES.add("set"); 33 | END_CLAUSES.add("having"); 34 | END_CLAUSES.add("join"); 35 | END_CLAUSES.add("from"); 36 | END_CLAUSES.add("by"); 37 | END_CLAUSES.add("join"); 38 | END_CLAUSES.add("into"); 39 | END_CLAUSES.add("union"); 40 | 41 | LOGICAL.add("and"); 42 | LOGICAL.add("or"); 43 | LOGICAL.add("when"); 44 | LOGICAL.add("else"); 45 | LOGICAL.add("end"); 46 | 47 | QUANTIFIERS.add("in"); 48 | QUANTIFIERS.add("all"); 49 | QUANTIFIERS.add("exists"); 50 | QUANTIFIERS.add("some"); 51 | QUANTIFIERS.add("any"); 52 | 53 | DML.add("insert"); 54 | DML.add("update"); 55 | DML.add("delete"); 56 | 57 | MISC.add("select"); 58 | MISC.add("on"); 59 | } 60 | 61 | private static class FormatProcess { 62 | boolean beginLine = true; 63 | boolean afterBeginBeforeEnd = false; 64 | boolean afterByOrSetOrFromOrSelect = false; 65 | boolean afterOn = false; 66 | boolean afterBetween = false; 67 | boolean afterInsert = false; 68 | int inFunction = 0; 69 | int parensSinceSelect = 0; 70 | private LinkedList parenCounts = new LinkedList(); 71 | private LinkedList afterByOrFromOrSelects = new LinkedList(); 72 | 73 | int indent = 1; 74 | 75 | StringBuffer result = new StringBuffer(); 76 | StringTokenizer tokens; 77 | String lastToken; 78 | String token; 79 | String lcToken; 80 | 81 | public FormatProcess(String sql) { 82 | this.tokens = new StringTokenizer(sql, "()+*/-=<>'`\"[], \n\r\f\t", true); 83 | } 84 | 85 | public String perform() { 86 | this.result.append("\n "); 87 | 88 | while (this.tokens.hasMoreTokens()) { 89 | this.token = this.tokens.nextToken(); 90 | this.lcToken = this.token.toLowerCase(); 91 | 92 | if ("'".equals(this.token)) { 93 | String t; 94 | do { 95 | t = this.tokens.nextToken(); 96 | this.token += t; 97 | } while ((!"'".equals(t)) && (this.tokens.hasMoreTokens())); 98 | } else if ("\"".equals(this.token)) { 99 | String t; 100 | do { 101 | t = this.tokens.nextToken(); 102 | this.token += t; 103 | } while (!"\"".equals(t)); 104 | } 105 | 106 | if ((this.afterByOrSetOrFromOrSelect) && (",".equals(this.token))) { 107 | commaAfterByOrFromOrSelect(); 108 | } else if ((this.afterOn) && (",".equals(this.token))) { 109 | commaAfterOn(); 110 | } else if ("(".equals(this.token)) { 111 | openParen(); 112 | } else if (")".equals(this.token)) { 113 | closeParen(); 114 | } else if (BEGIN_CLAUSES.contains(this.lcToken)) { 115 | beginNewClause(); 116 | } else if (END_CLAUSES.contains(this.lcToken)) { 117 | endNewClause(); 118 | } else if ("select".equals(this.lcToken)) { 119 | select(); 120 | } else if (DML.contains(this.lcToken)) { 121 | updateOrInsertOrDelete(); 122 | } else if ("values".equals(this.lcToken)) { 123 | values(); 124 | } else if ("on".equals(this.lcToken)) { 125 | on(); 126 | } else if ((this.afterBetween) && (this.lcToken.equals("and"))) { 127 | misc(); 128 | this.afterBetween = false; 129 | } else if (LOGICAL.contains(this.lcToken)) { 130 | logical(); 131 | } else if (isWhitespace(this.token)) { 132 | white(); 133 | } else { 134 | misc(); 135 | } 136 | 137 | if (!isWhitespace(this.token)) { 138 | this.lastToken = this.lcToken; 139 | } 140 | } 141 | 142 | return this.result.toString(); 143 | } 144 | 145 | private void commaAfterOn() { 146 | out(); 147 | this.indent -= 1; 148 | newline(); 149 | this.afterOn = false; 150 | this.afterByOrSetOrFromOrSelect = true; 151 | } 152 | 153 | private void commaAfterByOrFromOrSelect() { 154 | out(); 155 | newline(); 156 | } 157 | 158 | private void logical() { 159 | if ("end".equals(this.lcToken)) { 160 | this.indent -= 1; 161 | } 162 | newline(); 163 | out(); 164 | this.beginLine = false; 165 | } 166 | 167 | private void on() { 168 | this.indent += 1; 169 | this.afterOn = true; 170 | newline(); 171 | out(); 172 | this.beginLine = false; 173 | } 174 | 175 | private void misc() { 176 | out(); 177 | if ("between".equals(this.lcToken)) { 178 | this.afterBetween = true; 179 | } 180 | if (this.afterInsert) { 181 | newline(); 182 | this.afterInsert = false; 183 | } else { 184 | this.beginLine = false; 185 | if ("case".equals(this.lcToken)) 186 | this.indent += 1; 187 | } 188 | } 189 | 190 | private void white() { 191 | if (!this.beginLine) 192 | this.result.append(" "); 193 | } 194 | 195 | private void updateOrInsertOrDelete() { 196 | out(); 197 | this.indent += 1; 198 | this.beginLine = false; 199 | if ("update".equals(this.lcToken)) { 200 | newline(); 201 | } 202 | if ("insert".equals(this.lcToken)) 203 | this.afterInsert = true; 204 | } 205 | 206 | private void select() { 207 | out(); 208 | this.indent += 1; 209 | newline(); 210 | this.parenCounts.addLast(Integer.valueOf(this.parensSinceSelect)); 211 | this.afterByOrFromOrSelects.addLast(Boolean.valueOf(this.afterByOrSetOrFromOrSelect)); 212 | this.parensSinceSelect = 0; 213 | this.afterByOrSetOrFromOrSelect = true; 214 | } 215 | 216 | private void out() { 217 | this.result.append(this.token); 218 | } 219 | 220 | private void endNewClause() { 221 | if (!this.afterBeginBeforeEnd) { 222 | this.indent -= 1; 223 | if (this.afterOn) { 224 | this.indent -= 1; 225 | this.afterOn = false; 226 | } 227 | newline(); 228 | } 229 | out(); 230 | if (!"union".equals(this.lcToken)) { 231 | this.indent += 1; 232 | } 233 | newline(); 234 | this.afterBeginBeforeEnd = false; 235 | this.afterByOrSetOrFromOrSelect = (("by".equals(this.lcToken)) || ("set".equals(this.lcToken)) 236 | || ("from".equals(this.lcToken))); 237 | } 238 | 239 | private void beginNewClause() { 240 | if (!this.afterBeginBeforeEnd) { 241 | if (this.afterOn) { 242 | this.indent -= 1; 243 | this.afterOn = false; 244 | } 245 | this.indent -= 1; 246 | newline(); 247 | } 248 | out(); 249 | this.beginLine = false; 250 | this.afterBeginBeforeEnd = true; 251 | } 252 | 253 | private void values() { 254 | this.indent -= 1; 255 | newline(); 256 | out(); 257 | this.indent += 1; 258 | newline(); 259 | } 260 | 261 | private void closeParen() { 262 | this.parensSinceSelect -= 1; 263 | if (this.parensSinceSelect < 0) { 264 | this.indent -= 1; 265 | this.parensSinceSelect = ((Integer) this.parenCounts.removeLast()).intValue(); 266 | this.afterByOrSetOrFromOrSelect = ((Boolean) this.afterByOrFromOrSelects.removeLast()).booleanValue(); 267 | } 268 | if (this.inFunction > 0) { 269 | this.inFunction -= 1; 270 | out(); 271 | } else { 272 | if (!this.afterByOrSetOrFromOrSelect) { 273 | this.indent -= 1; 274 | newline(); 275 | } 276 | out(); 277 | } 278 | this.beginLine = false; 279 | } 280 | 281 | private void openParen() { 282 | if ((isFunctionName(this.lastToken)) || (this.inFunction > 0)) { 283 | this.inFunction += 1; 284 | } 285 | this.beginLine = false; 286 | if (this.inFunction > 0) { 287 | out(); 288 | } else { 289 | out(); 290 | if (!this.afterByOrSetOrFromOrSelect) { 291 | this.indent += 1; 292 | newline(); 293 | this.beginLine = true; 294 | } 295 | } 296 | this.parensSinceSelect += 1; 297 | } 298 | 299 | private static boolean isFunctionName(String tok) { 300 | char begin = tok.charAt(0); 301 | boolean isIdentifier = (Character.isJavaIdentifierStart(begin)) || ('"' == begin); 302 | return (isIdentifier) && (!LOGICAL.contains(tok)) && (!END_CLAUSES.contains(tok)) 303 | && (!QUANTIFIERS.contains(tok)) && (!DML.contains(tok)) && (!MISC.contains(tok)); 304 | } 305 | 306 | private static boolean isWhitespace(String token) { 307 | return " \n\r\f\t".indexOf(token) >= 0; 308 | } 309 | 310 | private void newline() { 311 | this.result.append("\n"); 312 | for (int i = 0; i < this.indent; i++) { 313 | this.result.append(" "); 314 | } 315 | this.beginLine = true; 316 | } 317 | } 318 | 319 | public static void main(String[] args) { 320 | System.out.println(SqlFormatterUtils.format( 321 | "SELECT aa,bb,cc,dd FROM ta1,(SELECT ee,ff,gg from ta2 where ee=ff) ta3 where aa=bb and cc=dd group by dd order by createtime desc limit 3 ")); 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/common/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.common.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.net.JarURLConnection; 9 | import java.net.URL; 10 | import java.net.URLDecoder; 11 | import java.util.ArrayList; 12 | import java.util.Enumeration; 13 | import java.util.LinkedList; 14 | import java.util.List; 15 | import java.util.jar.JarEntry; 16 | import java.util.jar.JarFile; 17 | import java.util.zip.ZipEntry; 18 | import java.util.zip.ZipOutputStream; 19 | 20 | import com.gzz.createcode.mvc.model.Field; 21 | 22 | import lombok.extern.slf4j.Slf4j; 23 | 24 | /** 25 | * @功能说明 代码生成辅助类 26 | * @author gzz_gzz@163.com 27 | * @date 2018-02-15 28 | */ 29 | @Slf4j 30 | public final class Utils { 31 | 32 | /** 33 | * @方法说明 拼接字段,getter,setter等 34 | * @param list 字段列表 35 | * @param prefix 前缀 36 | * @param suffix 后缀 37 | * @param wrap 换行符 38 | * @param join 2首字母大写 1原样 0无 39 | */ 40 | public static StringBuilder addFieldsWrap(final List list, final String prefix, final String suffix, final String wrap, final int firstUpper) { 41 | StringBuilder sb = new StringBuilder(); 42 | for (int i = 0; i < list.size(); i++) { 43 | Field field = list.get(i); 44 | sb.append((i != 0 && i % 8 == 0) ? wrap : ""); 45 | sb.append(prefix.concat(firstUpper == 2 ? Utils.firstUpper(field.getName()) : firstUpper == 1 ? field.getName() : "").concat(suffix)); 46 | } 47 | return sb.delete(sb.length() - 1, sb.length()); 48 | } 49 | 50 | public static StringBuilder addUpdateValue(final List list, final String prefix, final String suffix, final String wrap, final int firstUpper) { 51 | List sta = new ArrayList<>(list); 52 | sta.add(list.get(0)); 53 | sta.remove(0); 54 | return addFieldsWrap(sta, prefix, suffix, wrap, firstUpper); 55 | } 56 | public static StringBuilder addUpdateField(final List list, final String prefix, final String suffix, final String wrap, final int firstUpper) { 57 | List sta = new ArrayList<>(list); 58 | sta.remove(0); 59 | return addFieldsWrap(sta, prefix, suffix, wrap, firstUpper); 60 | } 61 | /** @方法说明 首字母大写 */ 62 | public static String firstUpper(final String word) { 63 | return word.substring(0, 1).toUpperCase() + word.substring(1, word.length()); 64 | } 65 | 66 | /** @方法说明 首字母小写 */ 67 | public static String firstLower(final String word) { 68 | return word.substring(0, 1).toLowerCase() + word.substring(1, word.length()); 69 | } 70 | 71 | /** @方法说明 实体类文件中是否增加java.util.Date的导入 */ 72 | public static String Import(final List list) { 73 | StringBuffer sb= new StringBuffer(""); 74 | sb.append(list.parallelStream().filter(i -> i.getType().equals("BigDecimal")).count() > 0 ? "\r\nimport java.math.BigDecimal;" : ""); 75 | sb.append(list.parallelStream().filter(i -> i.getType().equals("LocalDateTime")).count() > 0 ? "\r\nimport java.time.LocalDateTime;" : ""); 76 | sb.append(list.parallelStream().filter(i -> i.getType().equals("LocalTime")).count() > 0 ? "\r\nimport java.time.LocalTime;" : ""); 77 | sb.append(list.parallelStream().filter(i -> i.getType().equals("LocalDate")).count() > 0 ? "\r\nimport java.time.LocalDate;" : ""); 78 | return sb.toString(); 79 | } 80 | 81 | /** @方法说明 去掉第一个单词 */ 82 | public static String delFirWord(String tName) { 83 | return tName.substring(tName.indexOf("_") + 1); 84 | } 85 | 86 | 87 | 88 | /** @方法说明 主键数据类型 */ 89 | public static String keyType(final List list) { 90 | return list.get(0).getType(); 91 | } 92 | 93 | /** @方法说明 判断操作系统 */ 94 | public static boolean isLinux() { 95 | return !System.getProperty("os.name").toLowerCase().startsWith("windows"); 96 | } 97 | 98 | /** @方法说明 不同系统使用不同路径 */ 99 | public static String path() { 100 | return isLinux() ? "/data/samba_root/code/" : "d:/"; 101 | // return System.getProperty("user.dir") + "/src/main/java/"; 102 | } 103 | 104 | /** @方法说明 Linux时为目录授权 */ 105 | public static void chmod() { 106 | try { 107 | if (isLinux()) 108 | Runtime.getRuntime().exec("chmod 777 -R " + path()); 109 | } catch (IOException e) { 110 | log.info("设置权限时出现异常...", e); 111 | } 112 | } 113 | 114 | /** @方法说明 压缩目录 */ 115 | public static void createZip(final String sourcePath, final String zipPath) { 116 | try { 117 | FileOutputStream fos = new FileOutputStream(zipPath); 118 | ZipOutputStream zos = new ZipOutputStream(fos); 119 | writeZip(new File(sourcePath), "", zos); 120 | zos.close(); 121 | fos.close(); 122 | } catch (FileNotFoundException e) { 123 | log.info("压缩文件...", e); 124 | } catch (IOException e) { 125 | log.info("压缩文件...", e); 126 | }finally { 127 | 128 | } 129 | 130 | } 131 | 132 | /** @方法说明 递规删除目录 */ 133 | public static void delDir(final File file) { 134 | if (file.isDirectory()) { 135 | for (File subFile : file.listFiles()) { 136 | delDir(subFile); 137 | } 138 | } 139 | file.delete(); 140 | } 141 | 142 | /** @方法说明 压缩目录 */ 143 | private static void writeZip(final File file, String parentPath, final ZipOutputStream zos) { 144 | try { 145 | if (file.exists()) { 146 | if (file.isDirectory()) { 147 | parentPath = parentPath + file.getName() + File.separator; 148 | File[] files = file.listFiles(); 149 | if (files.length != 0) { 150 | for (File f : files) { 151 | writeZip(f, parentPath, zos); 152 | } 153 | } else { 154 | zos.putNextEntry(new ZipEntry(parentPath)); 155 | } 156 | } else { 157 | FileInputStream fis = null; 158 | fis = new FileInputStream(file); 159 | ZipEntry ze = new ZipEntry(parentPath + file.getName()); 160 | zos.putNextEntry(ze); 161 | byte[] content = new byte[1024]; 162 | int len; 163 | while ((len = fis.read(content)) != -1) { 164 | zos.write(content, 0, len); 165 | zos.flush(); 166 | } 167 | fis.close(); 168 | } 169 | } 170 | } catch (FileNotFoundException e) { 171 | log.info("压缩文件...", e); 172 | } catch (IOException e) { 173 | log.info("压缩文件...", e); 174 | } 175 | } 176 | 177 | /** @方法说明 扫描模板 */ 178 | public static List scanTemplate(final String packageName) { 179 | List list = null; 180 | try { 181 | URL baseURL = Thread.currentThread().getContextClassLoader().getResource(packageName); 182 | if ("file".equals(baseURL.getProtocol())) { 183 | list = scanFile(baseURL); 184 | } else if ("jar".equals(baseURL.getProtocol())) { 185 | list = scanJar(baseURL, packageName); 186 | } 187 | } catch (Exception e) { 188 | log.info("压缩文件...", e); 189 | } 190 | return list; 191 | } 192 | 193 | /** @方法说明 扫描jar包 */ 194 | private static List scanJar(final URL baseURL, final String packageName) throws IOException { 195 | List classList = new ArrayList<>(); 196 | JarFile jar = ((JarURLConnection) baseURL.openConnection()).getJarFile(); 197 | Enumeration entries = jar.entries(); 198 | while (entries.hasMoreElements()) { 199 | String urlName = entries.nextElement().getName(); 200 | if (urlName.startsWith(packageName) && (urlName.endsWith("java") || urlName.endsWith("vue") || urlName.endsWith("js") || urlName.endsWith("xml"))) { 201 | classList.add(urlName.replace(packageName + "/", "")); 202 | } 203 | } 204 | return classList; 205 | } 206 | 207 | /** @方法说明 扫描源文件 */ 208 | private static List scanFile(final URL path) throws Exception { 209 | File dir = new File(URLDecoder.decode(path.getFile(), "UTF-8")); 210 | if (!dir.exists() || !dir.isDirectory()) { 211 | throw new Exception("没有找到对应的包"); 212 | } 213 | List fileList = new ArrayList<>(); 214 | LinkedList dirs = new LinkedList<>(); 215 | dirs.add(dir); 216 | while (!dirs.isEmpty()) { 217 | File son = dirs.removeFirst(); 218 | if (son.isDirectory()) { 219 | for (File childFile : son.listFiles()) { 220 | dirs.add(childFile); 221 | } 222 | } else if (son.getName().endsWith("java") || son.getName().endsWith("vue") || son.getName().endsWith("js") || son.getName().endsWith("xml")) { 223 | fileList.add(son.getAbsolutePath().substring(dir.getAbsolutePath().length() + 1).replace("\\", "/")); 224 | } 225 | } 226 | return fileList; 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/action/CodeAction.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.action; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.util.List; 10 | 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import com.gzz.createcode.common.utils.Utils; 21 | import com.gzz.createcode.mvc.model.CodeCond; 22 | import com.gzz.createcode.mvc.model.Field; 23 | import com.gzz.createcode.mvc.model.Table; 24 | import com.gzz.createcode.mvc.service.CodeService; 25 | 26 | /** 27 | * @功能描述 代码生成器控制器类 28 | * @author gzz_gzz@163.com 29 | * @date 2018-02-15 30 | */ 31 | @RestController 32 | @RequestMapping("/code") 33 | public class CodeAction { 34 | @Autowired 35 | private CodeService service;// 生成器业务罗辑接口 36 | 37 | /** 38 | * @功能描述 查询数据库中表名列表 39 | */ 40 | @PostMapping("/queryList") 41 | public List queryList(@RequestBody CodeCond cond) { 42 | return service.queryTables(cond); 43 | } 44 | 45 | /** 46 | * @功能描述 查询数据库中表名列表 47 | */ 48 | @PostMapping("/queryField") 49 | public List queryField(@RequestBody CodeCond cond) { 50 | return service.queryFields(cond); 51 | } 52 | 53 | /** 54 | * @功能描述 生成代码 55 | */ 56 | @PostMapping("/create") 57 | public void create(@RequestBody CodeCond cond) { 58 | Utils.delDir(new File(Utils.path() + "com/")); 59 | service.create(cond); 60 | Utils.chmod(); 61 | } 62 | 63 | /** 64 | * @功能描述 下载代码 65 | */ 66 | @GetMapping("/downCode") 67 | public void downCode(HttpServletResponse response) throws IOException { 68 | String fileName = "code.zip"; 69 | Utils.createZip(Utils.path() + "com", Utils.path() + fileName); 70 | Path path = Paths.get(Utils.path() + fileName); 71 | response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); 72 | response.setHeader("Content-Length", "" + Files.size(path)); 73 | response.setContentType("application/zip"); 74 | OutputStream out = response.getOutputStream(); 75 | out.write(Files.readAllBytes(path)); 76 | out.flush(); 77 | out.close(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/action/CommonAction.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.action; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @功能描述 首页的跳转类 8 | * @author gzz_gzz@163.com 9 | * @date 2018-02-15 10 | */ 11 | @Controller 12 | public class CommonAction { 13 | /** 14 | * @功能描述 进入主页面的跳转 15 | */ 16 | @RequestMapping("/") 17 | public String index() { 18 | return "index"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/dao/CodeDao.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.gzz.createcode.common.base.BaseDao; 9 | import com.gzz.createcode.mvc.model.CodeCond; 10 | import com.gzz.createcode.mvc.model.Field; 11 | import com.gzz.createcode.mvc.model.Table; 12 | 13 | import lombok.extern.slf4j.Slf4j; 14 | 15 | /** 16 | * @功能描述 mysql数据访问类 17 | * @author gzz_gzz@163.com 18 | * @date 2020-03-10 19 | */ 20 | @Slf4j 21 | @Repository 22 | public class CodeDao extends BaseDao { 23 | 24 | /** @功能描述 查询表名列表 */ 25 | public List
queryTables(CodeCond cond) { 26 | StringBuilder sb = new StringBuilder(); 27 | sb.append("SELECT table_name t_name,if(table_comment='',table_name,table_comment) comment"); 28 | sb.append(" FROM information_schema.tables WHERE table_schema=(SELECT DATABASE())"); 29 | log.info(sb.toString()); 30 | return jdbcTemplate.query(sb.toString(), new BeanPropertyRowMapper<>(Table.class)); 31 | } 32 | 33 | /** @功能描述 查询字段名列表 */ 34 | public List queryFields(CodeCond cond) { 35 | StringBuilder sb = new StringBuilder(); 36 | sb.append("SELECT COLUMN_NAME NAME,"); 37 | sb.append(" CASE WHEN COLUMN_COMMENT = '' THEN COLUMN_NAME ELSE COLUMN_COMMENT END COMMENT,"); 38 | sb.append(" CASE WHEN DATA_TYPE='varchar' OR DATA_TYPE='text' OR DATA_TYPE='char' OR DATA_TYPE='longtext' OR DATA_TYPE='mediumtext' THEN 'String'"); 39 | sb.append(" WHEN DATA_TYPE = 'tinyint' THEN 'Byte'"); 40 | sb.append(" WHEN DATA_TYPE = 'smallint' THEN 'Short'"); 41 | sb.append(" WHEN DATA_TYPE = 'int' OR DATA_TYPE = 'mediumint' THEN 'Integer'"); 42 | sb.append(" WHEN DATA_TYPE = 'time' THEN 'LocalTime'"); 43 | sb.append(" WHEN DATA_TYPE = 'date' THEN 'LocalDate'"); 44 | sb.append(" WHEN DATA_TYPE = 'datetime' THEN 'LocalDateTime'"); 45 | sb.append(" WHEN DATA_TYPE = 'bigint' THEN 'Long'"); 46 | sb.append(" WHEN DATA_TYPE = 'float' THEN 'Float'"); 47 | sb.append(" WHEN DATA_TYPE = 'longblob' OR DATA_TYPE = 'blob' OR DATA_TYPE = 'tinyblob' OR DATA_TYPE = 'mediumblob' THEN 'Byte[]'"); 48 | sb.append(" WHEN DATA_TYPE = 'double' THEN 'Double'"); 49 | sb.append(" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal'"); 50 | sb.append(" WHEN DATA_TYPE = 'boolean' OR DATA_TYPE = 'bit' THEN 'Boolean'"); 51 | sb.append(" ELSE CONCAT ('DATA TYPE IS ERROR', DATA_TYPE) END type,CHARACTER_MAXIMUM_LENGTH length"); 52 | sb.append(" FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema=(SELECT DATABASE())"); 53 | sb.append(cond.and()); 54 | sb.append(" ORDER BY ORDINAL_POSITION"); 55 | log.info(super.sql(sb.toString(), cond.array())); 56 | return jdbcTemplate.query(sb.toString(), cond.array(), new BeanPropertyRowMapper<>(Field.class)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/model/CodeCond.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.model; 2 | 3 | import java.util.List; 4 | 5 | import com.gzz.createcode.common.base.BaseCondition; 6 | import com.gzz.createcode.common.utils.Utils; 7 | 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | 11 | @Setter 12 | @Getter 13 | public class CodeCond extends BaseCondition { 14 | @Override 15 | public void addCondition() { 16 | add("AND table_name LIKE ?", t_name, 3); 17 | add("AND table_name = ?", t_name_eq); 18 | } 19 | 20 | private String t_name;// 表名模糊 21 | private String t_name_eq;// 表名等于 22 | private String company;// 公司名 23 | private String item_name;// 项目名 24 | private int swagger;// 使用 25 | private String model;// 模块名 26 | private String auth;// 作者名 27 | private List
c_list;// 生成代码用的数据 28 | private String sql; 29 | 30 | public String pack(String app, String low) { 31 | app = app.equals("element-list") ? item_name : app; 32 | return "com." + company + "." + app + "." + model + "." + low; 33 | } 34 | 35 | public String path(String app, String low) { 36 | app = app.equals("element-list") ? item_name : app; 37 | return Utils.path() + "com/" + company + "/" + app + "/" + model + "/" + low + "/"; 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/model/Field.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.model; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | @Setter 7 | @Getter 8 | public class Field { 9 | private String name;// 字段名 10 | private String comment;// 注释 11 | private String type;// 数据类型 12 | private String bigName; // 首字母大写 13 | private Long length; // 字符型的长度 14 | private String camel; // 首字母大写 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/model/Table.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.model; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | @Setter 7 | @Getter 8 | public class Table { 9 | private String t_name;// 表名 10 | private String comment;// 表名注释 11 | private String cls_upp;// 类名(首字母大写) 12 | private String c_name;// 类中文名 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/model/ValidField.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.util.StringUtils; 7 | 8 | public class ValidField { 9 | private static final Map map = new HashMap<>(); 10 | 11 | ValidField() { 12 | map.put("String", "\t//@Length(max = #) //字段长度"); 13 | map.put("Long", "\t//@Max(9223372036854775807L) // bigint"); 14 | map.put("Integer", "\t//@Max(2147483647) // int"); 15 | map.put("Byte", "\t//@Max(127) // tinyint"); 16 | map.put("Short", "\t//@Max(32767) // smallint"); 17 | } 18 | 19 | public static String getValid(Field field) { 20 | String name = field.getName(); 21 | String value = map.get(name); 22 | if (!StringUtils.isEmpty(value)) 23 | return name.equals("String") ? value.replace("#", field.getLength().toString()) : value; 24 | return ""; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/gzz/createcode/mvc/service/CodeService.java: -------------------------------------------------------------------------------- 1 | package com.gzz.createcode.mvc.service; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.google.common.base.CaseFormat; 12 | import com.google.common.collect.Maps; 13 | import com.gzz.createcode.common.utils.FreemarkerUtils; 14 | import com.gzz.createcode.common.utils.Utils; 15 | import com.gzz.createcode.mvc.dao.CodeDao; 16 | import com.gzz.createcode.mvc.model.CodeCond; 17 | import com.gzz.createcode.mvc.model.Field; 18 | import com.gzz.createcode.mvc.model.Table; 19 | 20 | /** 21 | * @功能描述 生成列表类型代码的实现类 22 | * @author gzz_gzz@163.com 23 | * @date 2018-02-15 24 | */ 25 | @Service 26 | public final class CodeService { 27 | 28 | @Autowired 29 | private CodeDao dao; 30 | 31 | @Autowired 32 | private FreemarkerUtils utils; 33 | 34 | /** 35 | * @功能描述 生成代码 36 | */ 37 | public void create(CodeCond cond) { 38 | String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); 39 | String auth = cond.getAuth();// 作者 40 | 41 | for (Table table : cond.getC_list()) { 42 | cond.setT_name_eq(table.getT_name());// 表名 43 | List fList = this.queryFields(cond);// 字段列表 44 | String upp = table.getCls_upp();// 驼峰类名(首字母大写) 45 | String low = upp.toLowerCase();// 类名小写(只用包路径) 46 | Map params = Maps.newHashMap(); 47 | params.put("fList", fList); 48 | params.put("auth", auth); 49 | params.put("cName", table.getC_name());// 表注释中文名 50 | params.put("upp", upp); 51 | params.put("lowUpp", Utils.firstLower(upp));// 驼峰变量类名(首字母小写) 52 | params.put("low", low); 53 | params.put("idType", Utils.keyType(fList));// 主键数据类型 54 | params.put("table", table.getT_name()); 55 | params.put("id", fList.get(0)); 56 | params.put("cond", cond); 57 | params.put("tName", table.getT_name()); 58 | params.put("idName", fList.get(0).getName()); 59 | params.put("time", date); 60 | params.put("swagger", cond.getSwagger()); 61 | params.put("importList", Utils.Import(fList)); 62 | params.put("dollar", "$"); 63 | params.put("well", "#"); 64 | 65 | params.put("insertFields", Utils.addFieldsWrap(fList, "", ",", "\");\r\n\t\tsql.append(\"", 1)); 66 | params.put("insertValues", Utils.addFieldsWrap(fList, "", "?,", "", 0)); 67 | params.put("insertParams", Utils.addFieldsWrap(fList, " vo.get", "(),", "//\r\n\t\t\t\t",2)); 68 | 69 | params.put("updateFields", Utils.addUpdateField(fList, "", "=?,", "\");\r\n\t\tsql.append(\"", 1)); 70 | params.put("updateValues", Utils.addUpdateValue(fList, " vo.get", "(),", "//\r\n\t\t\t\t",2)); 71 | 72 | params.put("selectFields", Utils.addFieldsWrap(fList, "t.", ",", "\");\r\n\t\tsql.append(\"", 1)); 73 | params.put("insertParamsBatch", Utils.addFieldsWrap(fList, ":", ",", "\");\r\n\t\tsql.append(\"", 1)); 74 | 75 | params.put("insertFieldsMybatis", Utils.addFieldsWrap(fList, "", ",", "\r\n\t\t\t", 1)); 76 | params.put("selectFieldsMybatis", Utils.addFieldsWrap(fList, "t.", ",", "\r\n\t\t\t", 1)); 77 | params.put("insertValuesMybatis", Utils.addFieldsWrap(fList, "#{", "},", "\r\n\t\t\t", 1)); 78 | 79 | params.put("model", cond.getModel()); 80 | utils.getTemplates().forEach(item -> { 81 | String[] split = item.split("/"); 82 | params.put("pName", cond.pack(split[0], low)); 83 | params.put("path", cond.path(split[0], low)); 84 | utils.process(item, params); 85 | }); 86 | 87 | } 88 | 89 | } 90 | 91 | /** 92 | * @功能描述 查询数据库中表名列表 93 | */ 94 | public List
queryTables(CodeCond para) { 95 | List
list = dao.queryTables(para); 96 | list.forEach(item -> { 97 | item.setCls_upp(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, Utils.delFirWord(item.getT_name()))); 98 | item.setC_name(item.getComment()); 99 | }); 100 | return list; 101 | } 102 | 103 | /** 104 | * @功能描述 查询数据库中字段名列表 105 | */ 106 | public List queryFields(CodeCond cond) { 107 | List list = dao.queryFields(cond); 108 | list.forEach(item -> { 109 | item.setCamel(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, item.getName())); 110 | item.setBigName(Utils.firstUpper(item.getName())); 111 | }); 112 | return list; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9090 3 | compression: 4 | enabled: true 5 | mime-types: application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css 6 | spring: 7 | freemarker: 8 | suffix: .html 9 | datasource: 10 | # driverClassName: com.mysql.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC 12 | username: root 13 | password: root 14 | application: 15 | name: jdbc-creater -------------------------------------------------------------------------------- /src/main/resources/code/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | /code.iml 2 | /encodings.xml 3 | /misc.xml 4 | /modules.xml 5 | /vcs.xml 6 | /workspace.xml 7 | -------------------------------------------------------------------------------- /src/main/resources/code/android/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | /** 4 | * @类说明 ${cName}--实体类 5 | * @auth ${auth} 6 | * @date ${time} 7 | **/ 8 | public class ${upp}{ 9 | <#list fList as fi> 10 | private ${fi.type} ${fi.name} ;// ${fi.comment} 11 | 12 | 13 | //以下为护展属性 14 | 15 | <#list fList as fi> 16 | public ${fi.type} get${fi.bigName} (){ 17 | return this.${fi.name}; 18 | } 19 | 20 | public void set${fi.bigName}(${fi.type} ${fi.name}) { 21 | this.${fi.name} = ${fi.name}; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/main/resources/code/android/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | ${importList} 4 | import com.gzz.createcode.common.base.BaseCondition; 5 | 6 | /** 7 | * @类说明 ${cName}--查询条件实体 8 | * @aut ${auth} 9 | * @date ${time} 10 | **/ 11 | public class ${upp}Cond extends BaseCondition { 12 | <#list fList as fi> 13 | private ${fi.type} ${fi.name} ;// ${fi.comment} 14 | 15 | 16 | <#list fList as fi> 17 | public ${fi.type} get${fi.bigName} (){ 18 | return this.${fi.name}; 19 | } 20 | 21 | public void set${fi.bigName}(${fi.type} ${fi.name}) { 22 | this.${fi.name} = ${fi.name}; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/resources/code/android/ModelRequest.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import com.android.volley.AuthFailureError; 10 | import com.android.volley.Response; 11 | import com.android.volley.Response.Listener; 12 | import com.android.volley.VolleyError; 13 | import com.android.volley.toolbox.JsonObjectRequest; 14 | import com.android.volley.toolbox.StringRequest; 15 | import com.google.gson.Gson; 16 | 17 | import com.cn.danceland.myapplication.MyApplication; 18 | import com.cn.danceland.myapplication.utils.Constants; 19 | import com.cn.danceland.myapplication.utils.SPUtils; 20 | import com.cn.danceland.myapplication.utils.ToastUtils; 21 | 22 | /** 23 | * @类说明 ${cName}--网络请求层 24 | * @author ${auth} 25 | * @date ${time} 26 | **/ 27 | public class ${upp}Request { 28 | 29 | /** 30 | * @方法说明 新增[${cName}]记录 31 | */ 32 | public void save(${upp} ${lowUpp}, Listener listener) { 33 | JsonObjectRequest request = new JsonObjectRequest(1, Constants.HOST + "${lowUpp}/save", new Gson().toJson(${lowUpp}), listener, new Response.ErrorListener() { 34 | public void onErrorResponse(VolleyError error) { 35 | ToastUtils.showToastShort("请检查手机网络!"); 36 | } 37 | }) { 38 | public Map getHeaders() throws AuthFailureError { 39 | HashMap map = new HashMap(); 40 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 41 | return map; 42 | } 43 | }; 44 | MyApplication.getHttpQueues().add(request); 45 | } 46 | 47 | 48 | /** 49 | * @方法说明 修改[${cName}]记录 50 | */ 51 | public void update(${upp} ${lowUpp}, Listener listener) { 52 | JsonObjectRequest request = new JsonObjectRequest(1, Constants.HOST + "${lowUpp}/update", new Gson().toJson(${lowUpp}), listener, new Response.ErrorListener() { 53 | public void onErrorResponse(VolleyError error) { 54 | ToastUtils.showToastShort("请检查手机网络!"); 55 | } 56 | }) { 57 | public Map getHeaders() throws AuthFailureError { 58 | HashMap map = new HashMap(); 59 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 60 | return map; 61 | } 62 | }; 63 | MyApplication.getHttpQueues().add(request); 64 | } 65 | 66 | /** 67 | * @方法说明 按主键删除[${cName}]记录 68 | */ 69 | public void delete(${idType} id, Listener listener) { 70 | StringRequest request = new StringRequest(1, Constants.HOST + "${lowUpp}/delete?id=" + id, listener, new Response.ErrorListener() { 71 | @Override 72 | public void onErrorResponse(VolleyError volleyError) { 73 | ToastUtils.showToastShort("请检查手机网络!"); 74 | } 75 | }) { 76 | @Override 77 | public Map getHeaders() throws AuthFailureError { 78 | HashMap map = new HashMap(); 79 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 80 | return map; 81 | } 82 | }; 83 | MyApplication.getHttpQueues().add(request); 84 | } 85 | 86 | /** 87 | * @方法说明 按条件查询[${cName}]记录 88 | */ 89 | public void queryList(${upp}Cond cond, Listener listener) { 90 | JsonObjectRequest request = new JsonObjectRequest(1, Constants.HOST + "${lowUpp}/queryList", new Gson().toJson(cond), listener, new Response.ErrorListener() { 91 | public void onErrorResponse(VolleyError error) { 92 | ToastUtils.showToastShort("请检查手机网络!"); 93 | } 94 | }) { 95 | public Map getHeaders() throws AuthFailureError { 96 | HashMap map = new HashMap(); 97 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 98 | return map; 99 | } 100 | }; 101 | MyApplication.getHttpQueues().add(request); 102 | } 103 | 104 | /** 105 | * @方法说明 按条件查询[${cName}]分页列表 106 | */ 107 | public void queryPage(${upp}Cond cond, Listener listener) { 108 | JsonObjectRequest request = new JsonObjectRequest(1, Constants.HOST + "${lowUpp}/queryPage", new Gson().toJson(cond), listener, new Response.ErrorListener() { 109 | public void onErrorResponse(VolleyError error) { 110 | ToastUtils.showToastShort("请检查手机网络!"); 111 | } 112 | }) { 113 | public Map getHeaders() throws AuthFailureError { 114 | HashMap map = new HashMap(); 115 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 116 | return map; 117 | } 118 | }; 119 | MyApplication.getHttpQueues().add(request); 120 | } 121 | 122 | /** 123 | * @方法说明 按主键查询[${cName}]单个数据 124 | */ 125 | public void findById(${idType} id, Listener listener) { 126 | StringRequest request = new StringRequest(1, Constants.HOST + "${lowUpp}/findById?id=" + id, listener, new Response.ErrorListener() { 127 | @Override 128 | public void onErrorResponse(VolleyError volleyError) { 129 | ToastUtils.showToastShort("请检查手机网络!"); 130 | } 131 | }) { 132 | @Override 133 | public Map getHeaders() throws AuthFailureError { 134 | HashMap map = new HashMap(); 135 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 136 | return map; 137 | } 138 | }; 139 | MyApplication.getHttpQueues().add(request); 140 | } 141 | 142 | /** 143 | * @方法说明 按条件查询[${cName}]数据个数 144 | */ 145 | public void queryCount(${upp}Cond cond, Listener listener) { 146 | JsonObjectRequest request = new JsonObjectRequest(1, Constants.HOST + "${lowUpp}/queryCount", new Gson().toJson(cond), listener, new Response.ErrorListener() { 147 | public void onErrorResponse(VolleyError error) { 148 | ToastUtils.showToastShort("请检查手机网络!"); 149 | } 150 | }) { 151 | public Map getHeaders() throws AuthFailureError { 152 | HashMap map = new HashMap(); 153 | map.put("Authorization", SPUtils.getString(Constants.MY_TOKEN, "")); 154 | return map; 155 | } 156 | }; 157 | MyApplication.getHttpQueues().add(request); 158 | } 159 | } -------------------------------------------------------------------------------- /src/main/resources/code/android/ModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | import java.text.SimpleDateFormat; 5 | 6 | import com.android.volley.Response; 7 | import org.json.JSONObject; 8 | import com.google.gson.Gson; 9 | import com.google.gson.GsonBuilder; 10 | import com.google.gson.reflect.TypeToken; 11 | 12 | import com.cn.danceland.myapplication.bean.DLResult; 13 | import com.cn.danceland.myapplication.bean.Page; 14 | import com.cn.danceland.myapplication.utils.ToastUtils; 15 | 16 | /** 17 | * @友情提示 请清理掉用不到的代码包括这段注释 18 | **/ 19 | /** 20 | * @类说明 ${cName}--业务逻辑 21 | * @author ${auth} 22 | * @date ${time} 23 | **/ 24 | public class ${upp}Service { 25 | private ${upp}Request request = new ${upp}Request(); 26 | private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HHmmss").create(); 27 | private SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HHmmss"); 28 | 29 | /** 30 | * @方法说明 新增[${cName}]记录 31 | */ 32 | public void save() { 33 | ${upp} ${lowUpp} = new ${upp}(); 34 | // TODO 准备数据 35 | request.save(${lowUpp}, new Response.Listener() { 36 | public void onResponse(JSONObject json) { 37 | DLResult result = gson.fromJson(json.toString(), new TypeToken>() { 38 | }.getType()); 39 | if (result.isSuccess()) { 40 | // TODO 请求据成功后的代码 41 | } else { 42 | ToastUtils.showToastShort("保存数据失败,请检查手机网络"); 43 | } 44 | } 45 | }); 46 | 47 | } 48 | 49 | /** 50 | * @方法说明 修改[${cName}]记录 51 | */ 52 | public void update() { 53 | ${upp} ${lowUpp} = new ${upp}(); 54 | // TODO 准备数据 55 | request.save(${lowUpp}, new Response.Listener() { 56 | public void onResponse(JSONObject json) { 57 | DLResult result = gson.fromJson(json.toString(), new TypeToken>() { 58 | }.getType()); 59 | if (result.isSuccess()) { 60 | // TODO 请求成功后的代码 61 | } else { 62 | ToastUtils.showToastShort("修改数据失败,请检查手机网络!"); 63 | } 64 | } 65 | }); 66 | 67 | } 68 | 69 | /** 70 | * @方法说明 按主键删除[${cName}]记录 71 | */ 72 | public void delete() { 73 | ${idType} id = null; 74 | // TODO 准备数据 75 | request.delete(id, new Response.Listener() { 76 | public void onResponse(String res) { 77 | DLResult result = gson.fromJson(res, new TypeToken>() {}.getType()); 78 | if (result.isSuccess()) { 79 | // TODO 请求成功后的代码 80 | } else { 81 | ToastUtils.showToastShort("删除数据失败,请检查手机网络!"); 82 | } 83 | } 84 | }); 85 | } 86 | 87 | /** 88 | * @方法说明 按条件查询[${cName}]列表 89 | */ 90 | public void queryList() { 91 | ${upp}Cond cond = new ${upp}Cond(); 92 | // TODO 准备查询条件 93 | request.queryList(cond, new Response.Listener() { 94 | public void onResponse(JSONObject json) { 95 | DLResult> result = gson.fromJson(json.toString(), new TypeToken>>() {}.getType()); 96 | if (result.isSuccess()) { 97 | List<${upp}> list = result.getData(); 98 | System.out.println(list); 99 | // TODO 请求成功后的代码 100 | } else { 101 | ToastUtils.showToastShort("查询分页列表失败,请检查手机网络!"); 102 | } 103 | } 104 | }); 105 | } 106 | 107 | /** 108 | * @方法说明 按条件查询[${cName}]分页列表 109 | */ 110 | public void queryPage() { 111 | ${upp}Cond cond = new ${upp}Cond(); 112 | // TODO 准备查询条件 113 | request.queryPage(cond, new Response.Listener() { 114 | public void onResponse(JSONObject json) { 115 | // LogUtil.i(json.toString()); 116 | DLResult> result = gson.fromJson(json.toString(), new TypeToken>>() {}.getType()); 117 | if (result.isSuccess()) { 118 | Page<${upp}> page = result.getData(); 119 | List<${upp}> list = page.getContent(); 120 | System.out.println(list); 121 | // TODO 查询成功后的代码 122 | } else { 123 | ToastUtils.showToastShort("查询列表失败,请检查手机网络!\"); 124 | } 125 | 126 | } 127 | }); 128 | 129 | } 130 | 131 | /** 132 | * @方法说明 按主键查询单个[${cName}] 133 | */ 134 | public void findById() { 135 | ${idType} id = null; 136 | // TODO 准备数据 137 | request.findById(id, new Response.Listener() { 138 | public void onResponse(String res) { 139 | DLResult<${upp}> result = gson.fromJson(res, new TypeToken>() {}.getType()); 140 | if (result.isSuccess()) { 141 | ${upp} ${lowUpp} = result.getData(); 142 | System.out.println("${lowUpp}"); 143 | // TODO 查询成功后的代码 144 | } else { 145 | ToastUtils.showToastShort("请检查手机网络!"); 146 | } 147 | } 148 | }); 149 | } 150 | 151 | /** 152 | * @方法说明 按条件查询[${cName}]数据个数 153 | */ 154 | public void queryCount() { 155 | ${upp}Cond cond = new ${upp}Cond(); 156 | // TODO 准备查询条件 157 | request.queryCount(cond, new Response.Listener() { 158 | public void onResponse(JSONObject json) { 159 | DLResult result = gson.fromJson(json.toString(), new TypeToken>() {}.getType()); 160 | if (result.isSuccess()) { 161 | Long count = result.getData(); 162 | System.out.println(count); 163 | // TODO 请求成功后的代码 164 | } else { 165 | ToastUtils.showToastShort("查询分页列表失败,请检查手机网络!"); 166 | } 167 | } 168 | }); 169 | } 170 | } -------------------------------------------------------------------------------- /src/main/resources/code/appcenter/IModelClient.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import com.dl.keep.common.util.Page; 8 | 9 | /** 10 | * @类说明 ${cName}--客户端类 11 | * @author ${auth} 12 | * @date ${time} 13 | **/ 14 | @FeignClient("dl-keep-web-data/${lowUpp}") 15 | public interface I${upp}Client { 16 | 17 | /** 18 | * @方法说明 新增[${cName}]记录 19 | */ 20 | @PostMapping("save") 21 | int save(@RequestBody ${upp} ${lowUpp}); 22 | 23 | /** 24 | * @方法说明 删除${cName}记录(多条) 25 | */ 26 | @PostMapping("delete") 27 | int delete(@RequestParam("ids[]") ${idType} ids[]); 28 | 29 | /** 30 | * @方法说明 修改${cName}记录 31 | */ 32 | @PostMapping("update") 33 | int update(@RequestBody ${upp} ${lowUpp}); 34 | 35 | /** 36 | * @方法说明 按条件查询分页${cName}列表 37 | */ 38 | @PostMapping("queryPage") 39 | Page<${upp}> queryPage(@RequestBody ${upp}Cond cond ); 40 | 41 | /** 42 | * @方法说明 按条件查询不分页${cName}列表 43 | */ 44 | @PostMapping("queryList") 45 | List<${upp}> queryList(@RequestBody ${upp}Cond cond ); 46 | 47 | /** 48 | * @方法说明 按主键查单个${cName}记录 49 | */ 50 | @PostMapping("findById") 51 | ${upp} findById(@RequestParam("id") ${idType} id); 52 | 53 | /** 54 | * @方法说明 按条件查询${cName}记录个数 55 | */ 56 | @PostMapping("queryCount") 57 | long queryCount(@RequestBody ${upp}Cond cond ); 58 | 59 | /** 60 | * @方法说明 按条件查询分页${cName}列表 61 | */ 62 | //@PostMapping("queryPage") 63 | //String queryPageString(@RequestBody ${upp}Cond cond ); 64 | 65 | /** 66 | * @方法说明 按条件查询不分页${cName}列表 67 | */ 68 | //@PostMapping("queryList") 69 | //String queryListString(@RequestBody ${upp}Cond cond ); 70 | 71 | /** 72 | * @方法说明 按主键查单个${cName}记录 73 | */ 74 | //@PostMapping("findById") 75 | //String findByIdString(@RequestParam("id") ${idType} id); 76 | 77 | } -------------------------------------------------------------------------------- /src/main/resources/code/appcenter/ModelAction.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.security.Principal; 4 | import java.util.List; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiImplicitParam; 14 | import io.swagger.annotations.ApiImplicitParams; 15 | import io.swagger.annotations.ApiOperation; 16 | import lombok.extern.slf4j.Slf4j; 17 | 18 | import com.dl.appcenter.common.bean.SwaggerRespImpl; 19 | import com.dl.appcenter.common.util.PrincipalAction; 20 | import com.dl.keep.common.domain.app.${upp}; 21 | import com.dl.keep.common.domain.app.${upp}Cond; 22 | import com.dl.keep.common.util.MessageInfo; 23 | import com.dl.keep.common.util.Page; 24 | import com.gzz.createcode.mvc.dao.CodeDao; 25 | 26 | /** 27 | * @类说明 [${cName}]app端Swagger控制器类 28 | * @author ${auth} 29 | * @date ${time} 30 | **/ 31 | @Api(value = "[${cName}]控制器", description = "[${cName}]相关操作") 32 | @RestController 33 | @RequestMapping("${lowUpp}") 34 | @Slf4j 35 | public class ${upp}Action extends PrincipalAction { 36 | 37 | @Autowired 38 | private ${upp}Bus bus; //注入[${cName}]业务逻辑类 39 | 40 | /** 41 | * @方法说明 新增[${cName}]记录 42 | */ 43 | @ApiOperation(value = "新增[${cName}]", notes = "返回影响记录行数") 44 | @ApiImplicitParams({ 45 | <#list fList as fi> 46 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = true), 47 | 48 | @ApiImplicitParam(name = "Authorization", value = "Token",required = false, dataType = "string", paramType = "header") 49 | }) 50 | @ApiResponses({ 51 | @ApiResponse(code = 0, message = "操作成功") 52 | }) 53 | @PostMapping("save") 54 | public SwaggerRespImpl save(${upp} ${lowUpp}, Principal principal) { 55 | return new SwaggerRespImpl<>(bus.save(${lowUpp})); 56 | } 57 | 58 | 59 | /** 60 | * @方法说明 删除[${cName}]记录 61 | */ 62 | @ApiOperation(value = "删除[${cName}]", notes = "返回影响记录行数") 63 | @PostMapping( "delete" ) 64 | public SwaggerRespImpl delete(@RequestParam("id") ${idType} id) { 65 | return new SwaggerRespImpl<>(bus.delete(new ${idType}[] { id })); 66 | } 67 | 68 | /** 69 | * @方法说明 修改[${cName}]记录 70 | */ 71 | @ApiOperation(value = "修改[${cName}]", notes = "返回影响记录行数") 72 | @ApiImplicitParams( { 73 | <#list fList as fi> 74 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = false), 75 | 76 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") 77 | }) 78 | @PostMapping("update") 79 | public SwaggerRespImpl update(${upp} ${lowUpp}, Principal principal) { 80 | return new SwaggerRespImpl<>(bus.update(${lowUpp})); 81 | } 82 | 83 | /** 84 | * @方法说明 按条件查询分页[${cName}]列表 85 | */ 86 | @ApiOperation(value = "按条件查询分页[${cName}]列表", notes = "返回分页[${cName}]列表") 87 | @ApiImplicitParams({ 88 | <#list fList as fi> 89 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = false), 90 | 91 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") 92 | }) 93 | @PostMapping( "queryPage") 94 | public SwaggerRespImpl> queryPage(${upp}Cond cond, Principal principal) { 95 | // cond.setBranch_id(getSessionBranchId(principal)); 96 | return new SwaggerRespImpl<>(bus.queryPage(cond)); 97 | } 98 | 99 | /** 100 | * @方法说明 按条件查询不分页[${cName}]列表 101 | */ 102 | @ApiOperation(value = "按条件查询不分页[${cName}]列表", notes = "返回不分页[${cName}]列表") 103 | @ApiImplicitParams({ 104 | <#list fList as fi> 105 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = false), 106 | 107 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") 108 | }) 109 | @PostMapping("queryList") 110 | public SwaggerRespImpl> queryList(${upp}Cond cond, Principal principal) { 111 | // cond.setBranch_id(getSessionBranchId(principal)); 112 | return new SwaggerRespImpl<>(bus.queryList(cond)); 113 | } 114 | 115 | /** 116 | * @方法说明 按条件查询[${cName}]记录个数 117 | */ 118 | @ApiOperation(value = "按条件查询[${cName}]记录个数", notes = "返回记录个数") 119 | @ApiImplicitParams({ 120 | <#list fList as fi> 121 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = false), 122 | 123 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") 124 | }) 125 | @PostMapping( "queryCount") 126 | public SwaggerRespImpl queryCount(${upp}Cond cond) { 127 | return new SwaggerRespImpl<>(bus.queryCount(cond)); 128 | } 129 | 130 | /** 131 | * @方法说明 按主键查询单条[${cName}]记录 132 | */ 133 | @ApiOperation(value = "按主键查询单个[${cName}]记录", notes = "返回单个[${cName}]对象") 134 | @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "[${cName}]的主键", required = true, dataType = "${idType}", paramType = "query"), 135 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") }) 136 | @PostMapping( "findById") 137 | public SwaggerRespImpl<${upp}> findById(@RequestParam("id") ${idType} id) { 138 | return new SwaggerRespImpl<>(bus.findById(id)); 139 | } 140 | 141 | /** 142 | * @方法说明 验证方法 143 | */ 144 | @ApiOperation(value = "按条件验证方法[${cName}]相关相信息", notes = "返回验证结果") 145 | @ApiImplicitParams( { 146 | <#list fList as fi> 147 | @ApiImplicitParam(name = "${fi.name}", value = "${fi.comment}", paramType = "query", dataType="${fi.type}", required = false), 148 | 149 | @ApiImplicitParam(name = "Authorization", value = "Token",required = true, dataType = "string", paramType = "header") 150 | }) 151 | @PostMapping( "validate") 152 | public SwaggerRespImpl validate(${upp}Cond cond, Principal principal) { 153 | // 此处写验证逻辑 154 | // cond.setfield(...) 155 | // int count=bus.queryCount(cond) 156 | // if(count = 0){ 157 | // } 158 | return new SwaggerRespImpl<>(1); 159 | } 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/main/resources/code/appcenter/ModelBus.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | import java.util.stream.Collectors; 4 | import com.dl.keep.common.util.Page; 5 | import com.gzz.createcode.mvc.dao.CodeDao; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import com.alibaba.fastjson.JSON; 10 | import com.alibaba.fastjson.JSONObject; 11 | /** 12 | * @类说明 ${cName}--业务逻辑层 13 | * @author ${auth} 14 | * @date ${time} 15 | **/ 16 | @Service 17 | @Slf4j 18 | public class ${upp}Bus { 19 | 20 | @Autowired 21 | private I${upp}Client client; //注入${cName}客户端类 22 | 23 | /** 24 | * @方法说明 新增[${cName}]记录 25 | */ 26 | public int save(${upp} ${lowUpp}) { 27 | return client.save(${lowUpp}); 28 | } 29 | 30 | /** 31 | * @方法说明 删除${cName}记录(多条) 32 | */ 33 | public int delete(${idType} ids[]) { 34 | return client.delete(ids);//物理删除 35 | } 36 | 37 | /** 38 | * @方法说明 更新${cName}记录 39 | */ 40 | public int update(${upp} ${lowUpp}) { 41 | return client.update(${lowUpp}); 42 | } 43 | 44 | /** 45 | * @方法说明 按条件查询分页${cName}列表 46 | */ 47 | public Page<${upp}> queryPage(${upp}Cond cond) { 48 | return client.queryPage(cond); 49 | } 50 | 51 | /** 52 | * @方法说明 按条件查询不分页${cName}列表 53 | */ 54 | public List<${upp}> queryList(${upp}Cond cond) { 55 | return client.queryList(cond); 56 | } 57 | 58 | /** 59 | * @方法说明 按条件查询${cName}记录个数 60 | */ 61 | public long queryCount(${upp}Cond cond) { 62 | return client.queryCount(cond); 63 | } 64 | 65 | /** 66 | * @方法说明按主键查找单个${cName}记录 67 | */ 68 | public ${upp} findById(${idType} id) { 69 | return client.findById(id); 70 | } 71 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/MockMvcTestModel.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; 4 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 6 | 7 | import org.assertj.core.util.Arrays; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.http.MediaType; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | import org.springframework.test.web.servlet.MockMvc; 16 | //import org.springframework.test.web.servlet.MvcResult; 17 | import com.fasterxml.jackson.databind.ObjectMapper; 18 | import lombok.extern.slf4j.Slf4j; 19 | /** 20 | * @类说明 【${cName}】测试工具,将本类移到maven测试目录中或测试完成之后删除 21 | * @author 高振中 22 | * @date 2019-01-12 22:40:08 23 | **/ 24 | @Slf4j 25 | @SpringBootTest 26 | @AutoConfigureMockMvc 27 | @RunWith(SpringRunner.class) 28 | public class MockMvcTest${upp} { 29 | @Autowired 30 | private MockMvc mvc; 31 | @Autowired 32 | private ObjectMapper mapper; 33 | /** 34 | * @方法说明 测试 新增【${cName}】记录,根据数据类型修改每个字段的值 35 | */ 36 | //@Test 37 | public void save() throws Exception { 38 | ${upp} ${lowUpp} = ${upp}.builder() 39 | <#list fList as fi> 40 | //.${fi.name}("gaozz") // 设置【${fi.comment}】的值 41 | 42 | .build(); 43 | log.info(doRequest("/${lowUpp}/save", ${lowUpp})); 44 | } 45 | /** 46 | * @方法说明 测试 查询【${cName}】列表,条件可以为空,可直接运行 47 | */ 48 | @Test 49 | public void queryList() throws Exception { 50 | ${upp}Cond cond = ${upp}Cond.builder()//拼查询条件 51 | <#list fList as fi> 52 | //.${fi.name}("gaozz") // 【${fi.comment}】值 53 | 54 | .build(); 55 | log.info(doRequest("/${lowUpp}/list", cond)); 56 | } 57 | /** 58 | * @方法说明 测试 查询【${cName}】分页列表,条件可以为空,可直接运行 59 | */ 60 | @Test 61 | public void queryPage() throws Exception { 62 | ${upp}Cond cond = ${upp}Cond.builder()//拼查询条件 63 | <#list fList as fi> 64 | //.${fi.name}("gaozz") // 【${fi.comment}】值 65 | 66 | .ids(Arrays.asList(new Object[]{1,2,3,4})) 67 | .build(); 68 | cond.setPage(0); //当前页 69 | cond.setSize(10); //页大小 70 | log.info(doRequest("/${lowUpp}/page", cond)); 71 | } 72 | 73 | private String doRequest(String url, T t) throws Exception {// restController专用测试方法 74 | return mvc.perform(post(url).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(t))).andExpect(status().isOk()) 75 | .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString(); 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.NoArgsConstructor; 8 | <#if swagger == 1> 9 | import io.swagger.annotations.ApiModel; 10 | import io.swagger.annotations.ApiModelProperty; 11 | 12 | /** 13 | * @类说明 【${cName}】实体 14 | * @author ${auth} 15 | * @date ${time} 16 | **/ 17 | @Setter 18 | @Getter 19 | //@Accessors(chain = true) 20 | @Builder 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | <#if swagger == 1> 24 | @ApiModel(description = "【${cName}】实体") 25 | 26 | public class ${upp} { 27 | // @NotNull(message = "客户主建(Id)不能为空(数值型)") 28 | // @NotEmpty(message = "客户名称(name)不能为空(字符型)") 29 | // @Length(max = 20, min = 10, message = "客户名称(name)长度在有10~20之间(字符型)") 30 | // @Max(value = 1000, message = "客户年龄(age)最大值是1000(数值型)") 31 | // @Min(value = 100, message = "客户年龄(age)最小值是100(数值型)") 32 | // @Pattern(regexp = "^\\d{10}$", message = "必须为10位数字(字符型[正规判断])") 33 | // 以下为数据库中 字段 34 | <#list fList as fi> 35 | <#if swagger == 1> 36 | @ApiModelProperty("${fi.comment}") 37 | 38 | private ${fi.type} ${fi.name}; // ${fi.comment} 39 | 40 | // 以下为查询显示辅助属性 41 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import java.util.List; 4 | 5 | import com.gzz.common.base.BaseCondition; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Builder; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | <#if swagger == 1> 13 | import io.swagger.annotations.ApiModel; 14 | import io.swagger.annotations.ApiModelProperty; 15 | 16 | 17 | /** 18 | * @类说明 【${cName}】查询条件 19 | * @author ${auth} 20 | * @date ${time} 21 | **/ 22 | @Setter 23 | @Getter 24 | //@Accessors(chain = true) 25 | @Builder 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | <#if swagger == 1> 29 | @ApiModel(description = "【${cName}】查询条件") 30 | 31 | public class ${upp}Cond extends BaseCondition { 32 | 33 | /** 34 | * @方法说明: 拼加自定义条件 35 | **/ 36 | @Override 37 | public void addCondition() { 38 | <#list fList as fi> 39 | <#if fi.type == "String"> 40 | add("AND t.${fi.name} LIKE ?", ${fi.name}, 3); 41 | <#else> 42 | add("AND t.${fi.name} = ?", ${fi.name}); 43 | 44 | 45 | add("AND t.id IN", ids); 46 | } 47 | 48 | // 以下为查询条件 49 | <#list fList as fi> 50 | <#if swagger == 1> 51 | @ApiModelProperty("${fi.comment}") 52 | 53 | private ${fi.type} ${fi.name}; // ${fi.comment} 54 | 55 | <#if swagger == 1> 56 | @ApiModelProperty("主键数组") 57 | 58 | private List ids;// 主键列表 59 | // 以下为自定义查询条件 60 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/ModelController.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.validation.annotation.Validated; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.gzz.common.base.Page; 14 | import com.gzz.common.config.Result; 15 | 16 | import io.swagger.annotations.Api; 17 | import io.swagger.annotations.ApiOperation; 18 | 19 | /** 20 | * @类说明 【${cName}】控制器 21 | * @author ${auth} 22 | * @date ${time} 23 | **/ 24 | //@Slf4j 25 | @RestController 26 | @RequestMapping("${lowUpp}") 27 | @Api(tags = "【${cName}】API") 28 | public class ${upp}Controller { 29 | 30 | @Autowired 31 | private ${upp}Service ${lowUpp}Service; // 注入【${cName}】业务逻辑层 32 | 33 | /** 34 | * @方法说明 新增【${cName}】记录 35 | */ 36 | @PostMapping("save") 37 | @ApiOperation(value = "新增【${cName}】记录") 38 | public Result save(@RequestBody @Validated ${upp} ${lowUpp}) { 39 | return Result.success(${lowUpp}Service.save(${lowUpp})); 40 | } 41 | 42 | /** 43 | * @方法说明 删除【${cName}】记录 44 | */ 45 | @PostMapping("delete") 46 | @ApiOperation(value = "删除【${cName}】记录") 47 | public Result delete(${idType}[] ids) { 48 | return Result.success(${lowUpp}Service.delete(ids)); 49 | } 50 | 51 | /** 52 | * @方法说明 修改【${cName}】记录 53 | */ 54 | @PostMapping("update") 55 | @ApiOperation(value = "修改【${cName}】记录") 56 | public Result update(@RequestBody @Validated ${upp} ${lowUpp}) { 57 | return Result.success(${lowUpp}Service.update(${lowUpp})); 58 | } 59 | 60 | /** 61 | * @方法说明 按条件查询分页【${cName}】列表 62 | */ 63 | @PostMapping("page") 64 | @ApiOperation(value = "按条件查询分页【${cName}】列表") 65 | public Result> page(@RequestBody ${upp}Cond cond) { 66 | return Result.success(${lowUpp}Service.page(cond)); 67 | } 68 | 69 | /** 70 | * @方法说明 按条件查询【${cName}】列表 71 | */ 72 | @PostMapping("list") 73 | @ApiOperation(value = "按条件查询不分页【${cName}】列表") 74 | public Result> list(@RequestBody ${upp}Cond cond) { 75 | return Result.success(${lowUpp}Service.list(cond)); 76 | } 77 | 78 | /** 79 | * @方法说明 按主键查单个【${cName}】记录 80 | */ 81 | @PostMapping("findById") 82 | @ApiOperation(value = "按主键查单个【${cName}】记录") 83 | public Result<${upp}> findById(@RequestParam("id") ${idType} id) { 84 | return Result.success(${lowUpp}Service.findById(id)); 85 | } 86 | 87 | /** 88 | * @方法说明 按条件查询【${cName}】记录个数 89 | */ 90 | @PostMapping("count") 91 | @ApiOperation(value = "【${cName}】记录个数") 92 | public Result count(@RequestBody ${upp}Cond cond) { 93 | return Result.success(${lowUpp}Service.count(cond)); 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/ModelDao.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.gzz.common.base.BaseDao; 9 | import com.gzz.common.base.Page; 10 | 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * @类说明 【${cName}】数据访问层 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @Slf4j 19 | @Repository 20 | public class ${upp}Dao extends BaseDao { 21 | 22 | /** 23 | * @方法说明 新增【${cName}】记录 24 | */ 25 | public int save(${upp} vo) { 26 | StringBuilder sql = new StringBuilder(); 27 | sql.append("INSERT INTO ${tName} (${insertFields})"); 28 | sql.append(" VALUES (${insertValues})"); 29 | Object[] params = {${insertParams} }; 30 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 31 | return jdbcTemplate.update(sql.toString(), params); 32 | } 33 | 34 | /** 35 | * @方法说明 删除【${cName}】记录 36 | */ 37 | public int delete(Object[] ids) { 38 | String sql = "DELETE FROM ${tName} WHERE ${idName} IN" + toIn(ids); 39 | // log.info(super.sql(sql, ids));// 显示SQL语句 40 | return jdbcTemplate.update(sql, ids); 41 | } 42 | 43 | /** 44 | * @方法说明 更新【${cName}】记录 45 | */ 46 | public int update(${upp} vo) { 47 | StringBuilder sql = new StringBuilder(); 48 | sql.append("UPDATE ${tName} SET ${updateFields}"); 49 | sql.append(" WHERE ${idName}=? "); 50 | Object[] params = {${updateValues} }; 51 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 52 | return jdbcTemplate.update(sql.toString(), params); 53 | } 54 | 55 | /** 56 | * @方法说明 按条件查询分页【${cName}】列表 57 | */ 58 | public Page<${upp}> page(${upp}Cond cond) { 59 | StringBuilder sql = new StringBuilder(); 60 | sql.append("SELECT ${selectFields}"); 61 | sql.append(" FROM ${tName} t"); 62 | sql.append(cond.where()); 63 | log.info(super.sql(sql.toString(), cond.array()));// 显示SQL语句 64 | return queryPage(sql.toString(), cond, ${upp}.class); 65 | } 66 | 67 | /** 68 | * @方法说明 按条件查询【${cName}】列表 69 | */ 70 | public List<${upp}> list(${upp}Cond cond) { 71 | StringBuilder sql = new StringBuilder(); 72 | sql.append("SELECT ${selectFields}"); 73 | sql.append(" FROM ${tName} t"); 74 | sql.append(cond.where()); 75 | sql.append(" ORDER BY ${idName} DESC"); 76 | // log.info(super.sql(sql.toString(),cond.array()));//显示SQL语句 77 | return jdbcTemplate.query(sql.toString(), cond.array(), new BeanPropertyRowMapper<>(${upp}.class)); 78 | } 79 | 80 | /** 81 | * @方法说明 按主键查找单个【${cName}】记录 82 | */ 83 | public ${upp} findById(${idType} id) { 84 | StringBuilder sql = new StringBuilder(); 85 | sql.append("SELECT ${selectFields}"); 86 | sql.append(" FROM ${tName} t WHERE t.${idName}=?"); 87 | // log.info(super.sql(sql.toString(),id));//显示SQL语句 88 | return jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(${upp}.class), id); 89 | } 90 | 91 | /** 92 | * @方法说明 按条件查询【${cName}】记录个数 93 | */ 94 | public int count(${upp}Cond cond) { 95 | String sql = "SELECT COUNT(1) FROM ${tName} t " + cond.where(); 96 | // log.info(super.sql(sql,cond.array()));//显示SQL语句 97 | return jdbcTemplate.queryForObject(sql, cond.array(), Integer.class); 98 | } 99 | 100 | /** 101 | * @方法说明 新增【${cName}】记录并返回自增涨主键值 102 | */ 103 | public int saveReturnPK(${upp} vo) { 104 | StringBuilder sql = new StringBuilder(); 105 | sql.append("INSERT INTO ${tName} (${insertFields})"); 106 | sql.append(" VALUES (${insertParamsBatch})"); 107 | // log.info(super.sqlp(sql.toString(), vo));// 显示SQL语句 108 | return saveKey(vo, sql.toString(), "${idName}"); 109 | } 110 | 111 | /** 112 | * @方法说明 批量插入【${cName}】记录 113 | */ 114 | public int[] insertBatch(List<${upp}> list) { 115 | StringBuilder sql = new StringBuilder(); 116 | sql.append("INSERT INTO ${tName} (${insertFields})"); 117 | sql.append(" VALUES (${insertParamsBatch})"); 118 | // log.info(super.sqlp(sql.toString(), list));// 显示SQL语句 119 | return batchOperate(list, sql.toString()); 120 | } 121 | 122 | /** 123 | * @方法说明 逻辑删除【${cName}】记录 124 | */ 125 | // public int delete(Object... ids) { 126 | // String sql = "UPDATE ${tName} SET dr=1 WHERE ${idName} IN " + toIn(ids); 127 | // return jdbcTemplate.update(sql,ids); 128 | // } 129 | 130 | } -------------------------------------------------------------------------------- /src/main/resources/code/boot/ModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.gzz.common.base.Page; 8 | 9 | /** 10 | * @类说明 【${cName}】业务逻辑层 11 | * @author ${auth} 12 | * @date ${time} 13 | **/ 14 | //@Slf4j 15 | @Service 16 | public class ${upp}Service { 17 | 18 | @Autowired 19 | private ${upp}Dao ${lowUpp}Dao; // 注入【${cName}】数据访问层 20 | 21 | /** 22 | * @方法说明 新增【${cName}】记录 23 | */ 24 | // @Transactional 25 | public int save(${upp} ${lowUpp}) { 26 | return ${lowUpp}Dao.save(${lowUpp}); 27 | } 28 | 29 | /** 30 | * @方法说明 删除【${cName}】记录 31 | */ 32 | public int delete(${idType}[] ids) { 33 | return ${lowUpp}Dao.delete(ids); 34 | } 35 | 36 | /** 37 | * @方法说明 更新【${cName}】记录 38 | */ 39 | public int update(${upp} ${lowUpp}) { 40 | return ${lowUpp}Dao.update(${lowUpp}); 41 | } 42 | 43 | /** 44 | * @方法说明 按条件查询分页【${cName}】列表 45 | */ 46 | public Page<${upp}> page(${upp}Cond cond) { 47 | return ${lowUpp}Dao.page(cond); 48 | } 49 | 50 | /** 51 | * @方法说明 按条件查询【${cName}】列表 52 | */ 53 | public List<${upp}> list(${upp}Cond cond) { 54 | return ${lowUpp}Dao.list(cond); 55 | } 56 | 57 | /** 58 | * @方法说明 按主键查找单个【${cName}】记录 59 | */ 60 | public ${upp} findById(${idType} id) { 61 | return ${lowUpp}Dao.findById(id); 62 | } 63 | 64 | /** 65 | * @方法说明 按条件查询【${cName}】记录个数 66 | */ 67 | public int count(${upp}Cond cond) { 68 | return ${lowUpp}Dao.count(cond); 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/resources/code/common/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.NoArgsConstructor; 8 | //import lombok.experimental.Accessors; 9 | <#if swagger == 1> 10 | import io.swagger.annotations.ApiModel; 11 | import io.swagger.annotations.ApiModelProperty; 12 | 13 | /** 14 | * @类说明 [${cName}]实体类 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @Setter 19 | @Getter 20 | //@Accessors(chain = true) 21 | @Builder 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | <#if swagger == 1> 25 | @ApiModel(value = "${upp}", description = "${cName}实体") 26 | 27 | public class ${upp} { 28 | // 数据库中的字段 29 | <#list fList as fi> 30 | <#if swagger == 1> 31 | @ApiModelProperty(value = "${fi.comment}", dataType = "${fi.type}") 32 | 33 | private ${fi.type} ${fi.name}; // ${fi.comment} 34 | 35 | // 此处可添加查询显示辅助字段 36 | } -------------------------------------------------------------------------------- /src/main/resources/code/common/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.NoArgsConstructor; 8 | //import lombok.experimental.Accessors; 9 | import com.gzz.createcode.common.base.BaseCondition; 10 | <#if swagger == 1> 11 | import io.swagger.annotations.ApiModel; 12 | import io.swagger.annotations.ApiModelProperty; 13 | 14 | /** 15 | * @类说明 [${cName}]查询条件实体 16 | * @author: ${auth} 17 | * @date : ${time} 18 | **/ 19 | @Setter 20 | @Getter 21 | //@Accessors(chain = true) 22 | @Builder 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | <#if swagger == 1> 26 | @ApiModel(value = "${upp}Cond", description = "${cName}查询条件实体") 27 | 28 | public class ${upp}Cond extends BaseCondition { 29 | 30 | /** 31 | * @方法说明: 拼加自定义条件 32 | **/ 33 | @Override 34 | public void addCondition() { 35 | <#list fList as fi> 36 | <#if fi.type == "String"> 37 | // add(${fi.name}, "AND t.${fi.name} LIKE ?", 3); 38 | <#else> 39 | // add(${fi.name}, "AND t.${fi.name} = ?"); 40 | 41 | 42 | // add(ids, "AND t.id IN "); 43 | } 44 | 45 | // 查询条件 46 | <#list fList as fi> 47 | <#if swagger == 1> 48 | // @ApiModelProperty(hidden = true) 49 | 50 | // private ${fi.type} ${fi.name}; // ${fi.comment} 51 | 52 | // private List ids;// 主键列表 53 | } -------------------------------------------------------------------------------- /src/main/resources/code/element-list/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.NoArgsConstructor; 8 | <#if swagger == 1> 9 | import io.swagger.annotations.ApiModel; 10 | import io.swagger.annotations.ApiModelProperty; 11 | 12 | /** 13 | * @类说明 【${cName}】实体 14 | * @author ${auth} 15 | * @date ${time} 16 | **/ 17 | @Setter 18 | @Getter 19 | //@Accessors(chain = true) 20 | @Builder 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | <#if swagger == 1> 24 | @ApiModel(description = "【${cName}】实体") 25 | 26 | public class ${upp} { 27 | // 以下为数据库中 字段 28 | <#list fList as fi> 29 | <#if swagger == 1> 30 | @ApiModelProperty("${fi.comment}") 31 | 32 | private ${fi.type} ${fi.name}; // ${fi.comment} 33 | 34 | // 以下为查询显示辅助属性 35 | } -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import java.util.List; 4 | 5 | import com.gzz.common.base.BaseCondition; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Builder; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | <#if swagger == 1> 13 | import io.swagger.annotations.ApiModel; 14 | import io.swagger.annotations.ApiModelProperty; 15 | 16 | 17 | /** 18 | * @类说明 【${cName}】查询条件 19 | * @author ${auth} 20 | * @date ${time} 21 | **/ 22 | @Setter 23 | @Getter 24 | //@Accessors(chain = true) 25 | @Builder 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | <#if swagger == 1> 29 | @ApiModel(description = "【${cName}】查询条件") 30 | 31 | public class ${upp}Cond extends BaseCondition { 32 | 33 | /** 34 | * @方法说明: 拼加自定义条件 35 | **/ 36 | @Override 37 | public void addCondition() { 38 | <#list fList as fi> 39 | <#if fi.type == "String"> 40 | add("AND t.${fi.name} LIKE ?", ${fi.name}, 3); 41 | <#else> 42 | add("AND t.${fi.name} = ?", ${fi.name}); 43 | 44 | 45 | add("AND t.id IN", ids); 46 | } 47 | 48 | // 以下为查询条件 49 | <#list fList as fi> 50 | <#if swagger == 1> 51 | @ApiModelProperty("${fi.comment}") 52 | 53 | private ${fi.type} ${fi.name}; // ${fi.comment} 54 | 55 | <#if swagger == 1> 56 | @ApiModelProperty("主键数组") 57 | 58 | private List ids;// 主键列表 59 | // 以下为自定义查询条件 60 | } -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelController.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.validation.annotation.Validated; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.gzz.common.base.Page; 14 | import com.gzz.common.config.Result; 15 | 16 | import io.swagger.annotations.Api; 17 | import io.swagger.annotations.ApiOperation; 18 | 19 | /** 20 | * @类说明 【${cName}】控制器 21 | * @author ${auth} 22 | * @date ${time} 23 | **/ 24 | //@Slf4j 25 | @RestController 26 | @RequestMapping("${lowUpp}") 27 | @Api(tags = "【${cName}】API") 28 | public class ${upp}Controller { 29 | 30 | @Autowired 31 | private ${upp}Service ${lowUpp}Service; // 注入【${cName}】业务逻辑层 32 | 33 | /** 34 | * @方法说明 新增【${cName}】记录 35 | */ 36 | @PostMapping("save") 37 | @ApiOperation(value = "新增【${cName}】记录") 38 | public Result save(@RequestBody @Validated ${upp} ${lowUpp}) { 39 | return Result.success(${lowUpp}Service.save(${lowUpp})); 40 | } 41 | 42 | /** 43 | * @方法说明 删除【${cName}】记录 44 | */ 45 | @PostMapping("delete") 46 | @ApiOperation(value = "删除【${cName}】记录") 47 | public Result delete(@RequestBody List<${idType}> ids) { 48 | return Result.success(${lowUpp}Service.delete(ids)); 49 | } 50 | 51 | /** 52 | * @方法说明 修改【${cName}】记录 53 | */ 54 | @PostMapping("update") 55 | @ApiOperation(value = "修改【${cName}】记录") 56 | public Result update(@RequestBody @Validated ${upp} ${lowUpp}) { 57 | return Result.success(${lowUpp}Service.update(${lowUpp})); 58 | } 59 | 60 | /** 61 | * @方法说明 按条件查询分页【${cName}】列表 62 | */ 63 | @PostMapping("page") 64 | @ApiOperation(value = "按条件查询分页【${cName}】列表") 65 | public Result> page(@RequestBody ${upp}Cond cond) { 66 | return Result.success(${lowUpp}Service.page(cond)); 67 | } 68 | 69 | /** 70 | * @方法说明 按条件查询【${cName}】列表 71 | */ 72 | @PostMapping("list") 73 | @ApiOperation(value = "按条件查询不分页【${cName}】列表") 74 | public Result> list(@RequestBody ${upp}Cond cond) { 75 | return Result.success(${lowUpp}Service.list(cond)); 76 | } 77 | 78 | /** 79 | * @方法说明 按主键查单个【${cName}】记录 80 | */ 81 | @PostMapping("findById") 82 | @ApiOperation(value = "按主键查单个【${cName}】记录") 83 | public Result<${upp}> findById(@RequestParam("id") ${idType} id) { 84 | return Result.success(${lowUpp}Service.findById(id)); 85 | } 86 | 87 | /** 88 | * @方法说明 按条件查询【${cName}】记录个数 89 | */ 90 | @PostMapping("count") 91 | @ApiOperation(value = "【${cName}】记录个数") 92 | public Result count(@RequestBody ${upp}Cond cond) { 93 | return Result.success(${lowUpp}Service.count(cond)); 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelDao.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.gzz.common.base.BaseDao; 9 | import com.gzz.common.base.Page; 10 | 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * @类说明 【${cName}】数据访问层 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @Slf4j 19 | @Repository 20 | public class ${upp}Dao extends BaseDao { 21 | 22 | /** 23 | * @方法说明 新增【${cName}】记录 24 | */ 25 | public int save(${upp} vo) { 26 | StringBuilder sql = new StringBuilder(); 27 | sql.append("INSERT INTO ${tName} (${insertFields})"); 28 | sql.append(" VALUES (${insertValues})"); 29 | Object[] params = {${insertParams} }; 30 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 31 | return jdbcTemplate.update(sql.toString(), params); 32 | } 33 | 34 | /** 35 | * @方法说明 删除【${cName}】记录 36 | */ 37 | public int delete(List<${idType}> ids) { 38 | String sql = "DELETE FROM ${tName} WHERE ${idName} IN" + toIn(ids); 39 | // log.info(super.sql(sql, ids));// 显示SQL语句 40 | return jdbcTemplate.update(sql, ids.toArray()); 41 | } 42 | 43 | /** 44 | * @方法说明 更新【${cName}】记录 45 | */ 46 | public int update(${upp} vo) { 47 | StringBuilder sql = new StringBuilder(); 48 | sql.append("UPDATE ${tName} SET ${updateFields}"); 49 | sql.append(" WHERE ${idName}=? "); 50 | Object[] params = {${updateValues} }; 51 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 52 | return jdbcTemplate.update(sql.toString(), params); 53 | } 54 | 55 | /** 56 | * @方法说明 按条件查询分页【${cName}】列表 57 | */ 58 | public Page<${upp}> page(${upp}Cond cond) { 59 | StringBuilder sql = new StringBuilder(); 60 | sql.append("SELECT ${selectFields}"); 61 | sql.append(" FROM ${tName} t"); 62 | sql.append(cond.where()); 63 | log.info(super.sql(sql.toString(), cond.array()));// 显示SQL语句 64 | return queryPage(sql.toString(), cond, ${upp}.class); 65 | } 66 | 67 | /** 68 | * @方法说明 按条件查询【${cName}】列表 69 | */ 70 | public List<${upp}> list(${upp}Cond cond) { 71 | StringBuilder sql = new StringBuilder(); 72 | sql.append("SELECT ${selectFields}"); 73 | sql.append(" FROM ${tName} t"); 74 | sql.append(cond.where()); 75 | sql.append(" ORDER BY ${idName} DESC"); 76 | // log.info(super.sql(sql.toString(),cond.array()));//显示SQL语句 77 | return jdbcTemplate.query(sql.toString(), cond.array(), new BeanPropertyRowMapper<>(${upp}.class)); 78 | } 79 | 80 | /** 81 | * @方法说明 按主键查找单个【${cName}】记录 82 | */ 83 | public ${upp} findById(${idType} id) { 84 | StringBuilder sql = new StringBuilder(); 85 | sql.append("SELECT ${selectFields}"); 86 | sql.append(" FROM ${tName} t WHERE t.${idName}=?"); 87 | // log.info(super.sql(sql.toString(),id));//显示SQL语句 88 | return jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(${upp}.class), id); 89 | } 90 | 91 | /** 92 | * @方法说明 按条件查询【${cName}】记录个数 93 | */ 94 | public int count(${upp}Cond cond) { 95 | String sql = "SELECT COUNT(1) FROM ${tName} t " + cond.where(); 96 | // log.info(super.sql(sql,cond.array()));//显示SQL语句 97 | return jdbcTemplate.queryForObject(sql, cond.array(), Integer.class); 98 | } 99 | 100 | /** 101 | * @方法说明 新增【${cName}】记录并返回自增涨主键值 102 | */ 103 | public int saveReturnPK(${upp} vo) { 104 | StringBuilder sql = new StringBuilder(); 105 | sql.append("INSERT INTO ${tName} (${insertFields})"); 106 | sql.append(" VALUES (${insertParamsBatch})"); 107 | // log.info(super.sqlp(sql.toString(), vo));// 显示SQL语句 108 | return saveKey(vo, sql.toString(), "${idName}"); 109 | } 110 | 111 | /** 112 | * @方法说明 批量插入【${cName}】记录 113 | */ 114 | public int[] insertBatch(List<${upp}> list) { 115 | StringBuilder sql = new StringBuilder(); 116 | sql.append("INSERT INTO ${tName} (${insertFields})"); 117 | sql.append(" VALUES (${insertParamsBatch})"); 118 | // log.info(super.sqlp(sql.toString(), list));// 显示SQL语句 119 | return batchOperate(list, sql.toString()); 120 | } 121 | 122 | /** 123 | * @方法说明 逻辑删除【${cName}】记录 124 | */ 125 | // public int delete(Object... ids) { 126 | // String sql = "UPDATE ${tName} SET dr=1 WHERE ${idName} IN " + toIn(ids); 127 | // return jdbcTemplate.update(sql,ids); 128 | // } 129 | 130 | } -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelDialog.vue: -------------------------------------------------------------------------------- 1 | /*${cName}新增与修改,作者:${auth},日期:${time}*/ 2 | 23 | 86 | 87 | -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelList.vue: -------------------------------------------------------------------------------- 1 | /*${cName}管理,作者:${auth},日期:${time}*/ 2 | 59 | 125 | 126 | -------------------------------------------------------------------------------- /src/main/resources/code/element-list/ModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.gzz.common.base.Page; 8 | 9 | /** 10 | * @类说明 【${cName}】业务逻辑层 11 | * @author ${auth} 12 | * @date ${time} 13 | **/ 14 | //@Slf4j 15 | @Service 16 | public class ${upp}Service { 17 | 18 | @Autowired 19 | private ${upp}Dao ${lowUpp}Dao; // 注入【${cName}】数据访问层 20 | 21 | /** 22 | * @方法说明 新增【${cName}】记录 23 | */ 24 | // @Transactional 25 | public int save(${upp} ${lowUpp}) { 26 | return ${lowUpp}Dao.save(${lowUpp}); 27 | } 28 | 29 | /** 30 | * @方法说明 删除【${cName}】记录 31 | */ 32 | public int delete(List<${idType}> ids) { 33 | return ${lowUpp}Dao.delete(ids); 34 | } 35 | 36 | /** 37 | * @方法说明 更新【${cName}】记录 38 | */ 39 | public int update(${upp} ${lowUpp}) { 40 | return ${lowUpp}Dao.update(${lowUpp}); 41 | } 42 | 43 | /** 44 | * @方法说明 按条件查询分页【${cName}】列表 45 | */ 46 | public Page<${upp}> page(${upp}Cond cond) { 47 | return ${lowUpp}Dao.page(cond); 48 | } 49 | 50 | /** 51 | * @方法说明 按条件查询【${cName}】列表 52 | */ 53 | public List<${upp}> list(${upp}Cond cond) { 54 | return ${lowUpp}Dao.list(cond); 55 | } 56 | 57 | /** 58 | * @方法说明 按主键查找单个【${cName}】记录 59 | */ 60 | public ${upp} findById(${idType} id) { 61 | return ${lowUpp}Dao.findById(id); 62 | } 63 | 64 | /** 65 | * @方法说明 按条件查询【${cName}】记录个数 66 | */ 67 | public int count(${upp}Cond cond) { 68 | return ${lowUpp}Dao.count(cond); 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/IModelMapper.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | /** 7 | * @类说明 【${cName}】数据访问层 8 | * @author ${auth} 9 | * @date ${time} 10 | **/ 11 | @Mapper 12 | public interface I${upp}Mapper extends BaseMapper<${upp}> { 13 | 14 | // /** 15 | // * @方法说明 自义联表查询 16 | // **/ 17 | // IPage<${upp}> queryPage(IPage<${upp}> page, ${upp} param); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/IModelMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <#list fList as fi> 7 | <#if fi_index == 0> 8 | 9 | 10 | <#if fi_index != 0> 11 | 12 | 13 | 14 | 15 | 16 | 27 | 28 | 29 | INSERT INTO ${tName} 30 | (${insertFieldsMybatis}) 31 | VALUES 32 | (${insertValuesMybatis}) 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/IModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | 5 | /** 6 | * @类说明 【${cName}】业务逻辑接口 7 | * @author ${auth} 8 | * @date ${time} 9 | **/ 10 | public interface I${upp}Service extends IService<${upp}> { 11 | 12 | // /** 13 | // * @方法说明 自定义联表查询 14 | // **/ 15 | // IPage<${upp}> queryPage(IPage<${upp}> page, ${upp} param); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | 9 | import lombok.AllArgsConstructor; 10 | import lombok.Builder; 11 | import lombok.Getter; 12 | import lombok.NoArgsConstructor; 13 | import lombok.Setter; 14 | /** 15 | * @类说明 【${cName}】实体类 16 | * @author ${auth} 17 | * @date ${time} 18 | **/ 19 | @Setter 20 | @Getter 21 | @Builder 22 | @TableName(value = "${tName}") 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class ${upp} extends Model<${upp}> { 26 | private static final long serialVersionUID = 1L; 27 | // @NotNull(message = "客户主建(Id)不能为空(数值型)") 28 | // @NotEmpty(message = "客户名称(name)不能为空(字符型)") 29 | // @Length(max = 20, min = 10, message = "客户名称(name)长度在有10~20之间(字符型)") 30 | // @Max(value = 1000, message = "客户年龄(age)最大值是1000(数值型)") 31 | // @Min(value = 100, message = "客户年龄(age)最小值是100(数值型)") 32 | // @Pattern(regexp = "^\\d{10}$", message = "必须为10位数字(字符型)") 33 | <#list fList as fi> 34 | <#if fi_index == 0> 35 | @TableId(value = "${fi.name}", type = IdType.AUTO) 36 | private ${fi.type} ${fi.name}; /* -${fi.comment} */ 37 | 38 | <#if fi_index != 0> 39 | private ${fi.type} ${fi.name}; /* -${fi.comment} */ 40 | 41 | 42 | } -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import com.gzz.common.util.BaseCondition; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.NoArgsConstructor; 9 | import lombok.experimental.Accessors; 10 | 11 | /** 12 | * @类说明 【${cName}】DTO对象 13 | * @author ${auth} 14 | * @date ${time} 15 | **/ 16 | @Setter 17 | @Getter 18 | @Accessors(chain = true) 19 | @Builder 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public class ${upp}Cond extends BaseCondition { 23 | <#list fList as fi> 24 | private ${fi.type} ${fi.name};/* -${fi.comment} */ 25 | 26 | } -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/ModelController.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.beans.BeanUtils; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 13 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 14 | import com.baomidou.mybatisplus.core.metadata.IPage; 15 | import com.gzz.common.util.Result; 16 | 17 | import io.swagger.annotations.Api; 18 | import io.swagger.annotations.ApiOperation; 19 | 20 | /** 21 | * @类说明 【${cName}】控制器 22 | * @author ${auth} 23 | * @date ${time} 24 | **/ 25 | @Api(tags = "${cName}接口") 26 | @RestController 27 | @RequestMapping("${low}") 28 | public class ${upp}Controller { 29 | 30 | @Autowired 31 | private I${upp}Service ${lowUpp}Service;//注入【${cName}】业务逻辑接口 32 | 33 | /** 34 | * @方法说明 新增【${cName}】记录 35 | */ 36 | @PostMapping("add") 37 | @ApiOperation(value = "新增【${cName}】记录") 38 | public Result add(@RequestBody @Valid ${upp} ${lowUpp}) { 39 | return Result.success(${lowUpp}Service.save(${lowUpp})); 40 | } 41 | 42 | /** 43 | * @方法说明 按主键删除【${cName}】记录 44 | */ 45 | @PostMapping("delete") 46 | @ApiOperation(value = "按主键删除【${cName}】记录") 47 | public Result delete(Integer id) { 48 | return Result.success(${lowUpp}Service.removeById(id)); 49 | } 50 | 51 | /** 52 | * @方法说明 修改【${cName}】记录 53 | */ 54 | @PostMapping("edit") 55 | @ApiOperation(value = "修改【${cName}】记录") 56 | public Result edit(@RequestBody @Valid ${upp} ${lowUpp}) { 57 | return Result.success(${lowUpp}Service.updateById(${lowUpp})); 58 | } 59 | 60 | /** 61 | * @方法说明 按条件查询分页【${cName}】列表 62 | */ 63 | @PostMapping("page") 64 | @ApiOperation(value = "按条件查询分页【${cName}】列表") 65 | public Result> page(@RequestBody ${upp}Cond cond) { 66 | ${upp} ${lowUpp}= new ${upp}(); 67 | BeanUtils.copyProperties(cond, ${lowUpp}); 68 | return Result.success(${lowUpp}Service.page(new Page<${upp}>(cond.getPage(),cond.getSize()), new QueryWrapper<${upp}>(${lowUpp}))); 69 | } 70 | 71 | /** 72 | * @方法说明 按主键查单个【${cName}】记录 73 | */ 74 | @PostMapping("findById") 75 | @ApiOperation(value = "按主键查单个【${cName}】记录") 76 | public Result<${upp}> get(Integer id) { 77 | return Result.success(${lowUpp}Service.getById(id)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/resources/code/mybatisplus/ModelServiceImpl.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * @类说明 【${cName}】业务逻辑实现 9 | * @author ${auth} 10 | * @date ${time} 11 | **/ 12 | //@Slf4j 13 | @Service 14 | public class ${upp}ServiceImpl extends ServiceImpl implements I${upp}Service { 15 | // @Autowired 16 | // private I${upp}Mapper ${lowUpp}Mapper;//注入【${cName}】数据访问接口 17 | // 18 | // /** 19 | // * @方法说明 自定义联表查询 20 | // **/ 21 | // @Override 22 | // public IPage<${upp}> queryPage(IPage<${upp}> page, ${upp} param){ 23 | // return ${lowUpp}Mapper.queryPage(page,param); 24 | // } 25 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/Model.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import java.util.List; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.NoArgsConstructor; 9 | <#if swagger == 1> 10 | import io.swagger.annotations.ApiModel; 11 | import io.swagger.annotations.ApiModelProperty; 12 | 13 | /** 14 | * @类说明 【${cName}】实体 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @Setter 19 | @Getter 20 | @Builder 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | <#if swagger == 1> 24 | @ApiModel(description = "【${cName}】实体") 25 | 26 | public class ${upp} { 27 | // 以下为数据库中 字段 28 | <#list fList as fi> 29 | <#if swagger == 1> 30 | @ApiModelProperty("${fi.comment}") 31 | 32 | private ${fi.type} ${fi.name}; // ${fi.comment} 33 | 34 | // 以下为查询显示辅助属性 35 | private List<${upp}> children ; 36 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelCond.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | ${importList} 3 | import java.util.List; 4 | 5 | import com.gzz.common.base.BaseCondition; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Builder; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | <#if swagger == 1> 13 | import io.swagger.annotations.ApiModel; 14 | import io.swagger.annotations.ApiModelProperty; 15 | 16 | 17 | /** 18 | * @类说明 【${cName}】查询条件 19 | * @author ${auth} 20 | * @date ${time} 21 | **/ 22 | @Setter 23 | @Getter 24 | //@Accessors(chain = true) 25 | @Builder 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | <#if swagger == 1> 29 | @ApiModel(description = "【${cName}】查询条件") 30 | 31 | public class ${upp}Cond extends BaseCondition { 32 | 33 | /** 34 | * @方法说明: 拼加自定义条件 35 | **/ 36 | @Override 37 | public void addCondition() { 38 | <#list fList as fi> 39 | <#if fi.type == "String"> 40 | add("AND t.${fi.name} LIKE ?", ${fi.name}, 3); 41 | <#else> 42 | add("AND t.${fi.name} = ?", ${fi.name}); 43 | 44 | 45 | add("AND t.id IN", ids); 46 | } 47 | 48 | // 以下为查询条件 49 | <#list fList as fi> 50 | <#if swagger == 1> 51 | @ApiModelProperty("${fi.comment}") 52 | 53 | private ${fi.type} ${fi.name}; // ${fi.comment} 54 | 55 | <#if swagger == 1> 56 | @ApiModelProperty("主键数组") 57 | 58 | private List ids;// 主键列表 59 | // 以下为自定义查询条件 60 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelController.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.validation.annotation.Validated; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import com.gzz.common.config.Result; 12 | 13 | import io.swagger.annotations.Api; 14 | import io.swagger.annotations.ApiOperation; 15 | 16 | /** 17 | * @类说明 【${cName}】控制器 18 | * @author ${auth} 19 | * @date ${time} 20 | **/ 21 | //@Slf4j 22 | @RestController 23 | @RequestMapping("${lowUpp}") 24 | @Api(tags = "【${cName}】API") 25 | public class ${upp}Controller { 26 | 27 | @Autowired 28 | private ${upp}Service ${lowUpp}Service; // 注入【${cName}】业务逻辑层 29 | 30 | /** 31 | * @方法说明 新增【${cName}】记录 32 | */ 33 | @PostMapping("save") 34 | @ApiOperation(value = "新增【${cName}】记录") 35 | public Result save(@RequestBody @Validated ${upp} ${lowUpp}) { 36 | return Result.success(${lowUpp}Service.save(${lowUpp})); 37 | } 38 | 39 | /** 40 | * @方法说明 删除【${cName}】记录 41 | */ 42 | @PostMapping("delete") 43 | @ApiOperation(value = "删除【${cName}】记录") 44 | public Result delete(@RequestBody List<${idType}> ids) { 45 | return Result.success(${lowUpp}Service.delete(ids)); 46 | } 47 | 48 | /** 49 | * @方法说明 修改【${cName}】记录 50 | */ 51 | @PostMapping("update") 52 | @ApiOperation(value = "修改【${cName}】记录") 53 | public Result update(@RequestBody @Validated ${upp} ${lowUpp}) { 54 | return Result.success(${lowUpp}Service.update(${lowUpp})); 55 | } 56 | 57 | 58 | /** 59 | * @方法说明 按条件查询【${cName}】列表 60 | */ 61 | @PostMapping("list") 62 | @ApiOperation(value = "按条件查询不分页【${cName}】列表") 63 | public Result> list(@RequestBody ${upp}Cond cond) { 64 | return Result.success(${lowUpp}Service.list(cond)); 65 | } 66 | 67 | /** 68 | * @方法说明 按条件查询【${cName}】树 69 | */ 70 | @PostMapping("tree") 71 | @ApiOperation(value = " 按条件查询【${cName}】树") 72 | public Result> tree() { 73 | return Result.success(${lowUpp}Service.tree()); 74 | } 75 | 76 | // /** 77 | // * @方法说明 按主键查单个【${cName}】记录 78 | // */ 79 | // @PostMapping("findById") 80 | // @ApiOperation(value = "按主键查单个【${cName}】记录") 81 | // public Result<${upp}> findById(@RequestParam("id") ${idType} id) { 82 | // return Result.success(${lowUpp}Service.findById(id)); 83 | // } 84 | 85 | /** 86 | * @方法说明 按条件查询【${cName}】记录个数 87 | */ 88 | @PostMapping("count") 89 | @ApiOperation(value = "【${cName}】记录个数") 90 | public Result count(@RequestBody ${upp}Cond cond) { 91 | return Result.success(${lowUpp}Service.count(cond)); 92 | } 93 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelDao.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.gzz.common.base.BaseDao; 9 | 10 | /** 11 | * @类说明 【${cName}】数据访问层 12 | * @author ${auth} 13 | * @date ${time} 14 | **/ 15 | //@Slf4j 16 | @Repository 17 | public class ${upp}Dao extends BaseDao { 18 | 19 | /** 20 | * @方法说明 新增【${cName}】记录 21 | */ 22 | public int save(${upp} vo) { 23 | StringBuilder sql = new StringBuilder(); 24 | sql.append("INSERT INTO ${tName} (${insertFields})"); 25 | sql.append(" VALUES (${insertValues})"); 26 | Object[] params = {${insertParams} }; 27 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 28 | return jdbcTemplate.update(sql.toString(), params); 29 | } 30 | 31 | /** 32 | * @方法说明 删除【${cName}】记录 33 | */ 34 | public int delete(List<${idType}> ids) { 35 | String sql = "DELETE FROM ${tName} WHERE ${idName} IN" + toIn(ids); 36 | // log.info(super.sql(sql, ids));// 显示SQL语句 37 | return jdbcTemplate.update(sql, ids.toArray()); 38 | } 39 | 40 | /** 41 | * @方法说明 更新【${cName}】记录 42 | */ 43 | public int update(${upp} vo) { 44 | StringBuilder sql = new StringBuilder(); 45 | sql.append("UPDATE ${tName} SET ${updateFields}"); 46 | sql.append(" WHERE ${idName}=? "); 47 | Object[] params = {${updateValues} }; 48 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 49 | return jdbcTemplate.update(sql.toString(), params); 50 | } 51 | 52 | /** 53 | * @方法说明 按条件查询【${cName}】列表 54 | */ 55 | public List<${upp}> list(${upp}Cond cond) { 56 | StringBuilder sql = new StringBuilder(); 57 | sql.append("SELECT ${selectFields}"); 58 | sql.append(" FROM ${tName} t"); 59 | sql.append(cond.where()); 60 | sql.append(" ORDER BY ${idName}"); 61 | // log.info(super.sql(sql.toString(),cond.array()));//显示SQL语句 62 | return jdbcTemplate.query(sql.toString(), cond.array(), new BeanPropertyRowMapper<>(${upp}.class)); 63 | } 64 | 65 | /** 66 | * @方法说明 按条件查询【${cName}】记录个数 67 | */ 68 | public int count(${upp}Cond cond) { 69 | String sql = "SELECT COUNT(1) FROM ${tName} t " + cond.where(); 70 | // log.info(super.sql(sql,cond.array()));//显示SQL语句 71 | return jdbcTemplate.queryForObject(sql, cond.array(), Integer.class); 72 | } 73 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelDialog.vue: -------------------------------------------------------------------------------- 1 | /*${cName}新增与修改,作者:${auth},日期:${time}*/ 2 | 23 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.google.common.collect.Lists; 11 | 12 | 13 | /** 14 | * @类说明 【${cName}】业务逻辑层 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | //@Slf4j 19 | @Service 20 | public class ${upp}Service { 21 | 22 | @Autowired 23 | private ${upp}Dao ${lowUpp}Dao; // 注入【${cName}】数据访问层 24 | 25 | /** 26 | * @方法说明 新增【${cName}】记录 27 | */ 28 | // @Transactional 29 | public int save(${upp} ${lowUpp}) { 30 | return ${lowUpp}Dao.save(${lowUpp}); 31 | } 32 | 33 | /** 34 | * @方法说明 删除【${cName}】记录 35 | */ 36 | public int delete(List<${idType}> ids) { 37 | return ${lowUpp}Dao.delete(ids); 38 | } 39 | 40 | /** 41 | * @方法说明 更新【${cName}】记录 42 | */ 43 | public int update(${upp} ${lowUpp}) { 44 | return ${lowUpp}Dao.update(${lowUpp}); 45 | } 46 | 47 | /** 48 | * @方法说明 按条件查询【${cName}】列表 49 | */ 50 | public List<${upp}> list(${upp}Cond cond) { 51 | return ${lowUpp}Dao.list(cond); 52 | } 53 | 54 | /** 55 | * @方法说明 按条件查询【${cName}】记录个数 56 | */ 57 | public int count(${upp}Cond cond) { 58 | return ${lowUpp}Dao.count(cond); 59 | } 60 | /** 61 | * @方法说明 查询【功能】树 62 | */ 63 | public List<${upp}> tree() { 64 | List<${upp}> ${lowUpp}s = ${lowUpp}Dao.list(${upp}Cond.builder().build()); 65 | Map treeMap = new HashMap<>(); 66 | List<${upp}> treeList = Lists.newArrayList(); 67 | for (${upp} ${lowUpp} : ${lowUpp}s) { 68 | treeMap.put(${lowUpp}.getId(), ${lowUpp}); 69 | if (${lowUpp}.getParentId() == 0) { 70 | treeList.add(${lowUpp}); 71 | } else { 72 | if (treeMap.get(${lowUpp}.getParentId()).getChildren() == null) 73 | treeMap.get(${lowUpp}.getParentId()).setChildren(Lists.newArrayList()); 74 | treeMap.get(${lowUpp}.getParentId()).getChildren().add(${lowUpp});// children 75 | } 76 | } 77 | treeMap.clear(); 78 | return treeList; 79 | } 80 | } -------------------------------------------------------------------------------- /src/main/resources/code/tree/ModelTree.vue: -------------------------------------------------------------------------------- 1 | /*${cName}管理,作者:${auth},日期:${time}*/ 2 | 32 | 97 | -------------------------------------------------------------------------------- /src/main/resources/code/vue_element_ui/ModelDialog.vue: -------------------------------------------------------------------------------- 1 | /*${cName}新增与修改,作者:${auth},日期:${time}*/ 2 | 21 | 78 | 79 | -------------------------------------------------------------------------------- /src/main/resources/code/vue_element_ui/ModelList.vue: -------------------------------------------------------------------------------- 1 | /*${cName}管理,作者:${auth},日期:${time}*/ 2 | 52 | 116 | 117 | -------------------------------------------------------------------------------- /src/main/resources/code/vue_element_ui/ModelMock.js: -------------------------------------------------------------------------------- 1 | /*${cName}模拟数据},作者:${auth},日期:${time}*/ 2 | 'use strict'; 3 | var Mock = require('mockjs') 4 | var Random = Mock.Random; 5 | module.exports = { 6 | 7 | 'POST /api/${lowUpp}/queryPage': function (req, res, next) { 8 | var data = Mock.mock({ 9 | "content|10": [{ 10 | <#list fList as fi> 11 | <#if fi.type == "String"> 12 | ${fi.name} : "@word(5,10)",// ${fi.comment} 13 | <#else> 14 | ${fi.name}: "@integer(100,200)",//${fi.comment} 15 | 16 | 17 | }], 18 | number: '@integer(100,200)', 19 | size: 10, 20 | totalElements: 500, 21 | }); 22 | setTimeout(function () { 23 | res.json(data); 24 | }, 500); 25 | }, 26 | 27 | 'POST /api/${lowUpp}/update': function (req, res, next) { 28 | setTimeout(function () { 29 | res.json({}); 30 | }, 500); 31 | }, 32 | 33 | 'POST /api/${lowUpp}/save': function (req, res, next) { 34 | setTimeout(function () { 35 | res.json({}); 36 | }, 500); 37 | }, 38 | 39 | 'POST /api/${lowUpp}/queryList': function (req, res, next) { 40 | var data = Mock.mock({ 41 | "content|10": [{ 42 | <#list fList as fi> 43 | <#if fi.type == "String"> 44 | ${fi.name} : "@word(5,10)",// ${fi.comment} 45 | <#else> 46 | ${fi.name}: "@integer(100,200)",//${fi.comment} 47 | 48 | 49 | }] 50 | }); 51 | setTimeout(function () { 52 | res.json(data.content); 53 | }, 500); 54 | }, 55 | 56 | 'POST /api/${lowUpp}/delete': function (req, res, next) { 57 | setTimeout(function () { 58 | res.json({}); 59 | }, 500); 60 | }, 61 | } -------------------------------------------------------------------------------- /src/main/resources/code/vue_iview_ui/ModelDialog.vue: -------------------------------------------------------------------------------- 1 | /*${cName}新增与修改,作者:${auth},日期:${time}*/ 2 | 19 | 78 | 79 | -------------------------------------------------------------------------------- /src/main/resources/code/vue_iview_ui/ModelList.vue: -------------------------------------------------------------------------------- 1 | /*${cName}列表管理,作者:${auth},日期:${time}*/ 2 | 24 | 130 | 131 | -------------------------------------------------------------------------------- /src/main/resources/code/vue_iview_ui/ModelListExpand.vue: -------------------------------------------------------------------------------- 1 | /*${cName}列表扩展,作者:${auth},日期:${time}*/ 2 | 14 | 19 | 29 | -------------------------------------------------------------------------------- /src/main/resources/code/vuex_iview_ui/Model.js: -------------------------------------------------------------------------------- 1 | import http from '../../../utils/http'; 2 | import {Message, Modal} from 'iview'; 3 | //初始数据 4 | const initForm = { 5 | <#list fList as fi> 6 | ${fi.name}:null, //${fi.comment} 7 | 8 | }; 9 | //模型 10 | export default { 11 | state: { 12 | //分页列表 13 | total: 0, 14 | page: 1, 15 | dataList: [], 16 | loading: false, 17 | searchForm: { 18 | <#list fList as fi> 19 | ${fi.name}:null, //${fi.comment} 20 | 21 | }, 22 | //新增与修改 23 | form: {...initForm}, 24 | 25 | title: '', 26 | dialogMode: "save", 27 | show: false, 28 | }, 29 | getters: {}, 30 | mutations: { 31 | ['${lowUpp}/refresh'](state){ 32 | state.loading = true; 33 | const requestData = {...state.searchForm, page: state.page - 1}; 34 | http.post("/api/${lowUpp}/queryPage", JSON.stringify(requestData)).then(res => { 35 | state.loading = false; 36 | state.dataList = res.data.content; 37 | state.total = res.data.totalElements; 38 | }).catch(res => { 39 | Message.error({ 40 | content: "获取${cName}列表失败:" + res 41 | }); 42 | state.loading = false; 43 | }); 44 | }, 45 | ["${lowUpp}/addDialog"](state){ 46 | state.title = "新增${cName}"; 47 | state.dialogMode = "save"; 48 | state.form = {...initForm}; 49 | state.show = true; 50 | }, 51 | ["${lowUpp}/editDialog"](state, row){ 52 | state.title = "修改${cName}"; 53 | state.dialogMode = "update"; 54 | state.form = {...row}; 55 | state.show = true; 56 | }, 57 | ["${lowUpp}/showDialog"](state, show){ 58 | state.show = show; 59 | }, 60 | ["${lowUpp}/setPage"](state, page){ 61 | state.page = page; 62 | }, 63 | }, 64 | actions: { 65 | ["${lowUpp}/deleteAction"]({state, dispatch, commit}, row){ 66 | Modal.confirm({ 67 | title: '提示', 68 | content: '您确定要删除吗?', 69 | closable:true, 70 | onOk: () => { 71 | http.delete("/api/${lowUpp}/delete", { 72 | params: {ids: [row.${idName}]} 73 | }).then(res => { 74 | Message.success({ 75 | content: "删除成功" 76 | }); 77 | commit("${lowUpp}/refresh"); 78 | }).catch(res => { 79 | Message.error({ 80 | content: "删除失败:" + res 81 | }); 82 | }); 83 | }, 84 | onCancel: () => { 85 | 86 | } 87 | }); 88 | }, 89 | ['${lowUpp}/save']({state, dispatch, commit}){ 90 | http.post("/api/${lowUpp}/" + state.dialogMode, JSON.stringify(state.form)).then(res => { 91 | commit("${lowUpp}/refresh"); 92 | commit("${lowUpp}/showDialog", false); 93 | }).catch(res => { 94 | Message.error({ 95 | content: '保存${cName}信息失败' + res 96 | }); 97 | }) 98 | }, 99 | } 100 | }; 101 | 102 | -------------------------------------------------------------------------------- /src/main/resources/code/vuex_iview_ui/ModelDialog.vue: -------------------------------------------------------------------------------- 1 | /*${cName}新增与修改},作者:${auth},日期:${time}*/ 2 | 19 | 65 | -------------------------------------------------------------------------------- /src/main/resources/code/vuex_iview_ui/ModelList.vue: -------------------------------------------------------------------------------- 1 | /*${cName}管理,作者:${auth},日期:${time}*/ 2 | 24 | 107 | 108 | -------------------------------------------------------------------------------- /src/main/resources/code/vuex_iview_ui/ModelListExpand.vue: -------------------------------------------------------------------------------- 1 | 13 | 18 | 28 | -------------------------------------------------------------------------------- /src/main/resources/code/vuex_iview_ui/ModelRouter.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import ${upp} from '../pages/${model}/${low}/${upp}'; 4 | Vue.use(Vuex) 5 | export default new Vuex.Store({ 6 | modules: { 7 | ${lowUpp}: ${upp}, 8 | } 9 | }) 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/code/webcenter/IModelClient.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import com.dl.keep.common.util.Page; 8 | 9 | /** 10 | * @类说明 ${cName}--客户端类 11 | * @author ${auth} 12 | * @date ${time} 13 | **/ 14 | @FeignClient("dl-keep-web-data/${lowUpp}") 15 | public interface I${upp}Client { 16 | 17 | /** 18 | * @方法说明 新增[${cName}]记录 19 | */ 20 | @PostMapping("save") 21 | int save(@RequestBody ${upp} ${lowUpp}); 22 | 23 | /** 24 | * @方法说明 删除${cName}记录(多条) 25 | */ 26 | @PostMapping("delete") 27 | int delete(@RequestParam("ids[]") ${idType} ids[]); 28 | 29 | /** 30 | * @方法说明 修改${cName}记录 31 | */ 32 | @PostMapping("update") 33 | int update(@RequestBody ${upp} ${lowUpp}); 34 | 35 | /** 36 | * @方法说明 按条件查询分页${cName}列表 37 | */ 38 | @PostMapping("queryPage") 39 | Page<${upp}> queryPage(@RequestBody ${upp}Cond cond ); 40 | 41 | /** 42 | * @方法说明 按条件查询不分页${cName}列表 43 | */ 44 | @PostMapping("queryList") 45 | List<${upp}> queryList(@RequestBody ${upp}Cond cond ); 46 | 47 | /** 48 | * @方法说明 按主键查单个${cName}记录 49 | */ 50 | @PostMapping("findById") 51 | ${upp} findById(@RequestParam("id") ${idType} id); 52 | 53 | /** 54 | * @方法说明 按条件查询${cName}记录个数 55 | */ 56 | @PostMapping("queryCount") 57 | long queryCount(@RequestBody ${upp}Cond cond ); 58 | 59 | /** 60 | * @方法说明 按条件查询分页${cName}列表 61 | */ 62 | //@PostMapping("queryPage") 63 | //String queryPageString(@RequestBody ${upp}Cond cond ); 64 | 65 | /** 66 | * @方法说明 按条件查询不分页${cName}列表 67 | */ 68 | //@PostMapping("queryList") 69 | //String queryListString(@RequestBody ${upp}Cond cond ); 70 | 71 | /** 72 | * @方法说明 按主键查单个${cName}记录 73 | */ 74 | //@PostMapping("findById") 75 | //String findByIdString(@RequestParam("id") ${idType} id); 76 | 77 | } -------------------------------------------------------------------------------- /src/main/resources/code/webcenter/ModelAction.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.DeleteMapping; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import java.security.Principal; 11 | import com.dl.webcenter.common.controller.PrincipalAction; 12 | import com.gzz.createcode.mvc.dao.CodeDao; 13 | import lombok.extern.slf4j.Slf4j; 14 | import com.dl.keep.common.util.MessageInfo; 15 | import com.dl.keep.common.util.Page; 16 | /** 17 | * @类说明 ${cName}--前端控制器层 18 | * @author ${auth} 19 | * @date ${time} 20 | **/ 21 | @RestController 22 | @RequestMapping("api/${lowUpp}") 23 | @Slf4j 24 | public class ${upp}Action extends PrincipalAction { 25 | 26 | @Autowired 27 | private ${upp}Bus bus; //${cName}Business层 28 | 29 | /** 30 | * @方法说明 新增[${cName}]记录 31 | */ 32 | @PostMapping("save") 33 | public int save(@RequestBody ${upp} ${lowUpp}, Principal principal) { 34 | return bus.save(${lowUpp}); 35 | } 36 | 37 | /** 38 | * @方法说明 删除${cName}记录(多条) 39 | */ 40 | @DeleteMapping("delete") 41 | public int delete(@RequestParam("ids[]") ${idType} ids[]) { 42 | return bus.delete(ids); 43 | } 44 | 45 | /** 46 | * @方法说明 修改${cName}记录 47 | */ 48 | @PostMapping("update") 49 | public int update(@RequestBody ${upp} ${lowUpp}, Principal principal) { 50 | return bus.update(${lowUpp}); 51 | } 52 | 53 | /** 54 | * @方法说明 按条件查询分页${cName}列表 55 | */ 56 | @PostMapping("queryPage") 57 | public Page<${upp}> queryPage(@RequestBody ${upp}Cond cond, Principal principal){ 58 | //cond.setBranch_id(getDefaultBranchId(principal)); 59 | return bus.queryPage(cond); 60 | } 61 | 62 | /** 63 | * @方法说明 按条件查询不分页${cName}列表 64 | */ 65 | @PostMapping("queryList") 66 | public List<${upp}> queryList(@RequestBody ${upp}Cond cond, Principal principal){ 67 | //cond.setBranch_id(getDefaultBranchId(principal)); 68 | return bus.queryList(cond); 69 | } 70 | 71 | /** 72 | * @方法说明 按主键查找单个${cName}记录 73 | */ 74 | @GetMapping("findById") 75 | public ${upp} findById(@RequestParam("id") ${idType} id) { 76 | return bus.findById(id); 77 | } 78 | 79 | /** 80 | * @方法说明 按条件查询${cName}记录个数 81 | */ 82 | @PostMapping("queryCount") 83 | public long queryCount(@RequestBody ${upp}Cond cond){ 84 | return bus.queryCount(cond); 85 | } 86 | 87 | /** 88 | * @方法说明 新增[${cName}]记录 89 | */ 90 | //@PostMapping("validate") 91 | //public MessageInfo validate(@RequestBody ${upp}Cond cond, Principal principal) { 92 | //MessageInfo mi = new MessageInfo(); 93 | ////此处写验证逻辑 94 | ////cond.setfield(...) 95 | ////int count=bus.queryCount(cond) 96 | ////if(count = 0){ 97 | ////mi.setMessage(1, "记录个数不能为0!\ 98 | ////} 99 | //return mi; 100 | //} 101 | } -------------------------------------------------------------------------------- /src/main/resources/code/webcenter/ModelBus.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | import java.util.List; 3 | import java.util.stream.Collectors; 4 | import com.dl.keep.common.util.Page; 5 | import com.gzz.createcode.mvc.dao.CodeDao; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import com.alibaba.fastjson.JSON; 10 | import com.alibaba.fastjson.JSONObject; 11 | /** 12 | * @类说明 ${cName}--业务逻辑层 13 | * @author ${auth} 14 | * @date ${time} 15 | **/ 16 | @Service 17 | @Slf4j 18 | public class ${upp}Bus { 19 | 20 | @Autowired 21 | private I${upp}Client client; //注入${cName}客户端类 22 | 23 | /** 24 | * @方法说明 新增[${cName}]记录 25 | */ 26 | public int save(${upp} ${lowUpp}) { 27 | return client.save(${lowUpp}); 28 | } 29 | 30 | /** 31 | * @方法说明 删除${cName}记录(多条) 32 | */ 33 | public int delete(${idType} ids[]) { 34 | return client.delete(ids);//物理删除 35 | } 36 | 37 | /** 38 | * @方法说明 更新${cName}记录 39 | */ 40 | public int update(${upp} ${lowUpp}) { 41 | return client.update(${lowUpp}); 42 | } 43 | 44 | /** 45 | * @方法说明 按条件查询分页${cName}列表 46 | */ 47 | public Page<${upp}> queryPage(${upp}Cond cond) { 48 | return client.queryPage(cond); 49 | } 50 | 51 | /** 52 | * @方法说明 按条件查询不分页${cName}列表 53 | */ 54 | public List<${upp}> queryList(${upp}Cond cond) { 55 | return client.queryList(cond); 56 | } 57 | 58 | /** 59 | * @方法说明 按条件查询${cName}记录个数 60 | */ 61 | public long queryCount(${upp}Cond cond) { 62 | return client.queryCount(cond); 63 | } 64 | 65 | /** 66 | * @方法说明按主键查找单个${cName}记录 67 | */ 68 | public ${upp} findById(${idType} id) { 69 | return client.findById(id); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/resources/code/webdata/ModelController.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | //import java.util.List; 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.DeleteMapping; 8 | //import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import com.gzz.common.base.Page; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * @类说明 [${cName}]控制器 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @RestController 19 | @RequestMapping("${lowUpp}") 20 | @Slf4j 21 | public class ${upp}Controller { 22 | 23 | @Autowired 24 | private ${upp}Service service; //注入${cName}业务逻辑层 25 | 26 | /** 27 | * @方法说明 新增[${cName}]记录 28 | */ 29 | @PostMapping("save") 30 | public int save(@RequestBody ${upp} ${lowUpp}) { 31 | return service.save(${lowUpp}); 32 | } 33 | 34 | /** 35 | * @方法说明 删除${cName}记录(多条) 36 | */ 37 | @DeleteMapping("delete") 38 | public int delete( ${idType} ids[]) { 39 | return service.delete(ids); 40 | } 41 | 42 | /** 43 | * @方法说明 修改${cName}记录 44 | */ 45 | @PostMapping("update") 46 | public int update(@RequestBody ${upp} ${lowUpp}) { 47 | return service.update(${lowUpp}); 48 | } 49 | 50 | /** 51 | * @方法说明 按条件查询分页${cName}列表 52 | */ 53 | @PostMapping("queryPage") 54 | public Page<${upp}> queryPage(@RequestBody ${upp}Cond cond ){ 55 | return service.queryPage(cond); 56 | } 57 | 58 | /** 59 | * @方法说明 按条件查询不分页${cName}列表 60 | */ 61 | // @PostMapping("queryList") 62 | // public List<${upp}> queryList(@RequestBody ${upp}Cond cond ){ 63 | // return service.queryList(cond); 64 | // } 65 | 66 | /** 67 | * @方法说明 按主键查单个${cName}记录 68 | */ 69 | // @PostMapping("findById") 70 | // public ${upp} findById(@RequestParam("id") ${idType} id) { 71 | // return service.findById(id); 72 | // } 73 | 74 | /** 75 | * @方法说明 按条件查询${cName}记录个数 76 | */ 77 | // @PostMapping("queryCount") 78 | // public long queryCount(@RequestBody ${upp}Cond cond ){ 79 | // return service.queryCount(cond); 80 | // } 81 | } -------------------------------------------------------------------------------- /src/main/resources/code/webdata/ModelDao.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.gzz.common.base.BaseDao; 9 | import com.gzz.common.base.Page; 10 | 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * @类说明 【${cName}】数据访问层 15 | * @author ${auth} 16 | * @date ${time} 17 | **/ 18 | @Slf4j 19 | @Repository 20 | public class ${upp}Dao extends BaseDao { 21 | 22 | /** 23 | * @方法说明 新增【${cName}】记录 24 | */ 25 | public int save(${upp} vo) { 26 | StringBuilder sql = new StringBuilder(); 27 | sql.append("INSERT INTO ${tName} (${insertFields})"); 28 | sql.append(" VALUES (${insertValues})"); 29 | Object[] params = {${insertParams} }; 30 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 31 | return jdbcTemplate.update(sql.toString(), params); 32 | } 33 | 34 | /** 35 | * @方法说明 删除【${cName}】记录 36 | */ 37 | public int delete(Object[] ids) { 38 | String sql = "DELETE FROM ${tName} WHERE ${idName} IN" + toIn(ids); 39 | // log.info(super.sql(sql, ids));// 显示SQL语句 40 | return jdbcTemplate.update(sql, ids); 41 | } 42 | 43 | /** 44 | * @方法说明 更新【${cName}】记录 45 | */ 46 | public int update(${upp} vo) { 47 | StringBuilder sql = new StringBuilder(); 48 | sql.append("UPDATE ${tName} SET ${updateFields}"); 49 | sql.append(" WHERE ${idName}=? "); 50 | Object[] params = {${updateValues} }; 51 | // log.info(super.sql(sql.toString(), params));// 显示SQL语句 52 | return jdbcTemplate.update(sql.toString(), params); 53 | } 54 | 55 | /** 56 | * @方法说明 按条件查询分页【${cName}】列表 57 | */ 58 | public Page<${upp}> page(${upp}Cond cond) { 59 | StringBuilder sql = new StringBuilder(); 60 | sql.append("SELECT ${selectFields}"); 61 | sql.append(" FROM ${tName} t"); 62 | sql.append(cond.where()); 63 | log.info(super.sql(sql.toString(), cond.array()));// 显示SQL语句 64 | return queryPage(sql.toString(), cond, ${upp}.class); 65 | } 66 | 67 | /** 68 | * @方法说明 按条件查询不分页【${cName}】列表 69 | */ 70 | public List<${upp}> list(${upp}Cond cond) { 71 | StringBuilder sql = new StringBuilder(); 72 | sql.append("SELECT ${selectFields}"); 73 | sql.append(" FROM ${tName} t"); 74 | sql.append(cond.where()); 75 | sql.append(" ORDER BY ${idName} DESC"); 76 | // log.info(super.sql(sql.toString(),cond.array()));//显示SQL语句 77 | return jdbcTemplate.query(sql.toString(), cond.array(), new BeanPropertyRowMapper<>(${upp}.class)); 78 | } 79 | 80 | /** 81 | * @方法说明 按主键查找单个【${cName}】记录 82 | */ 83 | public ${upp} findById(${idType} id) { 84 | StringBuilder sql = new StringBuilder(); 85 | sql.append("SELECT ${selectFields}"); 86 | sql.append(" FROM ${tName} t WHERE t.${idName}=?"); 87 | // log.info(super.sql(sql.toString(),id));//显示SQL语句 88 | return jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(${upp}.class), id); 89 | } 90 | 91 | /** 92 | * @方法说明 按条件查询【${cName}】记录个数 93 | */ 94 | public int count(${upp}Cond cond) { 95 | String sql = "SELECT COUNT(1) FROM ${tName} t " + cond.where(); 96 | // log.info(super.sql(sql,cond.array()));//显示SQL语句 97 | return jdbcTemplate.queryForObject(sql, cond.array(), Integer.class); 98 | } 99 | 100 | /** 101 | * @方法说明 新增【${cName}】记录并返回自增涨主键值 102 | */ 103 | public long saveReturnPK(${upp} vo) { 104 | StringBuilder sql = new StringBuilder(); 105 | sql.append("INSERT INTO ${tName} (${insertFields})"); 106 | sql.append(" VALUES (${insertParamsBatch})"); 107 | // log.info(super.sql(sql.toString(), vo));// 显示SQL语句 108 | return saveKey(vo, sql.toString(), "${idName}"); 109 | } 110 | 111 | /** 112 | * @方法说明 批量插入【${cName}】记录 113 | */ 114 | public int[] insertBatch(List<${upp}> list) { 115 | StringBuilder sql = new StringBuilder(); 116 | sql.append("INSERT INTO ${tName} (${insertFields})"); 117 | sql.append(" VALUES (${insertParamsBatch})"); 118 | // log.info(super.sql(sql.toString(), list));// 显示SQL语句 119 | return batchOperate(list, sql.toString()); 120 | } 121 | 122 | /** 123 | * @方法说明 逻辑删除【${cName}】记录 124 | */ 125 | // public int delete(Object... ids) { 126 | // String sql = "UPDATE ${tName} SET dr=1 WHERE ${idName} IN " + toIn(ids); 127 | // return jdbcTemplate.update(sql,ids); 128 | // } 129 | 130 | } -------------------------------------------------------------------------------- /src/main/resources/code/webdata/ModelService.java: -------------------------------------------------------------------------------- 1 | package ${pName}; 2 | //import java.util.List; 3 | import com.gzz.common.base.Page; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | /** 10 | * @类说明 [${cName}]业务逻辑层 11 | * @author ${auth} 12 | * @date ${time} 13 | **/ 14 | @Slf4j 15 | @Service 16 | public class ${upp}Service { 17 | 18 | @Autowired 19 | private ${upp}Dao dao; //注入${cName}数据访问层 20 | 21 | /** 22 | * @方法说明 新增[${cName}]记录 23 | */ 24 | //@Transactional 25 | public int save(${upp} ${lowUpp}) { 26 | return dao.save(${lowUpp}); 27 | } 28 | 29 | /** 30 | * @方法说明 删除${cName}记录(多条) 31 | */ 32 | public int delete(${idType} ids[]) { 33 | //return dao.deleteLogic(ids);//逻辑删除 34 | return dao.delete(ids);//物理删除 35 | } 36 | 37 | /** 38 | * @方法说明 更新${cName}记录 39 | */ 40 | public int update(${upp} ${lowUpp}) { 41 | return dao.update(${lowUpp}); 42 | } 43 | 44 | /** 45 | * @方法说明 按条件查询分页${cName}列表 46 | */ 47 | public Page<${upp}> queryPage(${upp}Cond cond) { 48 | return dao.queryPage(cond); 49 | } 50 | 51 | /** 52 | * @方法说明 按条件查询不分页${cName}列表 53 | */ 54 | // public List<${upp}> queryList(${upp}Cond cond) { 55 | // return dao.queryList(cond); 56 | // } 57 | 58 | /** 59 | * @方法说明 按主键查找单个${cName}记录 60 | */ 61 | // public ${upp} findById(${idType} id) { 62 | // return dao.findById(id); 63 | // } 64 | 65 | /** 66 | * @方法说明 按条件查询${cName}记录个数 67 | */ 68 | // public long queryCount(${upp}Cond cond) { 69 | // return dao.queryCount(cond); 70 | // } 71 | } -------------------------------------------------------------------------------- /src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ${default-pattern} 8 | 9 | 10 | 11 | ${app.home:-.}/logs/${app-name}.log 12 | 13 | ${app.home:-.}/logs/${app-name}.%i.log.zip 14 | 1 15 | 100 16 | 17 | 18 | 80MB 19 | 20 | 21 | ${default-pattern} 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/static/axios.min.js: -------------------------------------------------------------------------------- 1 | /* axios v0.17.1 | (c) 2017 by Matt Zabriskie */ 2 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.axios=t():e.axios=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e){var t=new s(e),n=i(s.prototype.request,t);return o.extend(n,s.prototype,t),o.extend(n,t),n}var o=n(2),i=n(3),s=n(5),u=n(6),a=r(u);a.Axios=s,a.create=function(e){return r(o.merge(u,e))},a.Cancel=n(23),a.CancelToken=n(24),a.isCancel=n(20),a.all=function(e){return Promise.all(e)},a.spread=n(25),e.exports=a,e.exports.default=a},function(e,t,n){"use strict";function r(e){return"[object Array]"===R.call(e)}function o(e){return"[object ArrayBuffer]"===R.call(e)}function i(e){return"undefined"!=typeof FormData&&e instanceof FormData}function s(e){var t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer}function u(e){return"string"==typeof e}function a(e){return"number"==typeof e}function c(e){return"undefined"==typeof e}function f(e){return null!==e&&"object"==typeof e}function p(e){return"[object Date]"===R.call(e)}function d(e){return"[object File]"===R.call(e)}function l(e){return"[object Blob]"===R.call(e)}function h(e){return"[object Function]"===R.call(e)}function m(e){return f(e)&&h(e.pipe)}function y(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams}function w(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")}function g(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)}function v(e,t){if(null!==e&&"undefined"!=typeof e)if("object"!=typeof e&&(e=[e]),r(e))for(var n=0,o=e.length;n 6 | * @license MIT 7 | */ 8 | e.exports=function(e){return null!=e&&(n(e)||r(e)||!!e._isBuffer)}},function(e,t,n){"use strict";function r(e){this.defaults=e,this.interceptors={request:new s,response:new s}}var o=n(6),i=n(2),s=n(17),u=n(18);r.prototype.request=function(e){"string"==typeof e&&(e=i.merge({url:arguments[0]},arguments[1])),e=i.merge(o,this.defaults,{method:"get"},e),e.method=e.method.toLowerCase();var t=[u,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach(function(e){t.unshift(e.fulfilled,e.rejected)}),this.interceptors.response.forEach(function(e){t.push(e.fulfilled,e.rejected)});t.length;)n=n.then(t.shift(),t.shift());return n},i.forEach(["delete","get","head","options"],function(e){r.prototype[e]=function(t,n){return this.request(i.merge(n||{},{method:e,url:t}))}}),i.forEach(["post","put","patch"],function(e){r.prototype[e]=function(t,n,r){return this.request(i.merge(r||{},{method:e,url:t,data:n}))}}),e.exports=r},function(e,t,n){"use strict";function r(e,t){!i.isUndefined(e)&&i.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}function o(){var e;return"undefined"!=typeof XMLHttpRequest?e=n(8):"undefined"!=typeof process&&(e=n(8)),e}var i=n(2),s=n(7),u={"Content-Type":"application/x-www-form-urlencoded"},a={adapter:o(),transformRequest:[function(e,t){return s(t,"Content-Type"),i.isFormData(e)||i.isArrayBuffer(e)||i.isBuffer(e)||i.isStream(e)||i.isFile(e)||i.isBlob(e)?e:i.isArrayBufferView(e)?e.buffer:i.isURLSearchParams(e)?(r(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):i.isObject(e)?(r(t,"application/json;charset=utf-8"),JSON.stringify(e)):e}],transformResponse:[function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,validateStatus:function(e){return e>=200&&e<300}};a.headers={common:{Accept:"application/json, text/plain, */*"}},i.forEach(["delete","get","head"],function(e){a.headers[e]={}}),i.forEach(["post","put","patch"],function(e){a.headers[e]=i.merge(u)}),e.exports=a},function(e,t,n){"use strict";var r=n(2);e.exports=function(e,t){r.forEach(e,function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])})}},function(e,t,n){"use strict";var r=n(2),o=n(9),i=n(12),s=n(13),u=n(14),a=n(10),c="undefined"!=typeof window&&window.btoa&&window.btoa.bind(window)||n(15);e.exports=function(e){return new Promise(function(t,f){var p=e.data,d=e.headers;r.isFormData(p)&&delete d["Content-Type"];var l=new XMLHttpRequest,h="onreadystatechange",m=!1;if("undefined"==typeof window||!window.XDomainRequest||"withCredentials"in l||u(e.url)||(l=new window.XDomainRequest,h="onload",m=!0,l.onprogress=function(){},l.ontimeout=function(){}),e.auth){var y=e.auth.username||"",w=e.auth.password||"";d.Authorization="Basic "+c(y+":"+w)}if(l.open(e.method.toUpperCase(),i(e.url,e.params,e.paramsSerializer),!0),l.timeout=e.timeout,l[h]=function(){if(l&&(4===l.readyState||m)&&(0!==l.status||l.responseURL&&0===l.responseURL.indexOf("file:"))){var n="getAllResponseHeaders"in l?s(l.getAllResponseHeaders()):null,r=e.responseType&&"text"!==e.responseType?l.response:l.responseText,i={data:r,status:1223===l.status?204:l.status,statusText:1223===l.status?"No Content":l.statusText,headers:n,config:e,request:l};o(t,f,i),l=null}},l.onerror=function(){f(a("Network Error",e,null,l)),l=null},l.ontimeout=function(){f(a("timeout of "+e.timeout+"ms exceeded",e,"ECONNABORTED",l)),l=null},r.isStandardBrowserEnv()){var g=n(16),v=(e.withCredentials||u(e.url))&&e.xsrfCookieName?g.read(e.xsrfCookieName):void 0;v&&(d[e.xsrfHeaderName]=v)}if("setRequestHeader"in l&&r.forEach(d,function(e,t){"undefined"==typeof p&&"content-type"===t.toLowerCase()?delete d[t]:l.setRequestHeader(t,e)}),e.withCredentials&&(l.withCredentials=!0),e.responseType)try{l.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&l.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&l.upload&&l.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then(function(e){l&&(l.abort(),f(e),l=null)}),void 0===p&&(p=null),l.send(p)})}},function(e,t,n){"use strict";var r=n(10);e.exports=function(e,t,n){var o=n.config.validateStatus;n.status&&o&&!o(n.status)?t(r("Request failed with status code "+n.status,n.config,null,n.request,n)):e(n)}},function(e,t,n){"use strict";var r=n(11);e.exports=function(e,t,n,o,i){var s=new Error(e);return r(s,t,n,o,i)}},function(e,t){"use strict";e.exports=function(e,t,n,r,o){return e.config=t,n&&(e.code=n),e.request=r,e.response=o,e}},function(e,t,n){"use strict";function r(e){return encodeURIComponent(e).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var o=n(2);e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(o.isURLSearchParams(t))i=t.toString();else{var s=[];o.forEach(t,function(e,t){null!==e&&"undefined"!=typeof e&&(o.isArray(e)&&(t+="[]"),o.isArray(e)||(e=[e]),o.forEach(e,function(e){o.isDate(e)?e=e.toISOString():o.isObject(e)&&(e=JSON.stringify(e)),s.push(r(t)+"="+r(e))}))}),i=s.join("&")}return i&&(e+=(e.indexOf("?")===-1?"?":"&")+i),e}},function(e,t,n){"use strict";var r=n(2),o=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];e.exports=function(e){var t,n,i,s={};return e?(r.forEach(e.split("\n"),function(e){if(i=e.indexOf(":"),t=r.trim(e.substr(0,i)).toLowerCase(),n=r.trim(e.substr(i+1)),t){if(s[t]&&o.indexOf(t)>=0)return;"set-cookie"===t?s[t]=(s[t]?s[t]:[]).concat([n]):s[t]=s[t]?s[t]+", "+n:n}}),s):s}},function(e,t,n){"use strict";var r=n(2);e.exports=r.isStandardBrowserEnv()?function(){function e(e){var t=e;return n&&(o.setAttribute("href",t),t=o.href),o.setAttribute("href",t),{href:o.href,protocol:o.protocol?o.protocol.replace(/:$/,""):"",host:o.host,search:o.search?o.search.replace(/^\?/,""):"",hash:o.hash?o.hash.replace(/^#/,""):"",hostname:o.hostname,port:o.port,pathname:"/"===o.pathname.charAt(0)?o.pathname:"/"+o.pathname}}var t,n=/(msie|trident)/i.test(navigator.userAgent),o=document.createElement("a");return t=e(window.location.href),function(n){var o=r.isString(n)?e(n):n;return o.protocol===t.protocol&&o.host===t.host}}():function(){return function(){return!0}}()},function(e,t){"use strict";function n(){this.message="String contains an invalid character"}function r(e){for(var t,r,i=String(e),s="",u=0,a=o;i.charAt(0|u)||(a="=",u%1);s+=a.charAt(63&t>>8-u%1*8)){if(r=i.charCodeAt(u+=.75),r>255)throw new n;t=t<<8|r}return s}var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.prototype=new Error,n.prototype.code=5,n.prototype.name="InvalidCharacterError",e.exports=r},function(e,t,n){"use strict";var r=n(2);e.exports=r.isStandardBrowserEnv()?function(){return{write:function(e,t,n,o,i,s){var u=[];u.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&u.push("expires="+new Date(n).toGMTString()),r.isString(o)&&u.push("path="+o),r.isString(i)&&u.push("domain="+i),s===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}()},function(e,t,n){"use strict";function r(){this.handlers=[]}var o=n(2);r.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},r.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},r.prototype.forEach=function(e){o.forEach(this.handlers,function(t){null!==t&&e(t)})},e.exports=r},function(e,t,n){"use strict";function r(e){e.cancelToken&&e.cancelToken.throwIfRequested()}var o=n(2),i=n(19),s=n(20),u=n(6),a=n(21),c=n(22);e.exports=function(e){r(e),e.baseURL&&!a(e.url)&&(e.url=c(e.baseURL,e.url)),e.headers=e.headers||{},e.data=i(e.data,e.headers,e.transformRequest),e.headers=o.merge(e.headers.common||{},e.headers[e.method]||{},e.headers||{}),o.forEach(["delete","get","head","post","put","patch","common"],function(t){delete e.headers[t]});var t=e.adapter||u.adapter;return t(e).then(function(t){return r(e),t.data=i(t.data,t.headers,e.transformResponse),t},function(t){return s(t)||(r(e),t&&t.response&&(t.response.data=i(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)})}},function(e,t,n){"use strict";var r=n(2);e.exports=function(e,t,n){return r.forEach(n,function(n){e=n(e,t)}),e}},function(e,t){"use strict";e.exports=function(e){return!(!e||!e.__CANCEL__)}},function(e,t){"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t){"use strict";e.exports=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}},function(e,t){"use strict";function n(e){this.message=e}n.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},n.prototype.__CANCEL__=!0,e.exports=n},function(e,t,n){"use strict";function r(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise(function(e){t=e});var n=this;e(function(e){n.reason||(n.reason=new o(e),t(n.reason))})}var o=n(23);r.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},r.source=function(){var e,t=new r(function(t){e=t});return{token:t,cancel:e}},e.exports=r},function(e,t){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}}])}); 9 | //# sourceMappingURL=axios.min.map -------------------------------------------------------------------------------- /src/main/resources/static/fonts/element-icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzz2017gzz/code/4071909a880b1f7373c224a1166b628738ab2a47/src/main/resources/static/fonts/element-icons.woff -------------------------------------------------------------------------------- /src/main/resources/static/fonts/ionicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzz2017gzz/code/4071909a880b1f7373c224a1166b628738ab2a47/src/main/resources/static/fonts/ionicons.ttf -------------------------------------------------------------------------------- /src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 代码生成器(gzz_gzz@163.com) 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 【注意】 10 | 【调整[作者名]\[模块名],点击[查看字段]确保表名注释与字段名注释为中文,建议类名中表名前缀部分已去掉】 11 |
12 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 39 | 40 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
61 | 129 | 130 | --------------------------------------------------------------------------------