Skip to content

Commit eb3ffbc

Browse files
committed
add support Java-SpringBoot-MyBatis template
1 parent 206494b commit eb3ffbc

21 files changed

+349
-62
lines changed

build/version.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>2</VersionMajor>
44
<VersionMinor>2</VersionMinor>
5-
<VersionPatch>70</VersionPatch>
5+
<VersionPatch>80</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

doc/SmartCode-Spring-Boot.yml

+67-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Module: net.smartsql.code
1+
Module: net.smartsql.demo
22
Author: Ahoo Wang
33
DataSource:
44
Name: DbTable
55
Parameters:
66
DbName: smartsql_db
77
DbProvider: MySql
8-
ConnectionString: Data Source=**;database=smartsql_db;uid=root;pwd=**;Charset=utf8;SslMode=none
8+
ConnectionString: Data Source=serverAddress;database=smartsql_db;uid=root;pwd=smartsql;Charset=utf8;SslMode=none
99
Language: Java
1010
TemplateEngine:
1111
Name: Razor
@@ -15,7 +15,7 @@ Output:
1515
Path: 'D://SmartSql-Java'
1616
Parameters:
1717
BuildDir: 'D:\SmartSql-Java\build'
18-
18+
ApplicationName: Demo
1919
NamingConverter:
2020
Table:
2121
Tokenizer:
@@ -74,7 +74,31 @@ Build:
7474
{Key: 'Pom-Parent.cshtml',Output: {Name: 'pom',Extension: '.xml'}},
7575
{Key: 'Pom-Api.cshtml',Output: {Path: "api",Name: 'pom',Extension: '.xml'}},
7676
{Key: 'Pom-Server.cshtml',Output: {Path: "server",Name: 'pom',Extension: '.xml'}},
77-
{Key: 'Resources/Application-YAML.cshtml',Output: {Path: "server/src/main/resources",Name: 'application',Extension: '.yml'}}
77+
{Key: 'Resources/Application-YAML.cshtml',Output: {Path: "server/src/main/resources",Name: 'application',Extension: '.yml'}},
78+
{Key: 'Application.cshtml',Output:
79+
{
80+
Path: "server/src/main/java/{{Project.Module}}/",
81+
DotSplit: true,
82+
Name: '{{Project.Parameters.ApplicationName}}Application',
83+
Extension: '.java'
84+
}
85+
},
86+
{Key: 'Test/Application-Test.cshtml',Output:
87+
{
88+
Path: "server/src/test/java/{{Project.Module}}/",
89+
DotSplit: true,
90+
Name: '{{Project.Parameters.ApplicationName}}ApplicationTests',
91+
Extension: '.java'
92+
}
93+
},
94+
{Key: 'AppConfig.cshtml',Output:
95+
{
96+
Path: "server/src/main/java/{{Project.Module}}/config",
97+
DotSplit: true,
98+
Name: 'AppConfig',
99+
Extension: '.java'
100+
}
101+
}
78102
]
79103

80104
Entity:
@@ -90,13 +114,13 @@ Build:
90114
Parameters:
91115
AbstractEntity:
92116
Name: AbstractEntity
93-
Package: net.smartsql.code
117+
Package: net.smartsql.entity
94118
Properties:
95119
- id
96120
- createTime
97121
- modifiedTime
98122
- deleted
99-
123+
100124
SqlMap:
101125
Type: Table
102126
Module: repository
@@ -108,4 +132,40 @@ Build:
108132
Name: '{{Items.CurrentTable.ConvertedName}}Mapper'
109133
Extension: '.xml'
110134
Parameters:
111-
LogicalDelete: deleted
135+
LogicalDelete: deleted
136+
137+
Repository:
138+
Type: Table
139+
Module: repository
140+
TemplateEngine:
141+
Path: Repository.cshtml
142+
Output:
143+
Path: 'server/src/main/java/{{Project.Module}}.{{Build.Module}}'
144+
DotSplit: true
145+
Name: '{{Items.CurrentTable.ConvertedName}}Repository'
146+
Extension: '.java'
147+
Parameters:
148+
GenericRepository:
149+
Package: net.smartsql.repository
150+
151+
Service:
152+
Type: Table
153+
Module: service
154+
TemplateEngine:
155+
Path: Service.cshtml
156+
Output:
157+
Path: 'server/src/main/java/{{Project.Module}}.{{Build.Module}}'
158+
DotSplit: true
159+
Name: '{{Items.CurrentTable.ConvertedName}}Service'
160+
Extension: '.java'
161+
162+
Controller:
163+
Type: Table
164+
Module: controller
165+
TemplateEngine:
166+
Path: Controller.cshtml
167+
Output:
168+
Path: 'server/src/main/java/{{Project.Module}}.{{Build.Module}}'
169+
DotSplit: true
170+
Name: '{{Items.CurrentTable.ConvertedName}}Controller'
171+
Extension: '.java'

