初始化自动创建数据库

master
曹世达 5 months ago
parent 5f11702cd6
commit 66923f5415

@ -14,12 +14,12 @@
</parent>
<groupId>space.caoshd</groupId>
<artifactId>app1</artifactId>
<artifactId>kotlin-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>app1</name>
<name>kotlin-app</name>
<description>App1</description>
<description>kotlin-app</description>
<properties>
<java.version>17</java.version>
@ -27,11 +27,6 @@
</properties>
<dependencies>
<dependency>
<groupId>space.caoshd</groupId>
<artifactId>bootstrap</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>

@ -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<String>) {
SpringApplication.run(Application::class.java, *args)
}

@ -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 {
}

@ -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")

@ -1,4 +1,4 @@
package space.caoshd.app1.entity;
package space.caoshd.app.entity;
import java.io.Serializable;

@ -0,0 +1,7 @@
package space.caoshd.app.mapper
import space.caoshd.app.entity.User
interface UserMapper {
fun listUser(user: User): List<User>
}

@ -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()

@ -1,7 +0,0 @@
package space.caoshd.app1.mapper
import space.caoshd.app1.entity.User
interface UserMapper {
fun listUser(user: User): List<User>
}

@ -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
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

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="space.caoshd.app1.mapper.UserMapper">
<mapper namespace="space.caoshd.app.mapper.UserMapper">
<select id="listUser" resultType="space.caoshd.app1.entity.User">
<select id="listUser" resultType="space.caoshd.app.entity.User">
SELECT * FROM T_USER;
</select>

@ -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');

@ -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
);

@ -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');

@ -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
Loading…
Cancel
Save