SSM一对一映射、映射里带映射的Mapper.xml配置
2022/1/28 6:06:55
本文主要是介绍SSM一对一映射、映射里带映射的Mapper.xml配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.需求
表1 category 是标签表,包含主标签和子标签,通过自关联查询得到完整结果
表2 是商品表
2.配置完成的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="top.roud.buyfresh.dao.ProductMapper"> <resultMap id="CategoryResult" type="Category"> <id column="sub_id" property="id"/> <result column="sub_name" property="name"/> </resultMap> <resultMap id="CategoryWithSubResult" type="Category"> <id column="id" property="id"/> <result column="name" property="name"/> <collection property="categories" resultMap="CategoryResult"/> </resultMap> <resultMap type="Product" id="ProductResult"> <id column="id" property="id" /> <result column="name" property="name" /> <result column="price" property="price" /> <result column="producingArea" property="producingArea" /> <result column="groundingDate" property="groundingDate" /> <result column="goodsCode" property="goodsCode"/> <result column="description" property="description" /> <result column="image" property="image" /> <result column="introduction_image" property="introduction_image"/> <association property="category" column="category_id" select="findCategoryById" /> </resultMap> <select id="findCategoryById" resultMap="CategoryWithSubResult"> select t3.id, t3.name,t3.sub_id,t3.sub_name from( select t1.id id,t1.name name,t2.id sub_id,t2.name sub_name from bf_category t1,bf_category t2 where t1.parent_id=0 and t1.id=t2.parent_id) t3 where id=#{agr0} </select> <select id="findProductById" resultType="Product" parameterType="int"> select id,name,price,producingArea,groundingDate,goodsCode,description,image,introduction_image,category_id from bf_product where id=#{arg0} </select> <select id="findAllProducts" resultMap="ProductResult"> select id,name,price,producingArea,groundingDate,goodsCode,description,image,introduction_image,category_id from bf_product </select> <select id="findByCategoryId" resultMap="ProductResult" parameterType="int"> select id,name,price,producingArea,groundingDate,goodsCode,description,image,introduction_image,category_id from bf_product where category_id=#{arg0} </select> </mapper>
这篇关于SSM一对一映射、映射里带映射的Mapper.xml配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14XMLHTTPRequest教程:初学者必备指南
- 2024-10-10XMLHTTPRequest项目实战:从入门到上手
- 2024-02-26lxml not found please install it
- 2022-09-16使用Druid数据源-开启监控-xml的方式-配置类的方式
- 2022-09-08IDEA中pom.xml配置文件依赖文件版本号报红的最有效解决办法
- 2022-09-05如何更换项目中web.xml的版本
- 2022-09-02使用dom4j xml解析文件数据
- 2022-08-24可扩展标记语言——XML
- 2022-08-23mybatis 配置文件mybatis.xml的加载过程
- 2022-08-162022最新有效 哔哩哔哩Bilibili手机端.m4s文件缓存转.mp4教程 支持每个视频单独一个文件夹 支持转换xml弹幕