随笔分类 -  Mybatis

摘要:Mybatis默认事务管理器:JDBC 可选:JDBC|MANAGED 默认连接池:POOLED 可选:UNPOOLED|POOLED|JNDI 编写db.properties配置文件 driver = com.mysql.cj.jdbc.Driverurl=jdbc:mysql://localho 阅读全文
posted @ 2022-01-22 13:47 朝阳的博客 阅读(44) 评论(0) 推荐(0)
摘要:模糊查询: 1.Java代码执行的时候传递通配符%%(会产生sql注入问题) List<User> userlist = mapper.getUserLike("%value%"); 2.在sql拼接中使用通配符(更安全) select * from mybatis.user where name 阅读全文
posted @ 2022-01-22 10:25 朝阳的博客 阅读(48) 评论(0) 推荐(0)
摘要:增删改需要提交事务: sqlSession.commit(); 增 mapper: Test 删 Mapper Test 改 Mapper Test 查 resultType:Sql执行的返回结果类型 parameterType:参数类型 Mapper 阅读全文
posted @ 2022-01-22 09:52 朝阳的博客 阅读(92) 评论(0) 推荐(0)
摘要:搭建环境→导入Mybati→编写代码→测试 1.搭建环境 搭建数据库 新建项目 注意事项 删除src文件 导入依赖 <!-- Mybatis驱动--> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --> <dependenc 阅读全文
posted @ 2022-01-21 22:40 朝阳的博客 阅读(121) 评论(0) 推荐(0)
摘要:持久化 持久化就是将程序的数据在持久状态和瞬时状态转化的过程 内存:断电即失 数据库(jdbc),io文件持久化 为什么需要持久化: 某些对象,不能让他丢掉 内存太贵 持久层: 完成持久化工作的代码块 层的界限十分明显 为什么需要Mybatis 解除sql与程序代码的耦合:通过提供DAO层,将业务逻 阅读全文
posted @ 2022-01-21 19:50 朝阳的博客 阅读(102) 评论(0) 推荐(0)
摘要:public class MybatisUtils { private static SqlSessionFactory sqlSessionFactory; static { try { //使用Mybatis第一步:获取sqlSessionFactory对象 String resource = 阅读全文
posted @ 2021-12-27 10:47 朝阳的博客 阅读(164) 评论(0) 推荐(0)