55个常见Springboot应用示例,手把手教你深度学习Springboot

Springboot作为Java服务端开发事实上的框架标准,每一个学习Java的同学都应该深入了解。

但是经常看到有朋友说不知道该如何上手学习Springboot,平时开发功能都是在网上找一些示例,拼拼凑凑就交差了,至于功能模块能不能成功的跑起来全靠运气。

今天给大家推荐一个深度学习实战的Springboot项目,包含了服务端开发常见的55个功能示例,比如logback日志模块的配置、通过AOP切面记录日志、集成mybatisPlus、集成redis、集成RabbitMQ消息队列等等所有常见的功能。

项目作者将每一个功能都做成了一个模块,大家使用时只需要按照模块中的readme文档,一步一步的配置就可以完成一个功能的开发。

以集成mybatis-plus为例,打开demo-orm-mybatis-plus模块,

按照readme.md中步骤,即可快速完成mybatis-plus的集成。

1,引入mybatis-plus的包

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
  <mybatis.plus.version>3.0.5</mybatis.plus.version>
</properties>
<dependencies>
  <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>${mybatis.plus.version}</version>
  </dependency>
</dependencies>

2,配置mybatis-plus

@Configuration
@MapperScan(basePackages = {"要扫描的mapper包"})
@EnableTransactionManagement
public class MybatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

3,字段填充(可选)

@Slf4j
@Component
public class CommonFieldHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);
    }
}

4,配置数据源

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/spring-boot-demo
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    initialization-mode: always
    continue-on-error: true
    hikari:
      minimum-idle: 5
      connection-test-query: SELECT 1 FROM DUAL
      maximum-pool-size: 20
      auto-commit: true
      idle-timeout: 30000
      pool-name: SpringBootDemoHikariCP
      max-lifetime: 60000
      connection-timeout: 30000
logging:
  level:
    com.xkcoding: debug
    com.xkcoding.orm.mybatis.plus.mapper: trace
mybatis-plus:
  mapper-locations: classpath:mappers/*.xml
  global-config:
    # 数据库相关配置
    db-config:
      id-type: auto
     field-strategy: not_empty
      #驼峰下划线转换
      table-underline: true
      #是否开启大写命名,默认不开启
      #capital-mode: true
      #逻辑删除配置
      #logic-delete-value: 1
      #logic-not-delete-value: 0
      db-type: mysql
    refresh: true
  # 原生配置
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: true

经过以上4步,就可以轻松把mybatis-plus集成到我们的项目里面了。

这些项目的代码都是经过大家反复认证过的,只要引入的版本号没问题,就可以在我们的项目中正常的跑起来。

项目地址:

https://github.com/xkcoding/spring-boot-demo

大家clone项目以后注意看首页的readme,里面有开发环境、运行方式的说明。

我是@程序员拾山,全网同名,感谢您的点赞和关注。

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
SpringBoot登录示例可以通过以下步骤实现: 1. 首先,需要添加WebSocket的依赖。可以在pom.xml文件中添加以下代码引用\[1\]: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> ``` 2. 接下来,创建一个控制类来处理页面跳转。可以创建一个名为IndexController的类,代码如下引用\[2\]: ```java package com.xxx.springboot.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/") public class IndexController { public String index() { return "index"; } @GetMapping("/ws") public String webSocket() { return "webSocket"; } } ``` 3. 然后,需要配置WebSocket服务。可以创建一个名为WSConfig的配置类,代码如下引用\[3\]: ```java package com.xxx.springboot.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket.server.standard.ServerEndpointExporter; @Configuration public class WSConfig { @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } } ``` 通过以上步骤,你可以实现一个简单的SpringBoot登录示例。在IndexController中,index()方法返回的是登录页面的视图名,webSocket()方法返回的是WebSocket页面的视图名。在WSConfig中,使用@Bean注解将ServerEndpointExporter加入到容器中,以便支持WebSocket服务。 #### 引用[.reference_title] - *1* *2* *3* [springboot websocket示例](https://blog.csdn.net/feinifi/article/details/119797099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员拾山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值