SpringBoot的搭建
1.创建一个maven项目
2.在其pom.xml中配置
<!-- 配置属性 -->
<!--springboot的指定jdk-->
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<!-- springboot父节点依赖 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<!-- web依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 热部署工具 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--必须有才能编译jsp -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mysql 数据库驱动. -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- spring-boot mybatis依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!-- spring boot mybatis 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.2</version>
</dependency>
<!-- 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 热部署 -->
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
<!-- mapper.xml 扫描 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
3.创建一个启动类
@SpringBootApplication
public class RunAPP {
public static void main(String[] args) {
SpringApplication.run(RunAPP.class, args);
}
4.准备一个controller来测试
@RestController
public class helloController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
使用浏览器输入localhost:8080/hello访问,出现一下图,就说明springboot配置成功
5.在application.yml中配置关于mybatis的配置
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot-demo?useUnicode=true&characterEncoding=utf-8
username: root
password: 123456
# Mybatis配置
mybatis:
typeAliasesPackage: cn.itsource.domain
mapperLocations: classpath:cn/itsource/dao/mapper/*.xml
6.创建以下实现类
并进行测试crud
如果需要用注解写sql语句,需要加一个@mapper注解