广告
返回顶部
首页 > 资讯 > 精选 >使用Spring Boot 怎么对mybatis与swagger2进行整合
  • 566
分享到

使用Spring Boot 怎么对mybatis与swagger2进行整合

springbootmybatisswagger2 2023-05-31 09:05:59 566人浏览 薄情痞子
摘要

本篇文章给大家分享的是有关使用Spring Boot 怎么对mybatis与swagger2进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。首先是pom文件的一些依赖&l

本篇文章给大家分享的是有关使用Spring Boot 怎么对mybatisswagger2进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

首先是pom文件的一些依赖

<?xml version="1.0" encoding="UTF-8"?><project xmlns="Http://Maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.example</groupId>  <artifactId>demo 2</artifactId>  <version>0.0.1-SNAPSHOT</version>  <packaging>jar</packaging>  <name>demo 2</name>  <description>Demo project for spring Boot</description>  <parent>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-parent</artifactId>   <version>1.5.1.RELEASE</version>   <relativePath/> <!-- lookup parent from repository -->  </parent>  <properties>   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>   <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>   <java.version>1.7</java.version>  </properties>  <dependencies>   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-aop</artifactId>   </dependency>   <!-- 移除内置的log的依赖使用log4j进行日志输出-->   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-WEB</artifactId>     <exclusions>      <exclusion>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-logging</artifactId>      </exclusion>     </exclusions>   </dependency>   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-jdbc</artifactId>   </dependency>   <dependency>     <groupId>com.oracle</groupId>     <artifactId>ojdbc14</artifactId>     <version>10.2.0.1.0</version>   </dependency>   <!-- redis -->   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-Redis</artifactId>   </dependency>   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-test</artifactId>     <scope>test</scope>   </dependency>   <!--导入mybatis -->   <dependency>     <groupId>org.mybatis</groupId>     <artifactId>mybatis-spring</artifactId>     <version>1.2.2</version>   </dependency>   <dependency>     <groupId>org.mybatis</groupId>     <artifactId>mybatis</artifactId>     <version>3.2.8</version>   </dependency>   <dependency>     <groupId>org.apache.commons</groupId>     <artifactId>commons-lang3</artifactId>     <version>3.5</version>   </dependency>   <!--mybatis的分页插件 很好用的一个 具体使用方法可以去下面的网站 -->   <!-- https://mvnrepository.com/artifact/com.GitHub.pagehelper/pagehelper -->   <dependency>     <groupId>com.github.pagehelper</groupId>     <artifactId>pagehelper</artifactId>     <version>4.1.6</version>   </dependency>   <dependency>     <groupId>org.codehaus.jackson</groupId>     <artifactId>jackson-mapper-asl</artifactId>     <version>1.9.13</version>   </dependency>   <!--swagger2 生成api文档 -->   <dependency>     <groupId>io.springfox</groupId>     <artifactId>springfox-swagger2</artifactId>     <version>2.2.2</version>   </dependency>   <dependency>     <groupId>io.springfox</groupId>     <artifactId>springfox-swagger-ui</artifactId>     <version>2.2.2</version>   </dependency>   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-thymeleaf</artifactId>   </dependency>   <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-log4j</artifactId>   </dependency>   </dependencies>  <build>   <plugins>     <plugin>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-maven-plugin</artifactId>     </plugin>   </plugins>  </build>  <repositories>   <repository>     <id>spring-snapshots</id>     <name>Spring Snapshots</name>     <url>https://repo.spring.io/snapshot</url>     <snapshots>      <enabled>true</enabled>     </snapshots>   </repository>   <repository>     <id>spring-milestones</id>     <name>Spring Milestones</name>     <url>https://repo.spring.io/milestone</url>     <snapshots>      <enabled>false</enabled>     </snapshots>   </repository>  </repositories>  <pluginRepositories>   <pluginRepository>     <id>spring-snapshots</id>     <name>Spring Snapshots</name>     <url>https://repo.spring.io/snapshot</url>     <snapshots>      <enabled>true</enabled>     </snapshots>   </pluginRepository>   <pluginRepository>     <id>spring-milestones</id>     <name>Spring Milestones</name>     <url>https://repo.spring.io/milestone</url>     <snapshots>      <enabled>false</enabled>     </snapshots>   </pluginRepository>  </pluginRepositories></project>

接着是application.yml数据库配置

spring: datasource:   driver-class-name: oracle.jdbc.OracleDriver    url: jdbc:oracle:thin:localhost:1521:orcl   username: orcl   passWord: orcl

然后是application.java

package com.example;import org.apache.ibatis.session.sqlSessionFactory;import org.mybatis.spring.SqlSessionFactoryBean;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.core.io.support.PathMatchingResourcePatternResolver;import org.springframework.jdbc.datasource.DataSourceTransactionManager;import org.springframework.transaction.PlatfORMTransactionManager;import javax.sql.DataSource;@SpringBootApplication//@ComponentScan 注解自动收集所有的Spring组件,包括 @Configuration 类。@ComponentScan@MapperScan("com.example.mapper")public class DemoApplication {  @Bean  @ConfigurationProperties(prefix="spring.datasource")  public DataSource dataSource() {    return new org.apache.Tomcat.jdbc.pool.DataSource();  }  @Bean  public SqlSessionFactory sqlSessionFactoryBean() throws Exception {    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();    sqlSessionFactoryBean.setDataSource(dataSource());    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();    //这里的话如果不用mybatis-config.xml 可以把下面那句给注释掉    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis@Configuration@EnableSwagger2public class SwaggerConfig{  @Bean  public Docket createRestApi() {    return new Docket(DocumentationType.SWAGGER_2)        .apiInfo(apiInfo())        .select()        .apis(RequestHandlerSelectors.basePackage("com.example.web"))        .paths(PathSelectors.any())        .build();  }  private ApiInfo apiInfo() {    return new ApiInfoBuilder()        .title("API")        .description("")        .termsOfServiceUrl("")        .contact("yihec")        .version("1.0")        .build();  }}

