1.多表关联
1.一对一关联
2.一对多关联
3.多对多
2.MyBatis级联查询
1.一对一
2.一对多
3.MyBatis缓存
1.一级缓存
2.二级缓存
4.MyBatis注解开发方式
//1.查询User表的所有数据
List<User> selectAll();
//2.根据id查询用户信息
@Select("select * from USER where id=#{id}")
User selectById(int id);
//3.根据用户id删除用户
@Delete("DELETE from USER where id=#{id}")
void deleteById1(int id);
//4.根据id修改用户
@Update("UPDATE user SET username=#{username} WHERE id=#{id}")
void updateById(User user);
//5.添加用户
@Insert("INSERT INTO user VALUES (null, #{username},#{birthday}, #{sex},#{address})")
void add(User user);
//6.根据id查询用户信息,带有多表查询(级联)
@Select("select * from user where id=#{id}")
@Results(value = {
@Result(column = "id",property = "id"),
@Result(column = "username",property = "username"),
@Result(column = "birthday",property = "birthday"),
@Result(column = "sex",property = "sex"),
@Result(column = "address",property = "address"),
@Result(property = "infoData",one = @One(select="selectInfoById"),column = "id"),
@Result(property = "orderList",many = @Many(select = "selectOrdersById"),column = "id")
})
User selectByIdAndOthers(int id);
//7.根据id查询用户扩展信息
@Select("select * from user_info where id=#{id}")
UserInfo selectInfoById(int id);
//8.根据id查询订单数据信息
@Select("select * from `order` where user_id=#{id}")
List<Order> selectOrdersById(int id);