doc/SmartCode.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Output:
1414
Type: File
1515
Path: 'D:\SmartSql-Starter'
1616
Parameters:
17-
SmartSqlVersion: '4.1.23'
18-
SmartSqlSchemaVersion: '4.1.16'
17+
SmartSqlVersion: '4.1.32'
18+
SmartSqlSchemaVersion: '4.1.29'
1919
BuildDir: 'D:\SmartSql-Starter\build'
2020
DockerImage: 'smartsql.starter'
2121

src/SmartCode.App/BuildTasks/MultiTemplateBuildTask.cs

+22-6
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,27 @@ public MultiTemplateBuildTask(IPluginManager pluginManager
3131
_pluginManager = pluginManager;
3232
_logger = logger;
3333
}
34+
3435
public async Task Build(BuildContext context)
3536
{
3637
if (context.Build.Parameters.Value(TEMPLATES_KEY, out IEnumerable templates))
3738
{
3839
foreach (var templateKVs in templates)
3940
{
40-
var _templateKVs = (Dictionary<object, object>)templateKVs;
41+
var _templateKVs = (Dictionary<object, object>) templateKVs;
4142
if (!_templateKVs.Value(TEMPLATE_KEY, out string templateKey))
4243
{
4344
throw new SmartCodeException($"Build:{context.BuildKey},Can not find TemplateKey!");
4445
}
46+
4547
context.Build.TemplateEngine.Path = templateKey;
46-
context.Result = await _pluginManager.Resolve<ITemplateEngine>(context.Build.TemplateEngine.Name).Render(context);
48+
context.Result = await _pluginManager.Resolve<ITemplateEngine>(context.Build.TemplateEngine.Name)
49+
.Render(context);
4750
if (!_templateKVs.Value(TEMPLATE_OUTPUT_KEY, out Dictionary<object, object> outputKVs))
4851
{
4952
throw new SmartCodeException($"Build:{context.BuildKey},Can not find Output!");
5053
}
54+
5155
if (context.Output == null)
5256
{
5357
throw new SmartCodeException($"Build:{context.BuildKey},Output can not be null!");
@@ -57,39 +61,51 @@ public async Task Build(BuildContext context)
5761
{
5862
Path = context.Output.Path,
5963
Mode = context.Output.Mode,
64+
DotSplit = context.Output.DotSplit,
6065
Name = context.Output.Name,
6166
Extension = context.Output.Extension
6267
};
6368
if (outputKVs.Value(nameof(Output.Path), out string outputPath))
6469
{
6570
output.Path = outputPath;
6671
}
72+
6773
if (outputKVs.Value(nameof(Output.Mode), out CreateMode outputMode))
6874
{
6975
output.Mode = outputMode;
7076
}
77+
78+
if (outputKVs.Value(nameof(Output.DotSplit), out string dotSplit))
79+
{
80+
output.DotSplit = Convert.ToBoolean(dotSplit);
81+
}
82+
7183
if (String.IsNullOrEmpty(output.Path))
7284
{
73-
throw new SmartCodeException($"Build:{context.BuildKey},Template:{templateKey},can not find Output.Path!");
85+
throw new SmartCodeException(
86+
$"Build:{context.BuildKey},Template:{templateKey},can not find Output.Path!");
7487
}
88+
7589
if (!outputKVs.Value(nameof(Output.Name), out string outputName))
7690
{
77-
throw new SmartCodeException($"Build:{context.BuildKey},Template:{templateKey},can not find Output.Name!");
91+
throw new SmartCodeException(
92+
$"Build:{context.BuildKey},Template:{templateKey},can not find Output.Name!");
7893
}
94+
7995
output.Name = outputName;
8096

8197
if (outputKVs.Value(nameof(Output.Extension), out string extension))
8298
{
8399
output.Extension = extension;
84100
}
101+
85102
await _pluginManager.Resolve<IOutput>(context.Output.Type).Output(context, output);
86103
}
87104
}
88105
}
89106

90107
public void Initialize(IDictionary<string, object> parameters)
91108
{
92-
93109
}
94110
}
95-
}
111+
}

src/SmartCode.App/Outputs/FileOutput.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task Output(BuildContext context, Output output = null)
8585

8686
using (StreamWriter streamWriter = new StreamWriter(filePath))
8787
{
88-
await streamWriter.WriteAsync(context.Result);
88+
await streamWriter.WriteAsync(context.Result.Trim());
8989
}
9090

9191
_logger.LogInformation($"------ Mode:{output.Mode},Build:{context.BuildKey} -> {filePath} End! ------");

