引入springboot的两种方式以及springboot容器的引入

一、在项目中引入springboot有两种方式:

1、引入spring-boot-starter-parent

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

要覆盖parent自带的jar的版本号有两种方式:

  1. 在pom中重新引入这个jar,然后版本不一样,新引入的会覆盖parent本身的版本。
  2. <properties>中添加版本号变量

比如我们要修改mysql的版本号:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <mysql.version>5.1.42</mysql.version>
    </properties>

pom中也要加这个depency,只是版本号写在properties中了。

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
      <scope>runtime</scope>
</dependency>

2、引入spring-boot-dependencies

<dependencyManagement>
   <dependencies>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

depencies中如何覆盖依赖呢?

这里采用properties的这种方式不行,只能通过上面的第一种方式才可起作用:

二、springboot的内嵌容器

目前,springboot支持Tomcat,Jetty和Undertow作为Spring Boot嵌入式服务器,而Wiremock本身对特定版本的Jetty(目前为9.2)具有“本机”支持。要使用本地Jetty,您需要添加本机线程依赖关系,并排除Spring Boot容器(如果有的话)。

1、引入tomcat容器:直接引入spring-boot-starter-web,即引入了tomcat容器,默认为tomcat

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
 </dependency>

2、引入jetty容器。添加spring-boot-starter-jetty,并移除starter-tomcat

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
     </exclusion>
   </exclusions>
</dependency>
 <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Spring Boot项目中使用PageHelper,你可以按照以下步骤进行操作: 1. 首先,在你的项目的pom.xml文件中添加PageHelper的依赖。你可以在CSDN或者其他资源中找到PageHelper的最新版本,并将其添加到dependencies标签中,类似于下面的代码片段: ```xml <dependencies> <!-- 其他依赖 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>最新版本</version> </dependency> </dependencies> ``` 2. 接下来,在你的Spring Boot应用程序的配置文件(例如application.properties或application.yml)中,添加PageHelper的配置。下面是一个示例配置: ```properties # application.properties pagehelper.helper-dialect=mysql pagehelper.reasonable=true pagehelper.support-methods-arguments=true pagehelper.params=count=countSql ``` ```yaml # application.yml pagehelper: helper-dialect: mysql reasonable: true support-methods-arguments: true params: count=countSql ``` 根据你的数据库类型,修改`pagehelper.helper-dialect`的值。 3. 最后,你可以在你的Mapper接口方法上使用PageHelper进行分页查询。例如,在使用MyBatis的情况下,可以在查询方法上添加`PageHelper.startPage(pageNum, pageSize)`来指定分页参数。例如: ```java import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @Service public class UserService { @Autowired private UserMapper userMapper; public PageInfo<User> getUsers(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); List<User> userList = userMapper.getUsers(); return new PageInfo<>(userList); } } ``` 以上就是在Spring Boot项目中引入和使用PageHelper的基本步骤。希望能对你有所帮助!如有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值