hasan 3 years ago
parent
commit
0328fb1085

+ 8 - 127
pom.xml

@@ -15,20 +15,10 @@
15 15
     <description>nstths</description>
16 16
     <properties>
17 17
         <java.version>17</java.version>
18
-        <repackage.classifier/>
19
-        <spring-native.version>0.11.2</spring-native.version>
20 18
     </properties>
21 19
     <dependencies>
22 20
         <dependency>
23 21
             <groupId>org.springframework.boot</groupId>
24
-            <artifactId>spring-boot-starter-data-jdbc</artifactId>
25
-        </dependency>
26
-        <dependency>
27
-            <groupId>org.springframework.boot</groupId>
28
-            <artifactId>spring-boot-starter-data-jpa</artifactId>
29
-        </dependency>
30
-        <dependency>
31
-            <groupId>org.springframework.boot</groupId>
32 22
             <artifactId>spring-boot-starter-thymeleaf</artifactId>
33 23
         </dependency>
34 24
         <dependency>
@@ -41,9 +31,14 @@
41 31
             <version>2.2.2</version>
42 32
         </dependency>
43 33
         <dependency>
44
-            <groupId>org.springframework.experimental</groupId>
45
-            <artifactId>spring-native</artifactId>
46
-            <version>${spring-native.version}</version>
34
+            <groupId>com.baomidou</groupId>
35
+            <artifactId>mybatis-plus-boot-starter</artifactId>
36
+            <version>3.5.1</version>
37
+        </dependency>
38
+        <dependency>
39
+            <groupId>com.baomidou</groupId>
40
+            <artifactId>mybatis-plus-generator</artifactId>
41
+            <version>3.5.1</version>
47 42
         </dependency>
48 43
 
49 44
         <dependency>
@@ -53,11 +48,6 @@
53 48
             <optional>true</optional>
54 49
         </dependency>
55 50
         <dependency>
56
-            <groupId>com.h2database</groupId>
57
-            <artifactId>h2</artifactId>
58
-            <scope>runtime</scope>
59
-        </dependency>
60
-        <dependency>
61 51
             <groupId>mysql</groupId>
62 52
             <artifactId>mysql-connector-java</artifactId>
63 53
             <scope>runtime</scope>
@@ -86,118 +76,9 @@
86 76
                             <artifactId>lombok</artifactId>
87 77
                         </exclude>
88 78
                     </excludes>
89
-                    <classifier>${repackage.classifier}</classifier>
90
-                    <image>
91
-                        <builder>paketobuildpacks/builder:tiny</builder>
92
-                        <env>
93
-                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
94
-                        </env>
95
-                    </image>
96 79
                 </configuration>
97 80
             </plugin>
98
-            <plugin>
99
-                <groupId>org.springframework.experimental</groupId>
100
-                <artifactId>spring-aot-maven-plugin</artifactId>
101
-                <version>${spring-native.version}</version>
102
-                <executions>
103
-                    <execution>
104
-                        <id>test-generate</id>
105
-                        <goals>
106
-                            <goal>test-generate</goal>
107
-                        </goals>
108
-                    </execution>
109
-                    <execution>
110
-                        <id>generate</id>
111
-                        <goals>
112
-                            <goal>generate</goal>
113
-                        </goals>
114
-                    </execution>
115
-                </executions>
116
-            </plugin>
117
-            <plugin>
118
-                <groupId>org.hibernate.orm.tooling</groupId>
119
-                <artifactId>hibernate-enhance-maven-plugin</artifactId>
120
-                <version>${hibernate.version}</version>
121
-                <executions>
122
-                    <execution>
123
-                        <id>enhance</id>
124
-                        <goals>
125
-                            <goal>enhance</goal>
126
-                        </goals>
127
-                        <configuration>
128
-                            <failOnError>true</failOnError>
129
-                            <enableLazyInitialization>true</enableLazyInitialization>
130
-                            <enableDirtyTracking>true</enableDirtyTracking>
131
-                            <enableAssociationManagement>true</enableAssociationManagement>
132
-                            <enableExtendedEnhancement>false</enableExtendedEnhancement>
133
-                        </configuration>
134
-                    </execution>
135
-                </executions>
136
-            </plugin>
137 81
         </plugins>
