1、多对一配置文件
<?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.atguigu.springcloud.dao.ProductDao">
<select id="findAll" resultType="Product">
select ID,Name,db_source from Product;
</select>
<insert id="addProduct" parameterType="Product">
INSERT INTO Product(ID,Name,AddDate,Status,db_source) VALUES(#{ID},#{Name},#{AddDate},#{Status},DATABASE());
</insert>
<!--多对一-->
<select id="findById" resultMap="Product_ProductType" parameterType="String">
select * from Product where ID=#{value};
</select>
<resultMap id="Product_ProductType" type="com.atguigu.springcloud.entities.Product">
<result property="ID" column="ID"></result>
<result property="Name" column="Name"></result>
<association property="ProductTypeEntity" column="ProductTypeID" java

本文档展示了MyBatis中多对一和一对多的配置示例。在`ProductDao`配置中,有用于查找所有产品、添加产品以及根据ID获取包含产品类型信息的产品的方法。而在`ProductTypeDao`配置中,包含了查找所有产品类型、添加产品类型以及通过ID获取包含产品列表的产品类型的方法。这两个配置展示了如何在MyBatis中处理关联关系。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



