SpringBoot如何构建ORM框架
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,本篇内容主要讲解"SpringBoot如何构建ORM框架",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"SpringBoot如何构建ORM框架"吧!目前常用
千家信息网最后更新 2024年09月22日SpringBoot如何构建ORM框架
本篇内容主要讲解"SpringBoot如何构建ORM框架",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"SpringBoot如何构建ORM框架"吧!
目前常用的ORM框架有 Mybatis(batis)、MybatisPlus,Hibernate、Jpa等几个框架,今天就简单介绍一下搭建Mybatisplus框架的流程。
1.增加依赖
com.baomidou mybatis-plus-boot-starter 3.5.1 mysql mysql-connector-java 8.0.28 com.alibaba druid-spring-boot-starter 1.2.8
2.数据库实体模型
主要使用@TableName和@TableField,配置属性类和数据库表的对应关系
@TableName("userinfo")@Datapublic class UserInfo { @TableId(type = IdType.AUTO) private Integer id; @TableField private String name; private String usernum; private int sex; private Date createtime; private Date updatetime;}
3.增加Mapper
使用BaseMapper继承或者IService继承
BaseMapper 接口中封装了一系列 CRUD 常用操作
IService 内部进一步封装了 BaseMapper 接口的方法(当然也提供了更详细的方法)。
public interface IUserInfoMapper extends BaseMapper{ }
或者
public interface IUserInfoSevice extends IService{ }
4.@Mapper或者@MapperScan
使用@Mapper或者@MapperScan,将Mapper的接口类编译成实现类,才能注入。
@MapperScan:在启动项类上增加@MapperScan,指定扫描的包。指定了变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
@Mapper:在接口上增加@Mapper,在编译之后会生成相应的接口实现类。
@SpringBootApplication@MapperScan("......")public class MybatisPlusProgram { public static void main(String[] args) { SpringApplication.run(MybatisPlusProgram.class, args); }}
5.配置连接
默认数据库配置连接
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/myboot?useUnicode=true&characterEncoding=utf8 username: root password: root
durid连接池配置连接:
spring: datasource: #1.JDBC type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/myboot?useUnicode=true&characterEncoding=utf8 username: root password: root druid: #2.连接池配置 #初始化连接池的连接数量 大小,最小,最大 initial-size: 5 min-idle: 5 max-active: 20 #配置获取连接等待超时的时间 max-wait: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 time-between-eviction-runs-millis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 min-evictable-idle-time-millis: 30000 # 检查数据库 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: true test-on-return: false # 是否缓存preparedStatement,也就是PSCache 官方建议MySQL下建议关闭 个人建议如果想用SQL防火墙 建议打开 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 filter: stat: merge-sql: true slow-sql-millis: 5000 #3.基础监控配置 web-stat-filter: enabled: true url-pattern: /* #设置不统计哪些URL exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" session-stat-enable: true session-stat-max-count: 100 stat-view-servlet: enabled: true url-pattern: /druid/* reset-enable: true #设置监控页面的登录名和密码 #监控页访问:http://localhost:端口号/项目名称/druid/login.html login-username: admin login-password: admin allow: 127.0.0.1 #deny: 192.168.1.100
到此,相信大家对"SpringBoot如何构建ORM框架"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
配置
接口
框架
监控
建议
数据
数据库
方法
统计
编译
最小
内容
单位
常用
时间
防火墙
学习
封装
检测
生成
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
全球网络安全实时排名查询
hgmdpro数据库
获得三级数据库技术证书条件
宝塔能打开是不是服务器正常
云服务器内网地址和公网地址
网络安全具体分类
企业服务器管理公司
空间数据库设计案例
网络安全的诗20字
数据库版本号表如何查找
江北专业软件开发设计
嵌入式软件开发工作时间
乐陵软件开发找哪家
数据库读书笔记结尾
西湖区直播软件开发
服务器软中断
浙江net软件开发如何收费
公司数据库很多表怎样快速熟悉
视觉上位机软件开发主要内容
r720服务器安全模式
新三板公司翻译软件开发
网络安全中名词解释
北京智慧团建软件开发公司
机器视觉软件开发招聘
软件开发压力大怎么办
linux网络服务器安全加固
dcs网络安全设计
主公莫慌 服务器
东港警方网络安全宣传
2017最新网络安全