138 82
     </build>
139
-    <repositories>
140
-        <repository>
141
-            <id>spring-releases</id>
142
-            <name>Spring Releases</name>
143
-            <url>https://repo.spring.io/release</url>
144
-            <snapshots>
145
-                <enabled>false</enabled>
146
-            </snapshots>
147
-        </repository>
148
-    </repositories>
149
-    <pluginRepositories>
150
-        <pluginRepository>
151
-            <id>spring-releases</id>
152
-            <name>Spring Releases</name>
153
-            <url>https://repo.spring.io/release</url>
154
-            <snapshots>
155
-                <enabled>false</enabled>
156
-            </snapshots>
157
-        </pluginRepository>
158
-    </pluginRepositories>
159
-
160
-    <profiles>
161
-        <profile>
162
-            <id>native</id>
163
-            <properties>
164
-                <repackage.classifier>exec</repackage.classifier>
165
-                <native-buildtools.version>0.9.9</native-buildtools.version>
166
-            </properties>
167
-            <dependencies>
168
-                <dependency>
169
-                    <groupId>org.junit.platform</groupId>
170
-                    <artifactId>junit-platform-launcher</artifactId>
171
-                    <scope>test</scope>
172
-                </dependency>
173
-            </dependencies>
174
-            <build>
175
-                <plugins>
176
-                    <plugin>
177
-                        <groupId>org.graalvm.buildtools</groupId>
178
-                        <artifactId>native-maven-plugin</artifactId>
179
-                        <version>${native-buildtools.version}</version>
180
-                        <extensions>true</extensions>
181
-                        <executions>
182
-                            <execution>
183
-                                <id>test-native</id>
184
-                                <phase>test</phase>
185
-                                <goals>
186
-                                    <goal>test</goal>
187
-                                </goals>
188
-                            </execution>
189
-                            <execution>
190
-                                <id>build-native</id>
191
-                                <phase>package</phase>
192
-                                <goals>
193
-                                    <goal>build</goal>
194
-                                </goals>
195
-                            </execution>
196
-                        </executions>
197
-                    </plugin>
198
-                </plugins>
199
-            </build>
200
-        </profile>
201
-    </profiles>
202 83
 
203 84
 </project>

+ 2 - 0
src/main/java/com/szls/nstths/NstthsApplication.java

@@ -1,9 +1,11 @@
1 1
 package com.szls.nstths;
2 2
 
3
+import org.mybatis.spring.annotation.MapperScan;
3 4
 import org.springframework.boot.SpringApplication;
4 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 6
 
6 7
 @SpringBootApplication
