好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

SpringBoot中的Mybatis依赖问题

Pom导入依赖

?

1

2

3

4

5

<dependency>

             <groupId>org.mybatis.spring.boot</groupId>

             <artifactId>mybatis-spring-boot-starter</artifactId>

             <version> 2.0 . 0 </version>

         </dependency>

application.yml

?

1

2

3

4

5

6

7

8

9

10

#配置数据源,yml格式

spring:

   datasource:

      url: jdbc:mysql: //127.0.0.1:3306/dianping?useUnicode=true&characterEncoding=utf8

      username: root

      password: 123

      driver- class -name: com.mysql.jdbc.Driver

#指定mybatis映射文件的地址

mybatis:

   mapper-locations: classpath:mapper/*.xml

项目结构

mybatis默认是属性名和数据库字段名一一对应的,即
数据库表列:user_name
实体类属性:user_name

但是java中一般使用驼峰命名
数据库表列:user_name
实体类属性:userName

在Springboot中,可以通过设置map-underscore-to-camel-case属性为true来开启驼峰功能。
application.properties中:

?

1

2

3

mybatis:

   configuration:

     map-underscore-to-camel- case : true

补充:下面再看下spring boot集成mybatis需要的相关依赖

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

<dependencies>

         <!-- 单元测试 -->

         <dependency>

             <groupId>junit</groupId>

             <artifactId>junit</artifactId>

             <scope>test</scope>

         </dependency>

         <!-- springboot对面向切面编程的支持,包括spring-aop和aspectj -->

             <groupId>org.springframework.boot</groupId>

             <artifactId>spring-boot-starter-aop</artifactId>

         <!-- 通过spring-rabbit来支持AMQP协议 -->

             <artifactId>spring-boot-starter-amqp</artifactId>

         <!-- 对全栈web开发的支持,包括tomcat和spring-webmvc -->

             <artifactId>spring-boot-starter-web</artifactId>

             <!-- TODO 发布生产的时候需要将此段放开 -->

             <!-- <exclusions> -->

             <!-- <exclusion> -->

             <!-- <groupId>org.springframework.boot</groupId> -->

             <!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->

             <!-- </exclusion> -->

             <!-- </exclusions> -->

         <!-- 支持常规的测试依赖,包括junit,hamcrest.mockito以及spring-test -->

             <artifactId>spring-boot-starter-test</artifactId>

         <!-- 生产准备的特征,用于帮你监控和管理应用 -->

             <artifactId>spring-boot-starter-actuator</artifactId>

     <!--核心spring boot starter,包括自动配置支持,日志和YAML -->

     <dependency>

             <groupId>org.mybatis.spring.boot</groupId>

             <artifactId>spring-boot-starter</artifactId>

     <!--对jdbc数据库的支持 -->

             <artifactId>spring-boot-starter-jdbc</artifactId>

     <!--对spring-security的支持 -->

             <artifactId>spring-boot-starter-security</artifactId>

     <!--对spring-redis的支持 ,支持Redis键值存储数据库-->

             <artifactId>spring-boot-starter-redis</artifactId>

         <!-- mybatis -->

             <artifactId>mybatis-spring-boot-starter</artifactId>

             <version> 1.1 . 1 </version>

         <!-- MYSQL -->

             <groupId>mysql</groupId>

             <artifactId>mysql-connector-java</artifactId>

             <groupId>com.alibaba</groupId>

             <artifactId>fastjson</artifactId>

             <version> 1.2 . 30 </version>

             <artifactId>druid</artifactId>

             <version> 1.0 . 24 </version>

             <groupId>org.hibernate</groupId>

             <artifactId>hibernate-validator</artifactId>

             <version> 5.3 . 1 .Final</version>

             <groupId>javax.servlet</groupId>

             <artifactId>javax.servlet-api</artifactId>

             <version> 3.0 . 1 </version>

             <scope>provided</scope>

             <groupId>commons-httpclient</groupId>

             <artifactId>commons-httpclient</artifactId>

             <version> 3.1 </version>

         <!--pagehelper -->

         <!-- <dependency>

             <groupId>com.github.pagehelper</groupId>

             <artifactId>pagehelper-spring-boot-starter</artifactId>

         </dependency> -->

               <groupId>com.github.pagehelper</groupId>

               <artifactId>pagehelper</artifactId>

              <version> 4.1 . 6 </version>

          </dependency>

        

     </dependencies>

到此这篇关于SpringBoot中的Mybatis依赖问题的文章就介绍到这了,更多相关SpringBoot Mybatis依赖内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

原文链接:https://blog.csdn.net/m0_67402013/article/details/124404270

查看更多关于SpringBoot中的Mybatis依赖问题的详细内容...

  阅读:13次