Skip to content

Commit b30ce86

Browse files
author
moshowgame
committed
新增mapper2(Mybatis-Annotation模板)(感谢@baisi525@CHKEGit的建议)
1 parent e90f9f7 commit b30ce86

File tree

6 files changed

+82
-11
lines changed

6 files changed

+82
-11
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
# Description
99
- √ 基于SpringBoot2+Freemarker+Bootstrap
10-
-以释放双手为目的
10+
-以解放双手为目的,减少大量重复的CRUD工作
1111
- √ 支持mysql/oracle/pgsql三大数据库
1212
- √ 用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码.
1313

14+
# Advantage
15+
- 自动记忆最近生成的内容,最多保留9个
16+
- 支持特殊字符模板(`#`请用``代替;`$`请用``代替)
17+
- 提供众多通用模板,易于使用,复制粘贴加简单修改即可完成CRUD操作
18+
- 支持JSON逆向生成(只支持简单的一级树)
19+
1420

1521
# Url
1622

@@ -20,14 +26,14 @@
2026
|CSDN博客|http://zhengkai.blog.csdn.net|
2127
|最新Jar包|https://github.com/moshowgame/SpringBootCodeGenerator/releases|
2228

23-
感谢bejson三叔将他部署在[BEJSON](www.bejson.com)上,目前是besjon专供工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢).
29+
感谢bejson三叔将他部署在[BEJSON](www.bejson.com)上,目前是besjon专供的金牌工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢).
2430

2531

2632
# Update
2733

2834
|更新日期|更新内容|
2935
|-|-|
30-
|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件。 2.修复包含comment关键字时注释无法识别的问题。(感谢@1nchaos的反馈) 3.赞赏优化,感谢大家的赞赏|
36+
|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件。 2.修复包含comment关键字时注释无法识别的问题。(感谢@1nchaos的反馈) 3.赞赏优化,感谢大家的赞赏 4.新增mapper2(Mybatis-Annotation模板)(感谢@baisi525@CHKEGit的建议)。|
3137
|20200503|1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理<br> 2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈) 3.修优化对所有类型的判断(感谢@cnlw的反馈) 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 5.升级hutool和lombok版本|
3238
|20200306|1.提交一套layuimini+mybatisplus的模板. 2.修复mybatisplus一些相关问题. |
3339
|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)|

generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class FreemarkerUtil {
3131
* 传入需要转义的字符串进行转义
3232
* 20200503 zhengkai.blog.csdn.net
3333
* */
34-
public String escapeString(String originStr){
34+
public static String escapeString(String originStr){
3535
return originStr.replaceAll("井","\\#").replaceAll("¥","\\$");
3636
}
3737

@@ -88,7 +88,7 @@ public static String processString(String templateName, Map<String, Object> para
8888
throws IOException, TemplateException {
8989

9090
Template template = freemarkerConfig.getTemplate(templateName);
91-
String htmlText = processTemplateIntoString(template, params);
91+
String htmlText = escapeString(processTemplateIntoString(template, params));
9292
return htmlText;
9393
}
9494

generator-web/src/main/resources/template.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
"group": "mybatis",
6666
"description": "model"
6767
},
68+
{
69+
"id": "26",
70+
"name": "mapper2",
71+
"group": "mybatis",
72+
"description": "mapper annotation"
73+
},
6874
{
6975
"id": "30",
7076
"name": "entity",

generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
1212
* @author ${authorName}
1313
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
1414
*/
15-
@Data
16-
<#if swagger?exists && swagger==true>@ApiModel("${classInfo.classComment}")</#if>
15+
@Data<#if swagger?exists && swagger==true>
16+
@ApiModel("${classInfo.classComment}")</#if>
1717
public class ${classInfo.className} implements Serializable {
1818

1919
private static final long serialVersionUID = 1L;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ${packageName}.mapper;
2+
3+
import org.apache.ibatis.annotations.*;
4+
import org.springframework.stereotype.Repository;
5+
import java.util.List;
6+
7+
/**
8+
* @description ${classInfo.classComment}Mapper
9+
* @author ${authorName}
10+
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
11+
*/
12+
@Mapper
13+
@Repository
14+
public interface ${classInfo.className}Mapper {
15+
16+
@Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}")
17+
public ${classInfo.className} getById(Integer id);
18+
19+
@Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first}Id")
20+
@Insert("insert into ${classInfo.tableName}"
21+
"(<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>)"
22+
"values(<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName}<#if fieldItem_has_next>,</#if>)</#list>")
23+
public Integer insert(${classInfo.className} ${classInfo.className?uncap_first});
24+
25+
@Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id}")
26+
boolean delete(Integer id);
27+
28+
@Update(value = "update ${classInfo.tableName} set "
29+
<#list classInfo.fieldList as fieldItem >
30+
<#if fieldItem.columnName != "id">+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>,</#if>"</#if>
31+
</#list>
32+
+" where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ")
33+
boolean update(${classInfo.className} ${classInfo.className?uncap_first});
34+
35+
36+
@Results(value = {
37+
<#list classInfo.fieldList as fieldItem >
38+
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
39+
</#list>
40+
})
41+
@Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{queryParam}")
42+
${classInfo.className} selectOne(String queryParam);
43+
44+
@Results(value = {
45+
<#list classInfo.fieldList as fieldItem >
46+
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
47+
</#list>
48+
})
49+
@Select(value = "select * from ${classInfo.tableName} where "
50+
<#list classInfo.fieldList as fieldItem >
51+
+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or </#if>"
52+
</#list>
53+
)
54+
List<${classInfo.className}> selectList(${classInfo.className} ${classInfo.className?uncap_first});
55+
56+
}

generator-web/src/main/resources/templates/index.ftl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@
217217
<div class="container">
218218
<h2>Spring Boot Code Generator!</h2>
219219
<p class="lead">
220-
√基于SpringBoot2+Freemarker的<a class="lead" href="https://github.com/moshowgame/SpringBootCodeGenerator">代码生成器</a>,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
220+
√基于SpringBoot2+Freemarker的<a class="lead" href="https://github.com/moshowgame/SpringBootCodeGenerator">代码生成器</a><br>
221+
√以解放双手为目的,减少大量重复的CRUD工作<br>
222+
√支持mysql/oracle/pgsql三大数据库<br>
221223
√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码。<br>
222224
如果发现有SQL语句不能识别,请<a href="https://github.com/moshowgame/SpringBootCodeGenerator/issues">留言</a>,同时欢迎大家提<a href="https://github.com/moshowgame/SpringBootCodeGenerator/pulls">PR</a>和<a href="#" id="donate1">赞赏</a>,谢谢!<a id="version" href="#">查看版本</a>
223225
</p>
@@ -279,7 +281,7 @@
279281
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
280282
CREATE TABLE 'userinfo' (
281283
'user_id' int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
282-
'username' varchar(255) NOT NULL COMMENT '用户名',
284+
'user_name' varchar(255) NOT NULL COMMENT '用户名',
283285
'addtime' datetime NOT NULL COMMENT '创建时间',
284286
PRIMARY KEY ('user_id')
285287
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息'
@@ -307,10 +309,11 @@ CREATE TABLE 'userinfo' (
307309
</div>
308310
</div>
309311
<div class="btn-group" role="group" aria-label="First group">
310-
<button type="button" class="btn btn-default generator" id="mybatis">mybatis</button>
312+
<button type="button" class="btn btn-default generator" id="mybatis">ibatisXml</button>
311313
<button type="button" class="btn btn-default generator" id="mapper">mapper</button>
314+
<button type="button" class="btn btn-default generator" id="mapper2">mapper2</button>
312315
<button type="button" class="btn btn-default generator" id="service">service</button>
313-
<button type="button" class="btn btn-default generator" id="service_impl">service_impl</button>
316+
<button type="button" class="btn btn-default generator" id="service_impl">serviceImpl</button>
314317
<button type="button" class="btn btn-default generator" id="controller">controller</button>
315318
</div>
316319
</div>

0 commit comments

Comments
 (0)