修正
This commit is contained in:
33
springboot_05_mybatis/.gitignore
vendored
Normal file
33
springboot_05_mybatis/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
47
springboot_05_mybatis/pom.xml
Normal file
47
springboot_05_mybatis/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.yv</groupId>
|
||||
<artifactId>springboot_05_mybatis</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springboot_05_mybatis</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.49</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
package com.yv;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Springboot05MybatisApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Springboot05MybatisApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
19
springboot_05_mybatis/src/main/java/com/yv/dao/BookDao.java
Normal file
19
springboot_05_mybatis/src/main/java/com/yv/dao/BookDao.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.yv.dao;
|
||||
|
||||
import com.yv.domain.Book;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
* @date 2023/3/9 下午 3:25
|
||||
*/
|
||||
@Mapper
|
||||
public interface BookDao {
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from tbl_book where id = #{id}")
|
||||
public Book getById(Integer id);
|
||||
}
|
55
springboot_05_mybatis/src/main/java/com/yv/domain/Book.java
Normal file
55
springboot_05_mybatis/src/main/java/com/yv/domain/Book.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.yv.domain;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
* @date 2023/3/9 下午 3:23
|
||||
*/
|
||||
|
||||
public class Book {
|
||||
private Integer id;
|
||||
private String type;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Book{" +
|
||||
"id=" + id +
|
||||
", type='" + type + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
8
springboot_05_mybatis/src/main/resources/application.yml
Normal file
8
springboot_05_mybatis/src/main/resources/application.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
#??????
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ssm_db?useSSL=false
|
||||
username: root
|
||||
password: 8520
|
@@ -0,0 +1,19 @@
|
||||
package com.yv;
|
||||
|
||||
import com.yv.dao.BookDao;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Springboot05MybatisApplicationTests {
|
||||
@Autowired
|
||||
private BookDao bookDao;
|
||||
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
System.out.println(bookDao.getById(1));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user