src/SmartCode.CLI/SmartCode.CLI.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PackageReleaseNotes>
1515
</PropertyGroup>
1616
<ItemGroup>
17-
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.3.4" />
17+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.4.2" />
1818
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
1919
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
2020
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />

src/SmartCode.Db/SmartCode.Db.csproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="SmartSql.Options" Version="4.1.23" />
9-
<PackageReference Include="SmartSql.TypeHandler" Version="4.1.23" />
10-
<PackageReference Include="SmartSql.TypeHandler.PostgreSql" Version="4.1.23" />
11-
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
8+
<PackageReference Include="SmartSql.Options" Version="4.1.32" />
9+
<PackageReference Include="SmartSql.TypeHandler" Version="4.1.32" />
10+
<PackageReference Include="SmartSql.TypeHandler.PostgreSql" Version="4.1.32" />
11+
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
1212
<PackageReference Include="System.Data.SQLite" Version="1.0.110" />
13-
<PackageReference Include="MySql.Data" Version="8.0.17" />
14-
<PackageReference Include="Npgsql" Version="4.0.9" />
15-
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.31" />
13+
<PackageReference Include="MySql.Data" Version="8.0.18" />
14+
<PackageReference Include="Npgsql" Version="4.1.1" />
15+
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.50" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/SmartCode.ETL/SmartCode.ETL.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="SmartSql.Bulk.MySql" Version="4.1.23" />
9-
<PackageReference Include="SmartSql.Bulk.PostgreSql" Version="4.1.23" />
10-
<PackageReference Include="SmartSql.Bulk.SqlServer" Version="4.1.23" />
8+
<PackageReference Include="SmartSql.Bulk.MySql" Version="4.1.32" />
9+
<PackageReference Include="SmartSql.Bulk.PostgreSql" Version="4.1.32" />
10+
<PackageReference Include="SmartSql.Bulk.SqlServer" Version="4.1.32" />
1111
</ItemGroup>
1212

1313
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
Layout = "_JavaLayout.cshtml";
5+
var project = Model.Project;
6+
var buildTask = Model.Build;
7+
}
8+
9+
10+
package @(project.Module).config;
11+
12+
public class AppConfig {
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
package me.ahoo.demo;
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
Layout = "_JavaLayout.cshtml";
5+
var project = Model.Project;
6+
7+
var appName = "Demo";
8+
9+
if (project.Parameters.TryGetValue("ApplicationName", out var _appName))
10+
{
11+
appName = _appName.ToString();
12+
}
13+
var appClassName = $"{appName}Application";
14+
}
15+
16+
package @(project.Module);
217

318
import org.springframework.boot.SpringApplication;
419
import org.springframework.boot.autoconfigure.SpringBootApplication;
20+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
521

622
@@SpringBootApplication
7-
public class DemoApplication {
23+
@@EnableSwagger2
24+
public class @appClassName {
825

926
public static void main(String[] args) {
10-
SpringApplication.run(DemoApplication.class, args);
27+
SpringApplication.run(@(appClassName).class, args);
1128
}
1229

1330
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
Layout = "_JavaLayout.cshtml";
5+
var project = Model.Project;
6+
var buildTask = Model.Build;
7+
var table = Model.GetCurrentTable();
8+
var pkCol = table.PKColumn;
9+
if (pkCol == null)
10+
{
11+
throw new SmartCodeException($"Service Template can not find PKColumn,Table:{table.Name}.");
12+
}
13+
var pkType = pkCol.LanguageType;
14+
var insertRetType = table.AutoIncrement ? pkType : "int";
15+
var entityName = table.ConvertedName;
16+
var entityCamelName = NamingUtil.CamelCase(table.ConvertedName);
17+
var serviceName = $"{table.ConvertedName}Service";
18+
var serviceCamelName = NamingUtil.CamelCase(serviceName);
19+
var controllerName = $"{table.ConvertedName}Controller";
20+
}
21+
22+
23+
24+
package @(project.Module).@buildTask.Module;
25+
26+
import lombok.var;
27+
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import javax.validation.Valid;
30+
import org.springframework.web.bind.annotation.RequestMapping;
31+
import org.springframework.web.bind.annotation.RestController;
32+
import @(project.Module).service.@serviceName;
33+
34+
@Html.NewLine()
35+
@@RestController
36+
@@RequestMapping("@entityCamelName")
37+
public class @controllerName {
38+
@@Autowired
39+
@serviceName @serviceCamelName;
40+
41+
}

src/SmartCode.Generator/RazorTemplates/Java/Entity.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import java.util.UUID;
6767
import java.util.Date;
6868
@if (useAbstractEntity)
6969
{
70-
<text>import @abstractEntityPackage;</text>
70+
<text>import @($"{abstractEntityPackage}.{abstractEntityName}");</text>
7171
}
7272

7373
import lombok.Data;

0 commit comments

Comments
 (0)