8
+@MapperScan("com.szls.nstths.mapper")
7 9
 public class NstthsApplication {
8 10
 
9 11
     public static void main(String[] args) {

+ 25 - 0
src/main/java/com/szls/nstths/controller/UserController.java

@@ -0,0 +1,25 @@
1
+package com.szls.nstths.controller;
2
+
3
+
4
+import com.szls.nstths.mapper.UserMapper;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.web.bind.annotation.GetMapping;
7
+import org.springframework.web.bind.annotation.RequestParam;
8
+import org.springframework.web.bind.annotation.RestController;
9
+
10
+@RestController
11
+public class UserController {
12
+
13
+    private UserMapper userMapper;
14
+
15
+    @Autowired
16
+    public void setUserMapper(UserMapper userMapper) {
17
+        this.userMapper = userMapper;
18
+    }
19
+
20
+    @GetMapping("/hello")
21
+    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
22
+        userMapper.selectList(null);
23
+        return String.format("Hello %s!", name);
24
+    }
25
+}

+ 16 - 0
src/main/java/com/szls/nstths/entity/User.java

@@ -0,0 +1,16 @@
1
+package com.szls.nstths.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableId;
4
+import com.baomidou.mybatisplus.annotation.TableName;
5
+import lombok.Data;
6
+
7
+@Data
8
+@TableName("sys_user")
9
+public class User {
10
+    @TableId
11
+    private Long id;
12
+    private String name;
13
+    private String email;
14
+    private Integer age;
15
+
16
+}

+ 8 - 0
src/main/java/com/szls/nstths/mapper/UserMapper.java

@@ -0,0 +1,8 @@
1
+package com.szls.nstths.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.szls.nstths.entity.User;
5
+
6
+public interface UserMapper extends BaseMapper<User> {
7
+
8
+}

+ 0 - 1
src/main/resources/application.properties

@@ -1 +0,0 @@
1
-

+ 13 - 0
src/main/resources/application.yml

@@ -0,0 +1,13 @@
1
+# DataSource Config
2
+spring:
3
+  datasource:
4
+    driver-class-name: com.mysql.cj.jdbc.Driver
5
+    username: root
6
+    password: 123456
7
+    url: jdbc:mysql://36.134.100.155:3306/nstths?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
8
+  thymeleaf:
9
+    check-template-location: false
10
+# Logger Config
11
+logging:
12
+  level:
13
+    com.szls.nstths: debug

+ 25 - 0
src/test/java/com/szls/nstths/NstthsApplicationTests.java

@@ -1,13 +1,38 @@
1 1
 package com.szls.nstths;
2 2
 
3
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
4
+import com.baomidou.mybatisplus.generator.config.OutputFile;
5
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
3 6
 import org.junit.jupiter.api.Test;
4 7
 import org.springframework.boot.test.context.SpringBootTest;
5 8
 
9
+import java.util.Collections;
10
+
6 11
 @SpringBootTest
7 12
 class NstthsApplicationTests {
8 13
 
9 14
     @Test
10 15
     void contextLoads() {
16
+
17
+        FastAutoGenerator.create("url", "username", "password")
18
+                .globalConfig(builder -> {
19
+                    builder.author("baomidou") // 设置作者
20
+                            .enableSwagger() // 开启 swagger 模式
21
+                            .fileOverride() // 覆盖已生成文件
22
+                            .outputDir("D://"); // 指定输出目录
23
+                })
24
+                .packageConfig(builder -> {
25
+                    builder.parent("com.baomidou.mybatisplus.samples.generator") // 设置父包名
26
+                            .moduleName("system") // 设置父包模块名
27
+                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://")); // 设置mapperXml生成路径
28
+                })
29
+                .strategyConfig(builder -> {
30
+                    builder.addInclude("t_simple") // 设置需要生成的表名
31
+                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
32
+                })
33
+                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
34
+                .execute();
35
+
11 36
     }
12 37
 
13 38
 }

+ 27 - 0
src/test/java/com/szls/nstths/SampleTest.java

@@ -0,0 +1,27 @@
1
+package com.szls.nstths;
2
+
3
+import com.szls.nstths.entity.User;
4
+import com.szls.nstths.mapper.UserMapper;
5
+import org.junit.jupiter.api.Assertions;
6
+import org.junit.jupiter.api.Test;
7
+import org.mybatis.spring.annotation.MapperScan;
8
+import org.springframework.boot.test.context.SpringBootTest;
9
+
10
+import javax.annotation.Resource;
11
+import java.util.List;
12
+
13
+@SpringBootTest
14
+public class SampleTest {
15
+
16
+    @Resource
17
+    private UserMapper userMapper;
18
+
19
+    @Test
20
+    public void testSelect() {
21
+        System.out.println(("----- selectAll method test ------"));
22
+        List<User> userList = userMapper.selectList(null);
23
+        //Assertions.assertEquals(5, userList.size());
24
+        userList.forEach(System.out::println);
25
+    }
26
+
27
+}