mybatis
AnjanaVakil
当时不杂
展开
-
MyBatis Plus
配置主键自增 1、实体类字段上 @TableId(type = IdType.AUTO) 2、数据库字段一定要是自增! 如果数据库字段不自增,会报下面的错: java.sql.SQLException: Field ‘id’ doesn’t have a default value原创 2020-11-25 17:30:02 · 73 阅读 · 0 评论 -
MyBatis 动态SQL语句 where 1=1
where 1=1 where 1=1:为了满足多条件查询页面中不确定的各种因素而采用的一种构造一条能正确运行的动态SQL语句的一种方法。 <select id="findByUser" resultType="user" parameterType="user"> select * from user where 1=1 <if test="username!=null and username != '' "> an原创 2020-11-23 19:26:50 · 1035 阅读 · 0 评论 -
Mybatis CRUD 复习笔记 添加用户 返回新增用户的id值 #{}与${}的区别
1、 <insert id="saveUser" parameterType="com.itheima.domain.User"> insert into user(username,address.sex.birthday) values(#{username},#{address},#{sex},#{birthday}); <selectKey keyProperty="id" keyColumn="id" resultType="Integer原创 2020-11-23 09:49:07 · 408 阅读 · 0 评论 -
Mybatis 的参数深入 SqlMapConfig.xml 中配置的内容和顺序 typeAliases(类型别名)
parameterType 配置参数 parameterType 属性的取值可以是: 基本类型 引用类型(例如:String 类型) 实体类类型(POJO 类) 使用实体类的包装类(例如:QueryVo 对象) 举例: public class QueryVo { private User user; public User getUser() { return user; } public void setUser(User user) {原创 2020-11-23 10:44:08 · 160 阅读 · 0 评论 -
Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml
mybatis学习过程中遇到下面的bug Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml 网上有在pom.xml中加配置内容的,但并没有解决我的bug。 通过仔细检查代码,原来是路径内容错误,不知道该用**斜杠/还是点.**来划分 使用配置方式: <!-- 指定映射配置文件的位置,映射配置文件指的是每个dao独立的配置文件 如果使用注解配置,应该使用class属性指定被注原创 2020-09-11 15:36:18 · 2471 阅读 · 1 评论