81,122
社区成员




CREATE TABLE `d_shop_sku` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
`category_id` bigint(20) unsigned DEFAULT NULL,
`attribute_ids` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE `d_shop_attribute` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`sku_id` bigint(20) unsigned DEFAULT NULL,
`name` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
<table tableName="d_shop_sku" domainObjectName="ShopSku" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="MySql" identity="true" />
<columnOverride column="attribute_ids" javaType="java.util.List" typeHandler="com.zcm.mybatis.typehandler.IntegerListTypeHandler" />
</table>
<table tableName="d_shop_attribute" domainObjectName="ShopAttribute" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="MySql" identity="true" />
</table>
package com.zcm.mybatis.dao.pojo;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
public class ShopSku extends com.zcm.mybatis.dao.entity.ShopSku {
@Getter
@Setter
private List attributes;
}
<resultMap id="AttributeResultMap" type="com.zcm.mybatis.dao.entity.ShopAttribute">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="sku_id" jdbcType="VARCHAR" property="skuId" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<resultMap id="BasePlusResultMap3" type="com.zcm.mybatis.dao.pojo.ShopSku">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="category_id" jdbcType="BIGINT" property="categoryId" />
<result column="attribute_ids" jdbcType="VARCHAR" property="attributeIds" javaType="java.util.List" typeHandler="com.zcm.mybatis.typehandler.IntegerListTypeHandler" />
<collection column="attributeIds" property="attributes" ofType="com.zcm.mybatis.dao.entity.ShopAttribute" select="getAttribute3">
</collection>
</resultMap>
<select id="getById3" resultMap="BasePlusResultMap3">
select * from d_shop_sku
where id = #{id,jdbcType = BIGINT}
</select>
<select id="getAttribute3" resultMap="AttributeResultMap">
select * from d_shop_attribute
where id in
<foreach collection="list" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
@Test
public void getById3() // 单参数: Long
{
var sku = shopSkuDao.getById3(1L);
System.out.println(sku == null);
if(sku != null)
{
System.out.println(JSON.toJSONString(sku, SerializerFeature.WRITE_MAP_NULL_FEATURES));
}
}
2019-05-07 14:00:28.436 INFO 36522 --- [ main] com.zaxxer.hikari.HikariDataSource : test - Starting...
2019-05-07 14:00:28.704 INFO 36522 --- [ main] com.zaxxer.hikari.HikariDataSource : test - Start completed.
2019-05-07 14:00:28.722 DEBUG 36522 --- [ main] com.zcm.mybatis.dao.ShopSkuDao.getById3 : ==> Preparing: select * from d_shop_sku where id = ?
2019-05-07 14:00:28.786 DEBUG 36522 --- [ main] com.zcm.mybatis.dao.ShopSkuDao.getById3 : ==> Parameters: 1(Long)
2019-05-07 14:00:28.844 DEBUG 36522 --- [ main] com.zcm.mybatis.dao.ShopSkuDao.getById3 : <== Total: 1
false
{attributes:[],name:"桔子1",id:1,attributeIds:[3,1],categoryId:2}