在.xml
文件編寫中有報錯,The content of element type "resultMap" must match ...
。參考了這篇博客的解答https://blog.csdn.net/chenxing1990/article/details/79649958
sql語句一對多查詢,<resultMap>
標簽中要按照
<id>
<result>
<association>
<collection>
的順序來排列
實體類Product_order
要extends
擴展類Product_orderExtend
public class Product_order extends Product_orderExtend {private Long orderId;private Integer sellerId;private Long goodId;private Integer purchaserId;private Integer addressId;private BigDecimal price;private Integer shippingMethod;private Integer pickupMethod;private Boolean usePoint;private Integer orderState;private Integer gainPoint;private Date createDate;
}
在擴展類Product_orderExtend
中
public class Product_orderExtend {private Good good;private User seller;private User purchaser;private Address address;
}
sql兩個表關聯查詢,mybatis/mapper/extend
下的xml
文件中寫擴展mapper
<?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.group5.springboot.crud.mapper.Product_orderMapper"><resultMap type="com.group5.springboot.crud.common.domain.Product_order" id="Product_orderAssociationResultMap"><id property="orderId" column="order_id"/><result property="price" column="price"/><result property="shippingMethod" column="shipping_method"/><result property="pickupMethod" column="pickup_method"/><result property="usePoint" column="use_point"/><result property="orderState" column="order_state"/><result property="gainPoint" column="gain_point"/><result property="createDate" column="create_date"/><association property="good" javaType="com.group5.springboot.crud.common.domain.Good"><id column="good_id" jdbcType="BIGINT" property="goodId" /><result column="image_path" jdbcType="VARCHAR" property="imagePath" /><result column="start_time" jdbcType="TIMESTAMP" property="startTime" /><result column="end_time" jdbcType="TIMESTAMP" property="endTime" /><result column="quantity" jdbcType="INTEGER" property="quantity" /><result column="origin_place" jdbcType="VARCHAR" property="originPlace" /><result column="type" jdbcType="INTEGER" property="type" /><result column="city" jdbcType="VARCHAR" property="city" /><result column="brand" jdbcType="VARCHAR" property="brand" /><result column="content" jdbcType="VARCHAR" property="content" /><result column="good_name" jdbcType="VARCHAR" property="goodName" /><result column="price" jdbcType="DECIMAL" property="price" /><result column="status" jdbcType="INTEGER" property="status" /><result column="current_price" jdbcType="DECIMAL" property="currentPrice" /></association><association property="seller" javaType="com.group5.springboot.crud.common.domain.User"><id column="id" jdbcType="INTEGER" property="id" /><result column="username" jdbcType="VARCHAR" property="username" /><result column="phone_num" jdbcType="VARCHAR" property="phoneNum" /><result column="email" jdbcType="VARCHAR" property="email" /><result column="password" jdbcType="VARCHAR" property="password" /><result column="rewardpoint" jdbcType="INTEGER" property="rewardpoint" /><result column="profile" jdbcType="VARCHAR" property="profile" /></association><association property="purchaser" javaType="com.group5.springboot.crud.common.domain.User"><id column="id" jdbcType="INTEGER" property="id" /><result column="username" jdbcType="VARCHAR" property="username" /><result column="phone_num" jdbcType="VARCHAR" property="phoneNum" /><result column="email" jdbcType="VARCHAR" property="email" /><result column="password" jdbcType="VARCHAR" property="password" /><result column="rewardpoint" jdbcType="INTEGER" property="rewardpoint" /><result column="profile" jdbcType="VARCHAR" property="profile" /></association><association property="address" javaType="com.group5.springboot.crud.common.domain.Address"><id column="address_id" jdbcType="INTEGER" property="addressId" /><result column="receiver" jdbcType="VARCHAR" property="receiver" /><result column="contact_number" jdbcType="VARCHAR" property="contactNumber" /><result column="user_id" jdbcType="INTEGER" property="userId" /><result column="adresss" jdbcType="VARCHAR" property="adresss" /><result column="isdefault" jdbcType="INTEGER" property="isdefault" /></association></resultMap><select id="selectAssociationPurchaser" parameterType="int" resultMap="Product_orderAssociationResultMap">select * from product_order p, user u1, user u2, good g, address awhere p.purchaser_id=#{purchaserId} and a.address_id=p.address_id and u1.id = p.seller_id and u2.id = p.purchaser_id and g.good_id=p.good_id</select><select id="selectAssociationSeller" parameterType="int" resultMap="Product_orderAssociationResultMap">select * from product_order p, user u1, user u2, good g, address awhere p.seller_id=#{sellerId} and a.address_id=p.address_id and u1.id = p.seller_id and u2.id = p.purchaser_id and g.good_id=p.good_id</select>
</mapper>
同理在mapper/extend
中添加接口。
public interface Browsing_historyExtendMapper {List<Good> selectGoodsByUid(int user_id);List<Browsing_history> selectAssociationGood(int userId);
}
略。
略。
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态