2023年12月23日发(作者:c语言 数组类型)
CH01_MyBatis框架概述//映射器接口:定义对持久化对象的增删改查操作的抽象方法public interface UserMapper { List findAllUsers();}
CH02_MyBatis的CRUD操作
insert into user(id,username,password) values(#{id},#{userName},#{password})
insert into user(id,username,password) values(#{id},#{userName},#{password}) select last_insert_id()
update user set user_name=#{userName}, password=#{password} where id=#{id}
delete from user where id=#{id}
CH03_MyBatis关联映射一对一
insert into shopping_cart(cart_id,price,user_id) values(#{id},#{price},#{})
insert into user(id,username,password) values(#{id},#{userName},#{password})
insert into user(id,username,password) values(#{id},#{userName},#{password}) select last_insert_id()
update user set user_name=#{userName}, password=#{password} where id=#{id}
delete from user where id=#{id}
javaType="ngCart" resultMap="p">
select="oppingCartByUserId" column="{user_id=id}">
select="oppingCartByUserId" column="{user_id=id}" fetchType="lazy">
一对多
from orders
where user_id = #{uId}
insert into user(id,username,password) values(#{id},#{userName},#{password})
insert into user(id,username,password) values(#{id},#{userName},#{password}) select last_insert_id()
update user set user_name=#{userName}, password=#{password} where id=#{id}
delete from user where id=#{id}
映射集合类型的属性,ofType指定集合中元素的类型 ofType="" resultMap="ap">
ofType="" select="ders" column="{uId=id}" fetchType="lazy">
多对多继承映射
CH04_动态ckage ;import ;import ;import ;import ;//映射器接口:定义对持久化对象的增删改查操作的抽象方法public interface UserMapper { List findAllUsers();
//方法中有多个参数,需要使用@Param注解指定SQL参数名称 User findUserByNameAndPassword(@Param("username")String name, @Param("psw")String password);
//方法参数是Map类型,map对象中的key的值就是SQL参数名称 User findUserByMap(Map map);
List findUserByNameOrAge(@Param("name")String name,
@Param("age")int age);
int updateUserById(User u);
int insertUser(User u);
List findUserByIds(Integer[] ids);
//批量插入 int insertUsers(List u);
int updateUserByMap(Map map);}
update user set user_name=#{userName}, password=#{password}, age=#{age}, id = #{id} where id = #{id}
update user
user_name=#{userName}, password=#{password}, age=#{age}, where id = #{id}
update user
user_name=#{userName}, password=#{password}, age=#{age},
where id = #{id}
insert into user(user_name,password ,age ) values(#{userName},#{password} ,#{age} )
insert into user(user_name,password,age) values
(#{me},#{rd},#{})
update user set ${k} = #{v} where id = #{id}
简答对MyBatis的理解
传参方式
#{}与${}的异同
发表评论