依赖包:
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 http://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.1.1.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>org.springboot</groupId> 12 <artifactId>demo</artifactId> 13 <version>1.0.1-SNAPSHOT</version> 14 <name>boot_demo</name> 15 <description>Demo project for Spring Boot</description> 16 17 <properties> 18 <java.version>1.8</java.version> 19 <dom4j.version>1.6.1</dom4j.version> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>org.springframework.boot</groupId> 25 <artifactId>spring-boot-starter</artifactId> 26 </dependency> 27 28 <dependency> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-starter-test</artifactId> 31 <scope>test</scope> 32 </dependency> 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-web</artifactId> 36 </dependency> 37 38 <dependency> 39 <groupId>org.springframework.boot</groupId> 40 <artifactId>spring-boot-devtools</artifactId> 41 <optional>true</optional> 42 </dependency> 43 44 <!-- 引入freemarker包 --> 45 <dependency> 46 <groupId>org.springframework.boot</groupId> 47 <artifactId>spring-boot-starter-freemarker</artifactId> 48 </dependency> 49 50 <dependency> 51 <groupId>org.springframework.boot</groupId> 52 <artifactId>spring-boot-starter-thymeleaf</artifactId> 53 </dependency> 54 55 <dependency> 56 <groupId>org.springframework.boot</groupId> 57 <artifactId>spring-boot-starter-data-jpa</artifactId> 58 </dependency> 59 60 <dependency> 61 <groupId>mysql</groupId> 62 <artifactId>mysql-connector-java</artifactId> 63 <scope>runtime</scope> 64 </dependency> 65 66 <dependency> 67 <groupId>org.springframework.boot</groupId> 68 <artifactId>spring-boot-starter-jdbc</artifactId> 69 </dependency> 70 71 <dependency> 72 <groupId>org.mybatis.spring.boot</groupId> 73 <artifactId>mybatis-spring-boot-autoconfigure</artifactId> 74 <version>1.3.2</version> 75 </dependency> 76 77 <dependency> 78 <groupId>commons-io</groupId> 79 <artifactId>commons-io</artifactId> 80 <version>2.6</version> 81 </dependency> 82 83 <dependency> 84 <groupId>org.mybatis</groupId> 85 <artifactId>mybatis</artifactId> 86 <version>3.4.6</version> 87 </dependency> 88 89 <dependency> 90 <groupId>org.mybatis</groupId> 91 <artifactId>mybatis-spring</artifactId> 92 <version>1.3.2</version> 93 </dependency> 94 95 <!-- spring事务 --> 96 <dependency> 97 <groupId>org.springframework</groupId> 98 <artifactId>spring-tx</artifactId> 99 </dependency> 100 101 <dependency> 102 <groupId>dom4j</groupId> 103 <artifactId>dom4j</artifactId> 104 <version>${dom4j.version}</version> 105 </dependency> 106 </dependencies> 107 108 <build> 109 <plugins> 110 <plugin> 111 <groupId>org.springframework.boot</groupId> 112 <artifactId>spring-boot-maven-plugin</artifactId> 113 <configuration> 114 <fork>true</fork> 115 </configuration> 116 </plugin> 117 </plugins> 118 </build> 119 120 </project>
配置文件application.properties:
#数据库配置 spring.datasource.url=jdbc:mysql://20.1.1.11:16306/gxrdb?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=root spring.datasource.driverClassNamee=com.mysql.jdbc.Driver #mybatis.config-locations=classpath:mybatis/mybatis-config.xml mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=org.springboot.model
model:
1 package org.springboot.model; 2 3 /** 4 * @Auther:GongXingRui 5 * @Date:2018/12/24 6 * @Description: 7 **/ 8 public class Student { 9 private String id; 10 private String name; 11 private String gender; 12 private int age; 13 private String telephone; 14 15 public Student() { 16 17 } 18 19 public Student(String id, String name, String gender) { 20 this.id = id; 21 this.name = name; 22 this.gender = gender; 23 } 24 25 public Student(String id, String name, String gender, int age, String telephone) { 26 this.id = id; 27 this.name = name; 28 this.gender = gender; 29 this.age = age; 30 this.telephone = telephone; 31 } 32 33 public String getId() { 34 return id; 35 } 36 37 public void setId(String id) { 38 this.id = id; 39 } 40 41 public String getName() { 42 return name; 43 } 44 45 public void setName(String name) { 46 this.name = name; 47 } 48 49 public String getGender() { 50 return gender; 51 } 52 53 public void setGender(String gender) { 54 this.gender = gender; 55 } 56 57 public int getAge() { 58 return age; 59 } 60 61 public void setAge(int age) { 62 this.age = age; 63 } 64 65 public String getTelephone() { 66 return telephone; 67 } 68 69 public void setTelephone(String telephone) { 70 this.telephone = telephone; 71 } 72 73 @Override 74 public String toString() { 75 return "Student{" + 76 "id='" + id + '\'' + 77 ", name='" + name + '\'' + 78 ", gender='" + gender + '\'' + 79 ", age=" + age + 80 ", telephone='" + telephone + '\'' + 81 '}'; 82 } 83 }