mybatis之关联关系映射
Mybatis关联关系映射
1、一对多
首先先用逆向生成工具生成t_hibernate_order、t_hibernate_order_item
这两张表对应的model与mapper OrderVo
package com.yuan.model.vo; import com.yuan.model.Order;
import com.yuan.model.OrderItem; import java.util.ArrayList;
import java.util.List; public class OrderVo extends Order { private List<OrderItem> orderItems = new ArrayList<>(); public List<OrderItem> getOrderItems() {
return orderItems;
} public void setOrderItems(List<OrderItem> orderItems) {
this.orderItems = orderItems;
}
}
OrderItemVo
package com.yuan.model.vo; import com.yuan.model.Order;
import com.yuan.model.OrderItem; public class OrderItemVo extends OrderItem {
private Order order; public Order getOrder() {
return order;
} public void setOrder(Order order) {
this.order = order;
}
}
OrderMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yuan.mapper.OrderMapper">
<resultMap id="BaseResultMap" type="com.yuan.model.Order">
<constructor>
<idArg column="order_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
<arg column="order_no" jdbcType="VARCHAR" javaType="java.lang.String"/>
</constructor>
</resultMap> <resultMap id="OrderVoMap" type="com.yuan.model.vo.OrderVo">
<result property="orderId" column="order_id"></result>
<result property="orderNo" column="order_no"></result>
<!--<result property="orderItems" column=""></result>-->
<collection property="orderItems" ofType="com.yuan.model.OrderItem">
<result property="orderItemId" column="order_item_id"></result>
<result property="productId" column="product_id"></result>
<result property="quantity" column="quantity"></result>
<result property="oid" column="oid"></result>
</collection>
</resultMap> <sql id="Base_Column_List">
order_id, order_no
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from t_hibernate_order
where order_id = #{orderId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from t_hibernate_order
where order_id = #{orderId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yuan.model.Order">
insert into t_hibernate_order (order_id, order_no)
values (#{orderId,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yuan.model.Order">
insert into t_hibernate_order
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderId != null">
order_id,
</if>
<if test="orderNo != null">
order_no,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderId != null">
#{orderId,jdbcType=INTEGER},
</if>
<if test="orderNo != null">
#{orderNo,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yuan.model.Order">
update t_hibernate_order
<set>
<if test="orderNo != null">
order_no = #{orderNo,jdbcType=VARCHAR},
</if>
</set>
where order_id = #{orderId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yuan.model.Order">
update t_hibernate_order
set order_no = #{orderNo,jdbcType=VARCHAR}
where order_id = #{orderId,jdbcType=INTEGER}
</update> <!--通过一个订单id,查询出订单信息的同时,查询所有的订单项-->
<select id="selectByOrderId" resultMap="OrderVoMap" parameterType="java.lang.Integer">
SELECT * FROM t_hibernate_order o,t_hibernate_order_item oi WHERE o.`order_id`=oi.`oid`
AND oi.oid=#{orderId}
</select> </mapper>
OrderMapper.java
package com.yuan.mapper; import com.yuan.model.Order;
import com.yuan.model.vo.OrderVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import java.util.List; @Repository
public interface OrderMapper {
int deleteByPrimaryKey(Integer orderId); int insert(Order record); int insertSelective(Order record); Order selectByPrimaryKey(Integer orderId); int updateByPrimaryKeySelective(Order record); int updateByPrimaryKey(Order record); //通过一个订单id,查询出订单信息的同时,查询所有的订单项
List<OrderVo> selectByOrderId(@Param("orderId") Integer orderId); }
OrderItemMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yuan.mapper.OrderItemMapper" >
<resultMap id="BaseResultMap" type="com.yuan.model.OrderItem" >
<constructor >
<idArg column="order_item_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="product_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="quantity" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="oid" jdbcType="INTEGER" javaType="java.lang.Integer" />
</constructor>
</resultMap> <resultMap id="OrderItemVoMap" type="com.yuan.model.vo.OrderItemVo"> <result property="orderItemId" column="order_item_id"></result>
<result property="productId" column="product_id"></result>
<result property="quantity" column="quantity"></result>
<result property="oid" column="oid"></result>
<collection property="order" javaType="com.yuan.model.Order">
<result property="orderId" column="order_id"></result>
<result property="orderNo" column="order_no"></result>
</collection>
</resultMap> <sql id="Base_Column_List" >
order_item_id, product_id, quantity, oid
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from t_hibernate_order_item
where order_item_id = #{orderItemId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from t_hibernate_order_item
where order_item_id = #{orderItemId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yuan.model.OrderItem" >
insert into t_hibernate_order_item (order_item_id, product_id, quantity,
oid)
values (#{orderItemId,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{quantity,jdbcType=INTEGER},
#{oid,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yuan.model.OrderItem" >
insert into t_hibernate_order_item
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="orderItemId != null" >
order_item_id,
</if>
<if test="productId != null" >
product_id,
</if>
<if test="quantity != null" >
quantity,
</if>
<if test="oid != null" >
oid,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="orderItemId != null" >
#{orderItemId,jdbcType=INTEGER},
</if>
<if test="productId != null" >
#{productId,jdbcType=INTEGER},
</if>
<if test="quantity != null" >
#{quantity,jdbcType=INTEGER},
</if>
<if test="oid != null" >
#{oid,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yuan.model.OrderItem" >
update t_hibernate_order_item
<set >
<if test="productId != null" >
product_id = #{productId,jdbcType=INTEGER},
</if>
<if test="quantity != null" >
quantity = #{quantity,jdbcType=INTEGER},
</if>
<if test="oid != null" >
oid = #{oid,jdbcType=INTEGER},
</if>
</set>
where order_item_id = #{orderItemId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yuan.model.OrderItem" >
update t_hibernate_order_item
set product_id = #{productId,jdbcType=INTEGER},
quantity = #{quantity,jdbcType=INTEGER},
oid = #{oid,jdbcType=INTEGER}
where order_item_id = #{orderItemId,jdbcType=INTEGER}
</update> <!--通过一个订单项id,查询出订单项信息的同时,查询所所属的订单-->
<select id="selectByOrderItemId" resultMap="OrderItemVoMap" parameterType="java.lang.Integer">
SELECT * FROM t_hibernate_order o,t_hibernate_order_item oi WHERE o.`order_id`=oi.`oid`
AND oi.order_item_id=#{orderItemId}
</select> </mapper>
OrderItemMapper.java
package com.yuan.mapper; import com.yuan.model.OrderItem;
import com.yuan.model.vo.OrderItemVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import java.util.List; @Repository
public interface OrderItemMapper {
int deleteByPrimaryKey(Integer orderItemId); int insert(OrderItem record); int insertSelective(OrderItem record); OrderItem selectByPrimaryKey(Integer orderItemId); int updateByPrimaryKeySelective(OrderItem record); int updateByPrimaryKey(OrderItem record); //通过一个订单项id,查询出订单项信息的同时,查询所所属的订单
List<OrderItemVo> selectByOrderItemId(@Param("orderItemId") Integer orderItemId); }
Service层
OneToManyService.java
package com.yuan.service; import com.yuan.model.vo.OrderItemVo;
import com.yuan.model.vo.OrderVo;
import org.apache.ibatis.annotations.Param; import java.util.List; public interface OneToManyService { //通过一个订单项id,查询出订单项信息的同时,查询所所属的订单
List<OrderItemVo> selectByOrderItemId(Integer orderItemId); //通过一个订单id,查询出订单信息的同时,查询所有的订单项
List<OrderVo> selectByOrderId( Integer orderId); }
Service实现类
OneToManyServiceImpl.java
package com.yuan.service.impl; import com.yuan.mapper.OrderItemMapper;
import com.yuan.mapper.OrderMapper;
import com.yuan.model.vo.OrderItemVo;
import com.yuan.model.vo.OrderVo;
import com.yuan.service.OneToManyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service
public class OneToManyServiceImpl implements OneToManyService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private OrderItemMapper orderItemMapper;
@Override
public List<OrderItemVo> selectByOrderItemId(Integer orderItemId) {
return orderItemMapper.selectByOrderItemId(orderItemId);
} @Override
public List<OrderVo> selectByOrderId(Integer orderId) {
return orderMapper.selectByOrderId(orderId);
}
}
Test测试层代码
OneToManyServiceImplTest
package com.yuan.service.impl; import com.yuan.SpringBaseTest;
import com.yuan.model.OrderItem;
import com.yuan.model.vo.OrderItemVo;
import com.yuan.model.vo.OrderVo;
import com.yuan.service.OneToManyService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import static org.junit.Assert.*; public class OneToManyServiceImplTest extends SpringBaseTest { @Autowired
private OneToManyService oneToManyService;
@Test
public void selectByOrderItemId() {
List<OrderItemVo> orderItemVos = oneToManyService.selectByOrderItemId(36);
OrderItemVo orderItemVo = orderItemVos.get(0);
//此订单项的信息
System.out.println(orderItemVo);
//此订单项所对应的订单
System.out.println(orderItemVo.getOrder());
} @Test
public void selectByOrderId() { List<OrderVo> orderVos = oneToManyService.selectByOrderId(8);
OrderVo orderVo = orderVos.get(0);
System.out.println(orderVo);
System.out.println(orderVos.size());
for (OrderItem orderItem : orderVo.getOrderItems()) {
System.out.println(orderItem);
} }
}
测试结果
2、多对多
首先先用逆向生成工具生成t_hibernate_book、t_hibernate_book_category、t_hibernate_category,这两张表对应的model与mapper
HbookVo
package com.yuan.model.vo; import com.yuan.model.Category;
import com.yuan.model.HBook; import java.util.ArrayList;
import java.util.List; public class HbookVo extends HBook {
private List<Category> categories = new ArrayList<>(); public List<Category> getCategories() {
return categories;
} public void setCategories(List<Category> categories) {
this.categories = categories;
}
}
CategoryVo
package com.yuan.model.vo; import com.yuan.model.Category;
import com.yuan.model.HBook; import java.util.ArrayList;
import java.util.List; public class CategoryVo extends Category {
private List<HBook> hBooks = new ArrayList<>(); public List<HBook> gethBooks() {
return hBooks;
} public void sethBooks(List<HBook> hBooks) {
this.hBooks = hBooks;
}
}
CategoryMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yuan.mapper.CategoryMapper" >
<resultMap id="BaseResultMap" type="com.yuan.model.Category" >
<constructor >
<idArg column="category_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="category_name" jdbcType="VARCHAR" javaType="java.lang.String" />
</constructor>
</resultMap> <resultMap id="CategoryVoMap" type="com.yuan.model.vo.CategoryVo">
<result property="categoryId" column="category_id"></result>
<result property="categoryName" column="category_name"></result> <!--<result property="orderItems" column=""></result>-->
<collection property="hBooks" ofType="com.yuan.model.HBook">
<result property="bookId" column="book_id"></result>
<result property="bookName" column="book_name"></result>
<result property="price" column="price"></result>
</collection>
</resultMap> <sql id="Base_Column_List" >
category_id, category_name
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from t_hibernate_category
where category_id = #{categoryId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from t_hibernate_category
where category_id = #{categoryId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yuan.model.Category" >
insert into t_hibernate_category (category_id, category_name)
values (#{categoryId,jdbcType=INTEGER}, #{categoryName,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yuan.model.Category" >
insert into t_hibernate_category
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="categoryId != null" >
category_id,
</if>
<if test="categoryName != null" >
category_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="categoryId != null" >
#{categoryId,jdbcType=INTEGER},
</if>
<if test="categoryName != null" >
#{categoryName,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yuan.model.Category" >
update t_hibernate_category
<set >
<if test="categoryName != null" >
category_name = #{categoryName,jdbcType=VARCHAR},
</if>
</set>
where category_id = #{categoryId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yuan.model.Category" >
update t_hibernate_category
set category_name = #{categoryName,jdbcType=VARCHAR}
where category_id = #{categoryId,jdbcType=INTEGER}
</update> <!--通过一个类别的id,查询出类别信息的同时,还查询出各个类别对应的书籍-->
<select id="selectByCid" resultMap="CategoryVoMap" parameterType="java.lang.Integer" >
SELECT * FROM t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c
WHERE b.book_id = bc.bid AND bc.cid = c.category_id
AND c.category_id = #{cid}
</select> </mapper>
CategoryMapper
package com.yuan.mapper; import com.yuan.model.Category;
import com.yuan.model.vo.CategoryVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; @Repository
public interface CategoryMapper {
int deleteByPrimaryKey(Integer categoryId); int insert(Category record); int insertSelective(Category record); Category selectByPrimaryKey(Integer categoryId); int updateByPrimaryKeySelective(Category record); int updateByPrimaryKey(Category record); // 通过一个类别的id,查询出类别信息的同时,还查询出各个类别对应的书籍
CategoryVo selectByCid(@Param("cid") Integer cid); }
HBookMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yuan.mapper.HBookMapper" >
<resultMap id="BaseResultMap" type="com.yuan.model.HBook" >
<constructor >
<idArg column="book_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="book_name" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="price" jdbcType="REAL" javaType="java.lang.Float" />
</constructor>
</resultMap> <resultMap id="HbookVoMap" type="com.yuan.model.vo.HbookVo">
<result property="bookId" column="book_id"></result>
<result property="bookName" column="book_name"></result>
<result property="price" column="price"></result>
<!--<result property="orderItems" column=""></result>-->
<collection property="categories" ofType="com.yuan.model.Category">
<result property="categoryId" column="category_id"></result>
<result property="categoryName" column="category_name"></result>
</collection>
</resultMap> <sql id="Base_Column_List" >
book_id, book_name, price
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from t_hibernate_book
where book_id = #{bookId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from t_hibernate_book
where book_id = #{bookId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yuan.model.HBook" >
insert into t_hibernate_book (book_id, book_name, price
)
values (#{bookId,jdbcType=INTEGER}, #{bookName,jdbcType=VARCHAR}, #{price,jdbcType=REAL}
)
</insert>
<insert id="insertSelective" parameterType="com.yuan.model.HBook" >
insert into t_hibernate_book
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="bookId != null" >
book_id,
</if>
<if test="bookName != null" >
book_name,
</if>
<if test="price != null" >
price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="bookId != null" >
#{bookId,jdbcType=INTEGER},
</if>
<if test="bookName != null" >
#{bookName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
#{price,jdbcType=REAL},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yuan.model.HBook" >
update t_hibernate_book
<set >
<if test="bookName != null" >
book_name = #{bookName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
price = #{price,jdbcType=REAL},
</if>
</set>
where book_id = #{bookId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yuan.model.HBook" >
update t_hibernate_book
set book_name = #{bookName,jdbcType=VARCHAR},
price = #{price,jdbcType=REAL}
where book_id = #{bookId,jdbcType=INTEGER}
</update> <!--通过一个书籍id,查询出书籍的信息的同时,还查询出这本书对应的类别-->
<select id="selectByBid" resultMap="HbookVoMap" parameterType="java.lang.Integer" >
SELECT * FROM t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c
WHERE b.book_id = bc.bid AND bc.cid = c.category_id
AND b.book_id=#{bid}
</select> </mapper>
HBookMapper
package com.yuan.mapper; import com.yuan.model.HBook;
import com.yuan.model.vo.HbookVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; @Repository
public interface HBookMapper {
int deleteByPrimaryKey(Integer bookId); int insert(HBook record); int insertSelective(HBook record); HBook selectByPrimaryKey(Integer bookId); int updateByPrimaryKeySelective(HBook record); int updateByPrimaryKey(HBook record); // 通过一个书籍id,查询出书籍的信息的同时,还查询出这本书对应的类别
HbookVo selectByBid(@Param("bid") Integer bid); }
Service层相关代码
ManyToManyService
package com.yuan.service; import com.yuan.model.vo.CategoryVo;
import com.yuan.model.vo.HbookVo;
import org.apache.ibatis.annotations.Param; public interface ManyToManyService { // 通过一个书籍id,查询出书籍的信息的同时,还查询出这本书对应的类别
HbookVo selectByBid(Integer bid); // 通过一个类别的id,查询出类别信息的同时,还查询出各个类别对应的书籍
CategoryVo selectByCid(Integer cid);
}
Service层实现类代码
ManyToManyServiceImpl
package com.yuan.service.impl; import com.yuan.mapper.CategoryMapper;
import com.yuan.mapper.HBookMapper;
import com.yuan.model.vo.CategoryVo;
import com.yuan.model.vo.HbookVo;
import com.yuan.service.ManyToManyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; @Service
public class ManyToManyServiceImpl implements ManyToManyService {
@Autowired
private CategoryMapper categoryMapper;
@Autowired
private HBookMapper hBookMapper; @Override
public HbookVo selectByBid(Integer bid) {
return hBookMapper.selectByBid(bid);
} @Override
public CategoryVo selectByCid(Integer cid) {
return categoryMapper.selectByCid(cid);
}
}
Test测试类
ManyToManyServiceImplTest
package com.yuan.service.impl; import com.yuan.SpringBaseTest;
import com.yuan.model.Category;
import com.yuan.model.HBook;
import com.yuan.model.vo.CategoryVo;
import com.yuan.model.vo.HbookVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import static org.junit.Assert.*; public class ManyToManyServiceImplTest extends SpringBaseTest { @Autowired
private ManyToManyServiceImpl manyToManyService; // 通过一个书籍id,查询出书籍的信息的同时,还查询出这本书对应的类别
@Test
public void selectByBid() {
HbookVo hbookVo = manyToManyService.selectByBid(8);
System.out.println(hbookVo);
for (Category category : hbookVo.getCategories()) {
System.out.println(category);
} } // 通过一个类别的id,查询出类别信息的同时,还查询出各个类别对应的书籍
@Test
public void selectByCid() {
CategoryVo categoryVo = manyToManyService.selectByCid(8);
System.out.println(categoryVo);
for (HBook gethBook : categoryVo.gethBooks()) {
System.out.println(gethBook);
} }
}
测试方法一:selectByBid
测试方法二:selectByCid
谢谢观看!!!
mybatis之关联关系映射的更多相关文章
- mybatis一对一关联关系映射
mybatis一对一关联关系映射 在关联关系中,有一对一,一对多,多对多三种关联关系. 一对一关系:在操作上,任意一方引入对方的主键作为外键. 一对多关系:在"多"的一方添加&qu ...
- mybatis多对多关联关系映射
mybatis多对多关联关系映射 多对多关系在java类实体中表示为,一个类中包含了集合为另一个类的属性.而这连个实体都需要包含对方的集合类的属性. 例如:订单和商品,一个订单包含多个商品,一个商品又 ...
- mybatis一对多关联关系映射
mybatis一对多关联关系映射 一对多关联关系只需要在多的一方引入少的一方的主键作为外键即可.在实体类中就是反过来,在少的一方添加多的一方,声明一个List 属性名 作为少的一方的属性. 用户和订单 ...
- Hibernate(6)—— 一对多 和 多对多关联关系映射(xml和注解)总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: One to Many 映射关系 多对一单向外键关联(XML/Annotation) 一对多单向外键关联(XM ...
- Hibernate—— 一对多 和 多对多关联关系映射(xml和注解)总结(转载)
One to Many 映射关系 多对一单向外键关联(XML/Annotation) 一对多单向外键关联(XML/Annotation) 懒加载和积极加载 一对多双向外键关联(XML/Annotati ...
- Mybatis的关联映射案例
主要是对之前学习的关联映射做一个案例,自己动手实践一下,可以理解的更好一点. 开发环境 开发工具:idea Java环境: jdk1.8.0_121 数据库:SQLServer 项目结构,里面包含了三 ...
- mybatis之关联关系
前言:在我们之前的hibernate中我们是学过了关联关系的,所以我们在本章给讲一讲mybatis的关联关系. mybatis的关联关系一对多的测试1.通过逆向工程生成Hbook,HbookCateg ...
- Mybatis(二) SQL映射文件
SQL映射文件 单条件查询 1. 在UserMapper接口添加抽象方法 //根据用户名模糊查询 List<User> getUserListByName(); 2. 在UserMappe ...
- MyBatis加强(1)~myBatis对象关系映射(多对一关系、一对多关系)、延迟/懒加载
一.myBatis对象关系映射(多对一关系.一对多关系) 1.多对一关系: ---例子:多个员工同属于一个部门. (1)myBatis发送 额外SQL: ■ 案例:员工表通过 dept_id 关联 部 ...
随机推荐
- 深入浅出JVM(一):运行时数据区域
程序计数器 线程私有 指向了正在执行的虚拟机字节码指令的地址:如果是本地方法,数值为空 没有 OutOfMemoryError 错误的区域 Java虚拟机栈 线程私有: 生命周期与线程相同: 代表着 ...
- Linux08 文件系统
对于磁盘等各类存储设备中所有的数据都以0和1的概念,但对于用户来说,0和1是没有任何意义的,这时候就需要一种类似于“翻译”的机制存在于用户和磁盘之间,Linux中采用的是文件系统+虚拟文件系统(Vir ...
- 什么是openshift
Openshift是一个开源的容器云平台,底层基于当前容器的事实标准编排系统Kubernetes和docker引擎,企业可以基于此平台搭建内部Paas平台,贯穿CI/CD流程,提高企业IT效率,拥抱D ...
- 不一样的go语言-athens源码概览
前言 上一篇文章介绍了athens私服的安装以及vgo download protocol的简要介绍.本文着重介绍go proxy sever的实现原理以及athens是如何实现的. go get ...
- golang 实现定时任务
在实际开发过程中,我们有时候需要编写一些定时任务.当然我们可以使用crontab命令实现我们的需求.但是这种方法不满足一些定制化场景,同时会依赖具体的操作系统环境. 定时任务 在golang中我们可以 ...
- Python中logging快速上手教程
本文使用得日志需要导入logging模块和logging.handlers模块,即 import logging import logging.handlers ''' author = " ...
- java第三次面试总结
这次面试是二面,由于自己的经验不足,面试的结果不是很令人满意,所以与这家公司失之交臂,在这里记录一下经历,吸取教训. 之前的一面是笔试+面试,面试是主管,今天的面试是总监.在前台招待我的时候,还跟我说 ...
- 分享-SpringCloud微服务架构图
1: 为大家分享一张SpringCloud微服务通用架构图 标题 此图仅供参考: 需要原图的同学请移步 >>>>>>>>> 这里 如有不合理的地 ...
- font-size 你所不知道的值
说起 font-size ,大家应该都知道是做什么的: CSS 属性指定字体的大小.因为该属性的值会被用于计算em和ex长度单位,定义该值可能改变其他元素的大小. 那么font-size 的值也是多 ...
- canvas教程(二) 绘制直线
经过 canvas 教程(一) 简介 我们知道了 canvas 的一些基本情况 而本次是给大家带来直线的绘制 canvas 中,基本图形有两种,一种是直线,还有一种是曲线 但是无论是直线还是曲线,我们 ...