idea配置springboot整合mybatis(傻瓜式配置)

1,打开idea软件
2,点击file-----new------project新建项目在这里插入图片描述
3,选择jdk版本,添加maven配置在这里插入图片描述
4,点击下一步
在这里插入图片描述
5,选择maven配置,找到settings.xml文件,然后点击ok。
在这里插入图片描述
6,点击finish完成创建项目
在这里插入图片描述
7,在pom.xml文件中添加配置

(这些配置是常用的配置,如果需要其他的配置请到官网查看配置内容)

 <!-- 核心模块,包括自动配置支持、日志支持 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.2</version>
    </dependency>

    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4.0</version>
    </dependency>

    <!-- druid数据库连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid-spring-boot-starter</artifactId>
      <version>1.1.9</version>
    </dependency>

    <!--模板thymeleaf包-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!--spring aop 包-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

    <!-- jedis包 -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.8.0</version>
    </dependency>

    <!-- mybatis 整合redis 包 -->
    <dependency>
      <groupId>org.mybatis.caches</groupId>
      <artifactId>mybatis-redis</artifactId>
      <version>1.0.0-beta2</version>
    </dependency>

    <!-- 分页插件pagehelper -->
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.0.0</version>
    </dependency>
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.2.3</version>
    </dependency>
    <!-- 分页插件pagehelper -->

8,在main目录下新建两个文件夹java,resources
在这里插入图片描述
9,右键标记java,resources文件夹
在这里插入图片描述
在这里插入图片描述
10,在resources文件夹下新建mapper,static,templates文件夹

mapper文件夹下放置的是mapper映射文件
static文件夹下放置的是静态文件(css,js,pictures)
templates文件夹下放置的是html文件和特殊配置文件

11,在resources文件夹下新建application.properties配置文件
配置文件内容如下:

#spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
#spring.datasource.username=scott
#spring.datasource.password=scott
spring.datasource.druid.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.druid.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
spring.datasource.druid.username=scott
spring.datasource.druid.password=123456
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=10
spring.datasource.druid.max-wait=10
#是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。
#在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。
#spring.datasource.druid.pool-prepared-statements=true
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.druid.time-between-eviction-runs-millis=60000
#配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.druid.min-evictable-idle-time-millis=300000
#配置扩展插件:监控统计用的filter:stat  日志用的filter:log4j  防御sql注入的filter:wall
#spring.datasource.druid.filters=stat,wall
#spring.datasource.druid.filter.stat.log-slow-sql=true
#spring.datasource.druid.filter.stat.slow-sql-millis=2000

#实体别名
mybatis.typeAliasesPackage=com.aaa.entity
#mapper文件扫描
mybatis.mapperLocations=classpath\:mapper/*.xml
#工程名
#server.servlet.context-path=/
#端口号aaa
server.port=8888
#tomcat编码
server.tomcat.uri-encoding=UTF-8

#配置静态资源前后缀
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
#开发时建议将spring.thymeleaf.cache设置为false,否则会有缓存,导致页面没法及时看到更新后的效果
spring.thymeleaf.cache=false

#配置上传路径
upload.path=D:/images/
#默认支持文件上传
spring.servlet.multipart.enabled=true
spring.servlet.multipart.file-size-threshold=0
#上传文件大小配置
spring.servlet.multipart.max-file-size=10mb
spring.servlet.multipart.max-request-size=10mb

#redis配置
spring.redis.host=192.168.1.63
spring.redis.port=6379
spring.redis.database=0
spring.redis.timeout=3000
spring.redis.jedis.pool.max-active=200
spring.redis.jedis.pool.max-idle=100
spring.redis.jedis.pool.min-idle=1
spring.redis.jedis.pool.max-wait=1000
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-on-return=true
#全局防止无效列类型配置
mybatis.configuration.jdbc-type-for-null=NULL

#分页插件
#helperDialect属性来指定分页插件使用哪种方言
pagehelper.helper-dialect=oracle
#当该参数设置为 true 时,pageNum<=0 时会查询第一页, pageNum>pages(超过总数时),会查询最后一页。
pagehelper.reasonable=true
#支持通过 Mapper 接口参数来传递分页参数,默认值false,分页插件会从查询方法的参数值中,自动根据上面 params 配置的字段中取值,查找到合适的值时就会自动分页。
pagehelper.support-methods-arguments=true
#增加了该参数来配置参数映射,用于从对象中根据属性名取值
pagehelper.params=count=countSql

12,在java文件夹下新建一个启动类(启动类要与dao,service,controller文件夹属于同一级)

package com.aaa.sb;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * className:SpringBootMainApplication
 * discription:springboot启动类
 * author:zz
 * createTime:2018-11-21 09:32
 */
@SpringBootApplication  //扫描他所在的包及所有的子包和子孙包
@MapperScan("com.aaa.sb.dao") //扫描dao层接口
public class SpringBootMainApplication {

    /**
     * 主函数
     */
    public static void main(String[] args) {
        SpringApplication.run(SpringBootMainApplication.class);

    }
}

13,在java文件夹下新建包,写后台代码
这样一个基本的springboot整合mybatis框架就配置好啦!有疑问欢迎留言!

猜你喜欢

转载自blog.csdn.net/weixin_44001965/article/details/86478385