一、创建项目
二、添加依赖
- <dependencies>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </dependency>
-
- <!--mybatis与spring boot整合依赖-->
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.3.2</version>
- </dependency>
-
- <!--mysql驱动-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.47</version>
- </dependency>
-
- <!-- druid驱动 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- <version>1.1.12</version>
- </dependency>
-
- <!--tomcat内置的JSP解析器-->
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <resources>
- <!--注册dao包下mybatis映射文件为资源目录-->
- <resource>
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.xml</include>
- </includes>
- </resource>
- <!--注册webapp目录为资源目录-->
- <resource>
- <directory>src/main/webapp</directory>
- <targetPath>META-INF/resources</targetPath>
- <includes>
- <include>**/*.*</include>
- </includes>
- </resource>
- </resources>
-
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
三、创建实体类
四、创建接口
五、创建接口实现类
六、创建dao层
七、创建mappin文件
八、配置核心文件
- # 视图的前辍与后辍
- spring:
- mvc:
- view:
- prefix: /
- suffix: .jsp
-
- # 注册数据源
- datasource:
- type: com.alibaba.druid.pool.DruidDataSource
- driver-class-name: com.mysql.jdbc.Driver
- url: jdbc:mysql:///test?useUnicode=true&characterEncoding=utf-8
- username: root
- password: root
-
- #编码设置
- http:
- encoding:
- force: true
- charset: utf-8
- enabled: true
- server:
- tomcat:
- uri-encoding: UTF-8
-
- mybatis:
- # 注册映射文件
- mapper-locations: classpath:com/abc/dao/*.xml
- # 注册实体类别名
- type-aliases-package: com.abc.bean