Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use mybatis in springboot2 multi-module project

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use mybatis in the springboot2 multi-module project, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

First of all, create a multi-module project to make the project run successfully and run.

You can refer to the article to create a multi-module project, Goodbye!

The project is divided into three sub-modules: parent megatron

Megatron-api

Project startup class

Package com.megatron.module;import com.megatron.utils.IPUtils;import org.mybatis.spring.annotation.MapperScan;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication@MapperScan ("com.megatron.module.dal.mapper") / / scan the interface public class MegatronLogApiApplication {public static Logger logger = LoggerFactory.getLogger (MegatronLogApiApplication.class) in the specified package Public static void main (String [] args) {System.setProperty ("local-ip", IPUtils.getLocalIp ()); SpringApplication.run (MegatronLogApiApplication.class, args);}}

Application.yml

Spring: datasource: name: mysql type: com.alibaba.druid.pool.DruidDataSource druid: filter: stat driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/megatron?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true username: root password: # configuration initialization size / min / max initial-size: 1 min-idle: 1 Max-active: 20 # get connection wait timeout max-wait: 60000 # how often is it checked Detect idle connections that need to be closed time-between-eviction-runs-millis: 60000 # minimum time for a connection to live in the pool min-evictable-idle-time-millis: 300000 validation-query: SELECT 'x' test-while-idle: true test-on-borrow: false test-on-return: false # Open PSCache and specify the size of the PSCache on each connection. Oracle is set to true,mysql and set to false. It is recommended to set false pool-prepared-statements: false max-pool-prepared-statement-per-connection-size: 20logging: config: classpath:log4j2-test.ymlmybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.megatron.module.dal.entity

Megatron-impl

Pom that mybatis needs to use

Org.mybatis mybatis 3.5.1 compile mysql mysql-connector-java runtime com.github.pagehelper pagehelper-spring-boot-starter 1.2.5 com.alibaba druid-spring-boot-starter 1.1.9

The red box content is generated by the mybatis plug-in code reference plug-in Goodluck plug-in!

Finally, you can see that the result can be output normally.

On the springboot2 multi-module project on how to use mybatis to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report