TOP

SpringBoot整合Mybatis(CRUD的实现)(一)
2019-09-06 00:26:39 】 浏览:69
Tags:SpringBoot 整合 Mybatis CRUD 实现

准备工具:IDEA   jdk1.8  Navicat for MySQL  Postman

 

一、新建Project

选择依赖:mybatis  Web  Mysql  JDBC

项目结构

pom依赖:

 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.1.7.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.beilin</groupId>
12     <artifactId>SpringBoot-Mybatis</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>SpringBoot-Mybatis</name>
15     <description>Demo project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19     </properties>
20     <dependencies>
21         <dependency>
22             <groupId>org.springframework.boot</groupId>
23             <artifactId>spring-boot-starter-jdbc</artifactId>
24         </dependency>
25         <dependency>
26             <groupId>org.springframework.boot</groupId>
27             <artifactId>spring-boot-starter-web</artifactId>
28         </dependency>
29 
30         <!--导入mybatis依赖-->
31         <dependency>
32             <groupId>org.mybatis.spring.boot</groupId>
33             <artifactId>mybatis-spring-boot-starter</artifactId>
34             <version>2.1.0</version>
35         </dependency>
36 
37         <!--导入mysql依赖-->
38         <dependency>
39             <groupId>mysql</groupId>
40             <artifactId>mysql-connector-java</artifactId>
41             <version>5.1.47</version>
42         </dependency>
43 
44         <dependency>
45             <groupId>org.springframework.boot</groupId>
46             <artifactId>spring-boot-starter-test</artifactId>
47             <scope>test</scope>
48         </dependency>
49     </dependencies>
50 
51     <build>
52         <plugins>
53             <plugin>
54                 <groupId>org.springframework.boot</groupId>
55                 <artifactId>spring-boot-maven-plugin</artifactId>
56             </plugin>
57         </plugins>
58     </build>
59 
60 </project>
pom.xml

二、创建user表

 

 

 、项目配置

1 .在com.beilin下创建controller包、mapper包,entity包;在resources文件夹下创建mapping文件夹(用来存放mapper映射的xml文件)

 

 

 2 .添加properties配置文件:application.properties

 1 #配置mybatis
 2 
 3 #配置xml映射路径
 4 mybatis.mapper-locations=classpath:mapping/*.xml
 5 #配置实体类别名
 6 mybatis.type-aliases-package=com.beilin.entity
 7 #开启驼峰命名法
 8 mybatis.configuration.map-underscore-to-camel-case=true
 9 
10 #配置Mysql连接
11 spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
12 s  
		
SpringBoot整合Mybatis(CRUD的实现)(一) https://www.cppentry.com/bencandy.php?fid=102&id=250200

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇什么是SEO?SEO能做什么! 下一篇IIS 程序池优化配置方案