MybatisPlus,Mybatis, 實現一對多

 2023-11-01 阅读 31 评论 0

摘要:我這里是拿商品做為例子 不多說直接上代碼 ? Mapper.xml MybatisPlus、? <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.d

我這里是拿商品做為例子

不多說直接上代碼

?

Mapper.xml

MybatisPlus、?

<?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.nf147.mall.dao.CommodityMapper"><resultMap id="BaseResultMap" type="com.nf147.mall.entity.Commodity"><id column="product_id" jdbcType="INTEGER" property="productId"/><result column="category_id" jdbcType="INTEGER" property="categoryId"/><result column="product_code" jdbcType="VARCHAR" property="productCode"/><result column="product_name" jdbcType="VARCHAR" property="productName"/><result column="product_content" jdbcType="LONGVARCHAR" property="productContent"/><!--這里還需要標明關系  property屬性對應是實體類的字段名--><association property="standard" resultMap="StandardResultMap"></association><association property="dommodityattribute" resultMap="DommodityattributeResultMap"></association></resultMap><!--這個是要查詢的表1  總之你直接去要查詢的表復制就好 -->
<resultMap id="DommodityattributeResultMap" type="com.nf147.mall.entity.Dommodityattribute"><id column="id" jdbcType="INTEGER" property="id"/><result column="product_id" jdbcType="INTEGER" property="productId"/><result column="product_simg" jdbcType="VARCHAR" property="productSimg"/>
</resultMap><!--這個是要查詢的表2-->
<resultMap id="StandardResultMap" type="com.nf147.mall.entity.Standard"><id column="specs_id" jdbcType="INTEGER" property="specsId"/><result column="product_id" jdbcType="INTEGER" property="productId"/><result column="product_specs" jdbcType="VARCHAR" property="productSpecs"/><result column="product_price" jdbcType="DECIMAL" property="productPrice"/>
</resultMap>

?

實體類:

public class Commodity {private Integer productId;private Integer categoryId;private String productCode;private String productName;private String productContent;private Standard standard;      //第一個表的實體類private Dommodityattribute dommodityattribute;  //第二個表的實體類  然后再提供 get 和 set 的方法public Standard getStandard() {return standard;}public void setStandard(Standard standard) {this.standard = standard;}public Dommodityattribute getDommodityattribute() {return dommodityattribute;}public void setDommodityattribute(Dommodityattribute dommodityattribute) {this.dommodityattribute = dommodityattribute;}public Integer getProductId() {return productId;}public void setProductId(Integer productId) {this.productId = productId;}public Integer getCategoryId() {return categoryId;}public void setCategoryId(Integer categoryId) {this.categoryId = categoryId;}public String getProductCode() {return productCode;}public void setProductCode(String productCode) {this.productCode = productCode == null ? null : productCode.trim();}public String getProductName() {return productName;}public void setProductName(String productName) {this.productName = productName == null ? null : productName.trim();}public String getProductContent() {return productContent;}public void setProductContent(String productContent) {this.productContent = productContent == null ? null : productContent.trim();}
}

希望能幫助大家,謝謝。

?

java雙數據源。轉載于:https://www.cnblogs.com/nongzihong/p/10275523.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/166108.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息