Skip to content

Commit 920828f

Browse files
committed
删除idea自动生成无用代码
1 parent 91f9a6b commit 920828f

File tree

10 files changed

+333
-0
lines changed

10 files changed

+333
-0
lines changed

Spring-Boot-Mybatis/pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.5.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>mybatis</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>Spring-Boot-Mybatis</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<!--web依赖-->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<!--mybatis依赖-->
28+
<dependency>
29+
<groupId>org.mybatis.spring.boot</groupId>
30+
<artifactId>mybatis-spring-boot-starter</artifactId>
31+
<version>2.1.1</version>
32+
</dependency>
33+
<!--mysql数据库驱动依赖-->
34+
<dependency>
35+
<groupId>mysql</groupId>
36+
<artifactId>mysql-connector-java</artifactId>
37+
</dependency>
38+
<!--Druid数据源-->
39+
<dependency>
40+
<groupId>com.alibaba</groupId>
41+
<artifactId>druid-spring-boot-starter</artifactId>
42+
<version>1.1.21</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-test</artifactId>
47+
<scope>test</scope>
48+
<exclusions>
49+
<exclusion>
50+
<groupId>org.junit.vintage</groupId>
51+
<artifactId>junit-vintage-engine</artifactId>
52+
</exclusion>
53+
</exclusions>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.mybatis;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringBootMybatisApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringBootMybatisApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.example.mybatis.bean;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Created by dengzhiming on 2019/3/21
7+
*/
8+
public class Student implements Serializable {
9+
private static final long serialVersionUID = -339516038496531943L;
10+
private String sno;
11+
private String name;
12+
private String sex;
13+
14+
public Student() {
15+
}
16+
17+
public static long getSerialVersionUID() {
18+
return serialVersionUID;
19+
}
20+
21+
public String getSno() {
22+
return sno;
23+
}
24+
25+
public void setSno(String sno) {
26+
this.sno = sno;
27+
}
28+
29+
public String getName() {
30+
return name;
31+
}
32+
33+
public void setName(String name) {
34+
this.name = name;
35+
}
36+
37+
public String getSex() {
38+
return sex;
39+
}
40+
41+
public void setSex(String sex) {
42+
this.sex = sex;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.mybatis.controller;
2+
3+
import com.example.mybatis.bean.Student;
4+
import com.example.mybatis.service.StudentService;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import javax.annotation.Resource;
10+
11+
/**
12+
* Created by dengzhiming on 2019/3/21
13+
*/
14+
@RestController
15+
public class TestController {
16+
@Resource
17+
private StudentService service;
18+
19+
@GetMapping("/querystudent/{sno}")
20+
public Student queryStudentBySno(@PathVariable String sno) {
21+
return this.service.queryStudentById(sno);
22+
}
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.example.mybatis.mapper;
2+
3+
import com.example.mybatis.bean.Student;
4+
import org.apache.ibatis.annotations.Mapper;
5+
import org.springframework.stereotype.Repository;
6+
7+
/**
8+
* Created by dengzhiming on 2019/3/21
9+
*/
10+
@Repository
11+
@Mapper
12+
public interface StudentMapper {
13+
//@Insert("insert into student(sno,sname,ssex) values(#{sno},#{name},#{sex})")
14+
int add(Student student);
15+
16+
//@Update("update student set sname=#{name},ssex=#{sex} where sno=#{sno}")
17+
int update(Student student);
18+
19+
//@Delete("delete from student where sno=#{sno}")
20+
int deleteById(String sno);
21+
22+
//@Select("select * from student where sno=#{sno}")
23+
/*@Results(id = "student", value = {
24+
@Result(property = "sno", column = "sno", javaType = String.class),
25+
@Result(property = "name", column = "sname", javaType = String.class),
26+
@Result(property = "sex", column = "ssex", javaType = String.class)
27+
})*/
28+
Student queryStudentById(String sno);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.mybatis.service;
2+
3+
import com.example.mybatis.bean.Student;
4+
5+
/**
6+
* Created by dengzhiming on 2019/3/21
7+
*/
8+
public interface StudentService {
9+
int add(Student student);
10+
11+
int update(Student student);
12+
13+
int deleteById(String sno);
14+
15+
Student queryStudentById(String sno);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example.mybatis.service.impl;
2+
3+
import com.example.mybatis.bean.Student;
4+
import com.example.mybatis.mapper.StudentMapper;
5+
import com.example.mybatis.service.StudentService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Service;
8+
9+
/**
10+
* Created by dengzhiming on 2019/3/21
11+
*/
12+
@Service
13+
public class StudentServiceImpl implements StudentService {
14+
@Autowired
15+
private StudentMapper studentMapper;
16+
17+
@Override
18+
public int add(Student student) {
19+
return this.studentMapper.add(student);
20+
}
21+
22+
@Override
23+
public int update(Student student) {
24+
return this.studentMapper.update(student);
25+
}
26+
27+
@Override
28+
public int deleteById(String sno) {
29+
return this.studentMapper.deleteById(sno);
30+
}
31+
32+
@Override
33+
public Student queryStudentById(String sno) {
34+
return this.studentMapper.queryStudentById(sno);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
server:
2+
servlet:
3+
context-path: /web
4+
5+
spring:
6+
datasource:
7+
druid:
8+
#数据库访问配置,使用Druid数据源
9+
driver-class-name: com.mysql.cj.jdbc.Driver
10+
url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8
11+
username: root
12+
password: root
13+
14+
# 连接池配置
15+
initial-size: 5
16+
min-idle: 5
17+
max-active: 20
18+
# 连接等待超时时间
19+
max-wait: 30000
20+
# 配置检测可以关闭的空闲连接间隔时间(检测空闲连接的周期)
21+
time-between-eviction-runs-millis: 60000
22+
# 配置连接在池中的最小生存时间
23+
min-evictable-idle-time-millis: 300000
24+
validation-query: select '1' from dual
25+
test-while-idle: true
26+
test-on-borrow: false
27+
test-on-return: false
28+
# 打开PSCache,并且指定每个连接上PSCache的大小
29+
pool-prepared-statements: true
30+
max-open-prepared-statements: 20
31+
max-pool-prepared-statement-per-connection-size: 20
32+
# 配置监控统计拦截的filters, 去掉后监控界面sql无法统计, 'wall'用于防火墙
33+
filters: stat,wall
34+
# Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔
35+
aop-patterns: com.springboot.service.*
36+
37+
# WebStatFilter配置
38+
web-stat-filter:
39+
enabled: true
40+
# 添加过滤规则
41+
url-pattern: /*
42+
# 忽略过滤的格式
43+
exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
44+
45+
# StatViewServlet配置
46+
stat-view-servlet:
47+
enabled: true
48+
# 访问路径为/druid时,跳转到StatViewServlet
49+
url-pattern: /druid/*
50+
# 是否能够重置数据
51+
reset-enable: false
52+
# 需要账号密码才能访问控制台
53+
login-username: admin
54+
login-password: admin
55+
# IP白名单
56+
# allow: 127.0.0.1
57+
# IP黑名单(共同存在时,deny优先于allow)
58+
# deny: 192.168.1.218
59+
60+
# 配置StatFilter
61+
filter:
62+
stat:
63+
log-slow-sql: true
64+
65+
mybatis:
66+
# type-aliases扫描路径
67+
# type-aliases-package:
68+
# com xml实现扫描路径
69+
mapper-locations: classpath:/mapper/*.xml
70+
configuration:
71+
# SQL日志输出
72+
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3+
<mapper namespace="com.example.mybatis.mapper.StudentMapper">
4+
<insert id="add">
5+
insert into student(sno,sname,ssex) values(#{sno},#{name},#{sex})
6+
</insert>
7+
<update id="update">
8+
update student set sname=#{name},ssex=#{sex} where sno=#{sno}
9+
</update>
10+
<delete id="deleteById">
11+
delete from student where sno=#{id}
12+
</delete>
13+
<select id="queryStudentById" resultType="com.example.mybatis.bean.Student">
14+
select
15+
sno sno
16+
,sname name
17+
,ssex sex
18+
from student where sno=#{id}
19+
</select>
20+
</mapper>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.mybatis;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class SpringBootMybatisApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)