以上就是使用Spring Boot 怎么对mybatis与swagger2进行整合,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注编程网精选频道。

--结束END--

本文标题: 使用Spring Boot 怎么对mybatis与swagger2进行整合

本文链接: https://www.lsjlt.com/news/224497.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 使用Spring Boot 怎么对mybatis与swagger2进行整合
    本篇文章给大家分享的是有关使用Spring Boot 怎么对mybatis与swagger2进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。首先是pom文件的一些依赖&l...
    99+
    2023-05-31
    springboot mybatis swagger2
  • 使用Spring boot怎么对Mybatis进行整合
    这篇文章将为大家详细讲解有关使用Spring boot怎么对Mybatis进行整合,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。1、文件结构DataBaseConfiguration.Jav...
    99+
    2023-05-31
    springboot mybatis
  • 使用spring boot如何实现对Swagger2进行整合
    本篇文章给大家分享的是有关使用spring boot如何实现对Swagger2进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。Swagger 是一个规范和完整的框架,用于...
    99+
    2023-05-31
    springboot swagger2
  • 使用Spring Boot如何对Mybatis进行整合
    今天就跟大家聊聊有关使用Spring Boot如何对Mybatis进行整合,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。依赖配置结合前面的内容,这里我们要嵌入数据库的操作,这里以操作...
    99+
    2023-05-31
    springboot mybatis
  • 使用spring怎么对mybatis进行整合
    本篇文章为大家展示了使用spring怎么对mybatis进行整合,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。1 数据库连接配置信息jdbc.properties#mysql version dat...
    99+
    2023-05-31
    spring mybatis
  • 使用Spring Boot如何实现对MyBatis的整合
    本篇文章为大家展示了使用Spring Boot如何实现对MyBatis的整合,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。1.加入mybatis-spring-boot-stater的Maven依赖...
    99+
    2023-05-31
    springboot mybatis
  • 怎么对struts、spring与hibernate进行整合
    怎么对struts、spring与hibernate进行整合?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。准备三个框架结合的lib包Spring3结合Struts2的步骤如下:...
    99+
    2023-05-31
    struts hibernate spring
  • 使用spring boot如何实现对CAS进行整合
    今天就跟大家聊聊有关使用spring boot如何实现对CAS进行整合,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。代码整合cas的重要过程import org.jasig.cas....
    99+
    2023-05-31
    springboot cas
  • 使用Spring Boot如何实现对MongoDB进行整合
    本篇文章给大家分享的是有关使用Spring Boot如何实现对MongoDB进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。MongoDB是什么?MongoDB是一个No...
    99+
    2023-05-31
    springboot mongodb
  • 使用spring boot如何实现对RabbitMQ进行整合
    使用spring boot如何实现对RabbitMQ进行整合?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。springboot集成RabbitMQ非常简单,如果...
    99+
    2023-05-31
    springboot rabbitmq
  • Spring Boot怎么利用XML方式整合MyBatis
    本篇内容介绍了“Spring Boot怎么利用XML方式整合MyBatis”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、前言下...
    99+
    2023-06-30
  • 使用spring如何实现springmvc与mybatis进行整合
    使用spring如何实现springmvc与mybatis进行整合?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。jar包 引入web.xml文件<conte...
    99+
    2023-05-31
    spring springmvc mybatis
  • 使用Spring怎么对Web项目进行整合
    今天就跟大家聊聊有关使用Spring怎么对Web项目进行整合,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。一 概述1.整合目的将所有对象的创建与管理任务交给Spring容器,降低程序...
    99+
    2023-05-31
    spring web
  • 使用Spring boot如何实现对Mybatis进行集成
    使用Spring boot如何实现对Mybatis进行集成?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。本章目标整合 Mybatis ,并集成 Druid 数据...
    99+
    2023-05-31
    springboot mybatis
  • 使用MongoDB如何对Spring进行整合
    本篇文章给大家分享的是有关使用MongoDB如何对Spring进行整合,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。添加依赖<dependency> &n...
    99+
    2023-05-31
    mongodb spring
  • Mybatis怎么与Spring结合使用
    Mybatis怎么与Spring结合使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。所需要用到的其他工具或技术:项目管理工具 : Maven前台WEB展示:JSP其他框架:S...
    99+
    2023-05-31
    mybatis spring
  • spring boot怎么与kafka结合使用
    spring boot怎么与kafka结合使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。引入相关依赖<dependency> <groupId>o...
    99+
    2023-05-31
    springboot kafka
  • 使用MyBatis怎么对Spring进行无缝对接
    本篇文章给大家分享的是有关使用MyBatis怎么对Spring进行无缝对接,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。1.为什么会出现MyBatis-SpringSpring...
    99+
    2023-05-31
    mybatis spring
  • 如何使用Spring Boot与Kotlin进行联合开发
    这篇文章给大家介绍如何使用Spring Boot与Kotlin进行联合开发,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。一、概述spring官方最近宣布,将在Spring Framework 5.0版本中正式支持Kot...
    99+
    2023-05-31
    springboot kotlin
  • 使用spring如何对cxf框架进行整合
    使用spring如何对cxf框架进行整合?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。1.创建动态web项目2.导入cxf和spring相关jar包(CXF核心...
    99+
    2023-05-31
    cxf spring
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作