随笔分类 -  MyBatis

摘要:简单CRUD package com.ttpfx.dao; import com.ttpfx.domain.User; import org.apache.ibatis.annotations.*; import java.util.List; public interface UserDao { 阅读全文
posted @ 2021-03-10 16:14 ttpfx 阅读(45) 评论(0) 推荐(0)
摘要:延迟加载 延迟加载是指关联对象的按需加载。把对多个表的一次连表查询,分解为对多个单表的多次查询。默认只查询主表的数据,在使用查询结果对象时,才去对关联表进行查询。 优点:提高数据库性能,单表查询效率高于连表查询 缺点:增加查询次数? 全局设置 <settings> <setting name="la 阅读全文
posted @ 2021-03-10 09:53 ttpfx 阅读(61) 评论(0) 推荐(0)
摘要:一对一 一个账户对应一个用户: 账户实体: public class Account { private Integer id; private Double money; private User user; } 用户实体: public class User { private Integer 阅读全文
posted @ 2021-03-09 17:43 ttpfx 阅读(115) 评论(0) 推荐(0)
摘要:if 和 where public interface UserDao { List<User> getUserListByCondition(User user); } <select id="getUserListByCondition" parameterType="User" resultT 阅读全文
posted @ 2021-03-09 11:53 ttpfx 阅读(56) 评论(0) 推荐(0)
摘要:属性(properties) 通过properties的子元素设置配置项: <properties> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql:/ 阅读全文
posted @ 2021-03-09 10:00 ttpfx 阅读(103) 评论(0) 推荐(0)
摘要:第一种解决方法:在sql中使用别名 <select id="getRoleList" resultType="com.ttpfx.domain.Role"> select ID as id, ROLE_NAME as name, ROLE_DESC as description from role; 阅读全文
posted @ 2021-03-08 11:21 ttpfx 阅读(90) 评论(0) 推荐(0)
摘要:Dao接口 package com.ttpfx.dao; import com.ttpfx.domain.User; import java.util.List; public interface UserDao { List<User> getAll(); List<User> getUserLi 阅读全文
posted @ 2021-03-04 17:09 ttpfx 阅读(56) 评论(0) 推荐(0)
摘要:1.创建空的Java工程,安装MyBatis依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/X 阅读全文
posted @ 2021-03-04 14:27 ttpfx 阅读(86) 评论(0) 推荐(0)