当前位置: 首页 > news >正文

1.Spring Boot框架整合

Spring Boot项目创建(约定大于配置)

2.1.3.RELEASE版本示例

  • idea创建

  • 从官网下载(https://start.spring.io/)
  • 单元测试默认依赖不对时,直接删除即可

Web支持(SpringMVC)

<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/  #修改默认路径 classpath:/templates/

Mybatis 整合

添加依赖【刷新Maven】

<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>

配置文件修改=> yml(yaml) / properties

spring:datasource:url: jdbc:mysql://localhost:3306/qcby_db?useUnicode=true&characterEncoding=utf-8username: rootpassword:driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:mapper-locations: classpath:mapper/*.xml  #对应mapper映射xml文件所在路径type-aliases-package: com.xxxx.entity  #对应实体类路径

启动类修改

// 启动类修改
@MapperScan("com.xxxx.mapper")
@SpringBootApplication

测试

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yglh.mapper.TestMapper"><resultMap id="BaseResultMap" type="com.qcbt.lxt.byg0417.entity.Test"><id column="id" jdbcType="BIGINT" property="id" /><result column="name" jdbcType="VARCHAR" property="name" /></resultMap><sql id="Base_Column_List">id,name</sql>
</mapper>

PageHelper 分页插件整合

需要注意和mybatis-spring-boot-starter的版本关系。

 添加依赖

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

配置 => properties / yml

pagehelper:helperDialect: mysqlreasonable: true # 修改默认值
  • reasonable:分页合理化参数,默认值为false。当该参数设置为 true 时,pageNumpages(超过总数时),会查询最后一页。默认false 时,直接根据参数进行查询。

 示例

Page<Object> page = PageHelper.startPage(logInfoVo.getPage(), logInfoVo.getLimit());

http://www.lryc.cn/news/331791.html

相关文章:

  • 如何在 Debian VPS 上添加、删除和授予用户 sudo 权限
  • openlayers 入门教程(九):overlay 篇
  • 基于Python的高考志愿辅助填报系统
  • 使用CMake搭建简单的Qt程序
  • Qt + VS2017 创建一个简单的图片加载应用程序
  • Linux文件搜索工具(gnome-search-tool)
  • c++20协程详解(三)
  • LLM--提示词Propmt的概念、作用及如何设计提示词
  • 59 使用 uqrcodejs 生成二维码
  • Leetcode 3097. Shortest Subarray With OR at Least K II
  • 算法系列--递归,回溯,剪枝的综合应用(2)
  • Docker搭建LNMP环境实战(09):安装mariadb
  • 基于Python的微博舆论分析,微博评论情感分析可视化系统,附源码
  • Flutter iOS上架指南
  • 实操:driver.js 实现产品导览、亮点、上下文帮助
  • 【JavaWeb】Day29.SpringBootWeb请求响应——请求(二)
  • asf是什么格式的文件?用手机怎么打开?
  • picGo图床搭建gitee和smms(建议使用)
  • LeetCode | 数组 | 二分查找 | 35.搜索插入位置【C++】
  • Linux 给网卡配置ip
  • 【C语言】翻译环境与运行环境
  • ubuntu20.04执行sudo apt-get update失败的解决方法
  • 接口调用成功后端却一直返回404
  • 【Vmware】 debian 12 安装教程
  • YooAssets 使用相关
  • 精准扶贫管理系统|基于Springboot的精准扶贫管理系统设计与实现(源码+数据库+文档)
  • Flutter与iOS和Android原生页面交互
  • Chrome安装Vue插件vue-devtools
  • 内存和网卡压力测试
  • 法律行业案例法模型出现,OPenAI公布与法律AI公司Harvey合作案例