快速开始一个springboot项目

Spring Boot

  • 快速第一个Spring Boot应用(2.1.3.RELEASE)

    • idea创建
    • 从官网下载
  • 通过配置,快速整合spring mvc、mybatis 、 thymleaf 示例

    • spring mvc 支持

              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
              </dependency>
      
    • thymleaf 整合 模板引擎

          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-thymeleaf</artifactId>
          </dependency>
      
      spring:
        thymeleaf:
          cache: false # 关闭缓存
          prefix: classpath:/pages/  #修改默认路径
      
      eg:
      spring:
      	thymeleaf:
      		cache: false #默认关闭前端缓存
      		prefix: classpath:/templates/ #前缀
      		suffix: .html #后缀
      
    • mybatis 整合

        	<dependency>
                  <groupId>org.mybatis.spring.boot</groupId>
                  <artifactId>mybatis-spring-boot-starter</artifactId>
                  <version>2.1.1</version>
            </dependency>
              <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <scope>runtime</scope>
            </dependency>
      
      spring:
        datasource:
          url: jdbc:mysql://localhost:3306/qcby_0319?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT
          username: root
          password:
        driver-class-name: com.mysql.cj.jdbc.Driver
          
      mybatis:
        mapper-locations: classpath:mapper/*.xml  #对应mapper映射xml文件所在路径
        type-aliases-package: com.xxxx.entity  #对应实体类路径
      
    启动类上加上mapper包注解
      @MapperScan("com.xxxx.mapper")
      @SpringBootApplication
    
    • pageHelper 分页插件整合,需要注意和mybatis-spring-boot-starter的版本关系

              <!--pageHelper分页插件-->
              <dependency>
                  <groupId>com.github.pagehelper</groupId>
                  <artifactId>pagehelper-spring-boot-starter</artifactId>
                  <version>1.3.0</version>
              </dependency>
      
      pagehelper:
        helperDialect: mysql
        reasonable: true
        supportMethodsArguments: true
        params: count=countSql
      
              Page<Object> page = PageHelper.startPage(logInfoVo.getPage(), logInfoVo.getLimit());
              List<LogInfo> data = logInfoMappper.queryAllLogInfoForList(logInfoVo);
      
    • HuTool 验证码依赖引入

      • 使用HuTool工具类,实现登录验证码:https://www.e-learn.cn/topic/3515429
      
              <dependency>
                  <groupId>cn.hutool</groupId>
                  <artifactId>hutool-all</artifactId>
                  <version>5.2.3</version>
              </dependency>
      
    • 文件上传引用的一个依赖

             <dependency>
                  <groupId>org.aspectj</groupId>
                  <artifactId>aspectjweaver</artifactId>
                  <version>1.6.8</version>
              </dependency>
      
    • layui页面整合调试

    • 整体演示

Idea配置注释 参考
https://blog.csdn.net/weixin_42685022/article/details/82682838

猜你喜欢

转载自blog.csdn.net/LvFengQi/article/details/115289824