diff --git a/pom.xml b/pom.xml index d3fb5a9..3de3247 100644 --- a/pom.xml +++ b/pom.xml @@ -14,12 +14,12 @@ space.caoshd - app1 + kotlin-app 1.0.0-SNAPSHOT - app1 + kotlin-app - App1 + kotlin-app 17 @@ -27,11 +27,6 @@ - - space.caoshd - bootstrap - 1.0.0-SNAPSHOT - com.alibaba diff --git a/src/main/kotlin/space/caoshd/app/Application.kt b/src/main/kotlin/space/caoshd/app/Application.kt new file mode 100644 index 0000000..70267a0 --- /dev/null +++ b/src/main/kotlin/space/caoshd/app/Application.kt @@ -0,0 +1,11 @@ +package space.caoshd.app + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication + +@SpringBootApplication +class Application + +fun main(args: Array) { + SpringApplication.run(Application::class.java, *args) +} diff --git a/src/main/kotlin/space/caoshd/app/config/MybatisConfig.kt b/src/main/kotlin/space/caoshd/app/config/MybatisConfig.kt new file mode 100644 index 0000000..3fe9e2a --- /dev/null +++ b/src/main/kotlin/space/caoshd/app/config/MybatisConfig.kt @@ -0,0 +1,9 @@ +package space.caoshd.app.config + +import org.mybatis.spring.annotation.MapperScan +import org.springframework.context.annotation.Configuration + +@Configuration +@MapperScan("space.caoshd.app") +class MybatisConfig { +} \ No newline at end of file diff --git a/src/main/kotlin/space/caoshd/app1/controller/UserController.kt b/src/main/kotlin/space/caoshd/app/controller/UserController.kt similarity index 80% rename from src/main/kotlin/space/caoshd/app1/controller/UserController.kt rename to src/main/kotlin/space/caoshd/app/controller/UserController.kt index 7eafe5d..29408c4 100644 --- a/src/main/kotlin/space/caoshd/app1/controller/UserController.kt +++ b/src/main/kotlin/space/caoshd/app/controller/UserController.kt @@ -1,11 +1,11 @@ -package space.caoshd.app1.controller +package space.caoshd.app.controller import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import space.caoshd.app1.entity.User -import space.caoshd.app1.mapper.UserMapper +import space.caoshd.app.entity.User +import space.caoshd.app.mapper.UserMapper @RestController @RequestMapping("/user") diff --git a/src/main/kotlin/space/caoshd/app1/entity/User.kt b/src/main/kotlin/space/caoshd/app/entity/User.kt similarity index 78% rename from src/main/kotlin/space/caoshd/app1/entity/User.kt rename to src/main/kotlin/space/caoshd/app/entity/User.kt index 0a56d19..6cccc98 100644 --- a/src/main/kotlin/space/caoshd/app1/entity/User.kt +++ b/src/main/kotlin/space/caoshd/app/entity/User.kt @@ -1,4 +1,4 @@ -package space.caoshd.app1.entity; +package space.caoshd.app.entity; import java.io.Serializable; diff --git a/src/main/kotlin/space/caoshd/app/mapper/UserMapper.kt b/src/main/kotlin/space/caoshd/app/mapper/UserMapper.kt new file mode 100644 index 0000000..3087794 --- /dev/null +++ b/src/main/kotlin/space/caoshd/app/mapper/UserMapper.kt @@ -0,0 +1,7 @@ +package space.caoshd.app.mapper + +import space.caoshd.app.entity.User + +interface UserMapper { + fun listUser(user: User): List +} \ No newline at end of file diff --git a/src/main/kotlin/space/caoshd/app1/Application.kt b/src/main/kotlin/space/caoshd/app1/Application.kt deleted file mode 100644 index 048f156..0000000 --- a/src/main/kotlin/space/caoshd/app1/Application.kt +++ /dev/null @@ -1,9 +0,0 @@ -package space.caoshd.app1 - -import org.mybatis.spring.annotation.MapperScan -import org.springframework.boot.autoconfigure.SpringBootApplication -import space.caoshd.BootstrapApplication - -@SpringBootApplication -@MapperScan("space.caoshd") -class Application : BootstrapApplication() diff --git a/src/main/kotlin/space/caoshd/app1/mapper/UserMapper.kt b/src/main/kotlin/space/caoshd/app1/mapper/UserMapper.kt deleted file mode 100644 index c07ed73..0000000 --- a/src/main/kotlin/space/caoshd/app1/mapper/UserMapper.kt +++ /dev/null @@ -1,7 +0,0 @@ -package space.caoshd.app1.mapper - -import space.caoshd.app1.entity.User - -interface UserMapper { - fun listUser(user: User): List -} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ba9f3d6..fe499ae 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,11 @@ server.port=8080 mybatis.mapper-locations=classpath*:mapper/**/*Mapper.xml -spring.datasource.url=jdbc:h2:file:~/.h2/app1 +spring.datasource.url=jdbc:h2:file:~/.h2/app spring.datasource.username=root spring.datasource.password=root -spring.datasource.driver-class-name=org.h2.Driver \ No newline at end of file +spring.datasource.driver-class-name=org.h2.Driver + +spring.sql.init.mode=always +spring.sql.init.schema-locations=classpath:script/schema.sql +spring.sql.init.data-locations=classpath:script/data.sql \ No newline at end of file diff --git a/src/main/resources/mapper/space/caoshd/app1/mapper/UserMapper.xml b/src/main/resources/mapper/space/caoshd/app/mapper/UserMapper.xml similarity index 59% rename from src/main/resources/mapper/space/caoshd/app1/mapper/UserMapper.xml rename to src/main/resources/mapper/space/caoshd/app/mapper/UserMapper.xml index 17a3575..20e4474 100644 --- a/src/main/resources/mapper/space/caoshd/app1/mapper/UserMapper.xml +++ b/src/main/resources/mapper/space/caoshd/app/mapper/UserMapper.xml @@ -1,9 +1,9 @@ - + - SELECT * FROM T_USER; diff --git a/src/main/resources/script/data.sql b/src/main/resources/script/data.sql new file mode 100644 index 0000000..9ca31d0 --- /dev/null +++ b/src/main/resources/script/data.sql @@ -0,0 +1,3 @@ +INSERT INTO T_USER (USERNAME, AGE) VALUES ('张三', '18'); +INSERT INTO T_USER (USERNAME, AGE) VALUES ('李四', '20'); +INSERT INTO T_USER (USERNAME, AGE) VALUES ('王五', '22'); \ No newline at end of file diff --git a/src/main/resources/script/schema.sql b/src/main/resources/script/schema.sql new file mode 100644 index 0000000..3289184 --- /dev/null +++ b/src/main/resources/script/schema.sql @@ -0,0 +1,6 @@ +DROP TABLE IF EXISTS T_USER ; +CREATE TABLE T_USER ( + ID BIGINT AUTO_INCREMENT PRIMARY KEY, + USERNAME VARCHAR(255) NOT NULL, + AGE INT +); \ No newline at end of file diff --git a/src/main/resources/static/scripts/schema.sql b/src/main/resources/static/scripts/schema.sql deleted file mode 100644 index 7d63c84..0000000 --- a/src/main/resources/static/scripts/schema.sql +++ /dev/null @@ -1,9 +0,0 @@ -DROP TABLE IF EXISTS T_USER ; -CREATE TABLE T_USER ( - ID BIGINT AUTO_INCREMENT PRIMARY KEY, - USERNAME VARCHAR(255) NOT NULL, - AGE INT -); -INSERT INTO T_USER (USERNAME, AGE) VALUES ('张三', '18'); -INSERT INTO T_USER (USERNAME, AGE) VALUES ('李四', '20'); -INSERT INTO T_USER (USERNAME, AGE) VALUES ('王五', '22'); \ No newline at end of file diff --git a/src/test/kotlin/space/caoshd/app1/BootstrapApplicationTests.kt b/src/test/kotlin/space/caoshd/app/BootstrapApplicationTests.kt similarity index 87% rename from src/test/kotlin/space/caoshd/app1/BootstrapApplicationTests.kt rename to src/test/kotlin/space/caoshd/app/BootstrapApplicationTests.kt index 55134fd..b6ef6c4 100644 --- a/src/test/kotlin/space/caoshd/app1/BootstrapApplicationTests.kt +++ b/src/test/kotlin/space/caoshd/app/BootstrapApplicationTests.kt @@ -1,4 +1,4 @@ -package space.caoshd.app1 +package space.caoshd.app import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest