Bootstrap

spring boot 的一些高级用法

1  spring boot 项目的创建

参考 https://www.cnblogs.com/PerZhu/p/10708809.html

2  首先我们先把Maven里面的配置完成

 

 1 <dependencies>
 2         <dependency>
 3             <groupId>org.springframework.boot</groupId>
 4             <artifactId>spring-boot-starter-actuator</artifactId>
 5         </dependency>
 6         <dependency>
 7             <groupId>org.springframework.boot</groupId>
 8             <artifactId>spring-boot-starter-data-jpa</artifactId>
 9         </dependency>
10         <dependency>
11             <groupId>org.springframework.boot</groupId>
12             <artifactId>spring-boot-starter-thymeleaf</artifactId>
13         </dependency>
14         <dependency>
15             <groupId>org.springframework.boot</groupId>
16             <artifactId>spring-boot-starter-web</artifactId>
17         </dependency>
18         <dependency>
19             <groupId>org.mybatis.spring.boot</groupId>
20             <artifactId>mybatis-spring-boot-starter</artifactId>
21             <version>2.0.1</version>
22         </dependency>
23 
24         <dependency>
25             <groupId>mysql</groupId>
26             <artifactId>mysql-connector-java</artifactId>
27             <scope>runtime</scope>
28         </dependency>
29         <dependency>
30             <groupId>org.springframework.boot</groupId>
31             <artifactId>spring-boot-starter-tomcat</artifactId>
32             <scope>provided</scope>
33         </dependency>
34         <dependency>
35             <groupId>org.springframework.boot</groupId>
36             <artifactId>spring-boot-starter-test</artifactId>
37             <scope>test</scope>
38         </dependency>
39     </dependencies>

 

 3  属性配置建议使用application.yml,里面用来配置数据库的连接,还有数据库里面表的创建方式,和端口号的选择

 

Controller处理http注解

Controller需要和模板一起使用(简单了解即可),首先需要在maven里面加入

1 <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-thymeleaf</artifactId>
4         </dependency>

 

 

 

 

 

 

 

 

 

4  URL 注解的使用

 

 5  数据库的操作

首先添加注解

1 <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-data-jpa</artifactId>
4         </dependency>
5 <dependency>
6             <groupId>mysql</groupId>
7             <artifactId>mysql-connector-java</artifactId>
8             <scope>runtime</scope>
9         </dependency>

创建一个Girl类来对应数据库里面的表

 1 package com.zzy;
 2 
 3 import javax.persistence.Entity;
 4 import javax.persistence.GeneratedValue;
 5 import javax.persistence.Id;
 6 
 7 @Entity
 8 
 9 public class Girl {
10     @Id
11     @GeneratedValue
12     private Integer id;
13 
14     private Integer age;
15 
16     private String height;
17 
18 
19     public Girl() {
20     }
21 
22     public Integer getId() {
23         return id;
24     }
25 
26     public void setId(Integer id) {
27         this.id = id;
28     }
29 
30     public String getHeight() {
31         return height;
32     }
33 
34     public void setHeight(String height) {
35         this.height = height;
36     }
37 
38     public Integer getAge() {
39         return age;
40     }
41 
42     public void setAge(Integer age) {
43         this.age = age;
44     }
45 
46     @Override
47     public String toString() {
48         return "Girl{" +
49                 "id=" + id +
50                 ", age=" + age +
51                 ", height='" + height + '\'' +
52                 '}';
53     }
54 }

 

创建刚开始的几个接口

 创建一个接口

 

 

添加一个女生

查询一个女生

更新一条记录

删除一条记录

数据库的增,更,删,填,都具备了

通过年龄来查询

 

转载于:https://www.cnblogs.com/PerZhu/p/10897263.html

;