1
This commit is contained in:
@@ -9,14 +9,14 @@ CREATE TABLE mall_product
|
||||
attribute text[] DEFAULT '' NOT NULL,
|
||||
unit VARCHAR(12),
|
||||
category_id int8 DEFAULT '' NOT NULL,
|
||||
category_ids VARCHAR(255) DEFAULT '' NOT NULL,
|
||||
category_ids bigint[] DEFAULT '' NOT NULL,
|
||||
cost_price DECIMAL(10, 2) DEFAULT 0.00 NOT NULL,
|
||||
original_price DECIMAL(10, 2) DEFAULT 0.00 NOT NULL,
|
||||
retail_price DECIMAL(10, 2) DEFAULT 0.00 NOT NULL,
|
||||
profit DECIMAL(10, 2) DEFAULT 0.00 NOT NULL,
|
||||
sales int4 DEFAULT 0 NOT NULL,
|
||||
spu_qty int4 DEFAULT 0 NOT NULL,
|
||||
tags text DEFAULT '' NOT NULL,
|
||||
tags text[] DEFAULT '' NOT NULL,
|
||||
status int4 DEFAULT 0 NULL,
|
||||
create_user int8 NULL,
|
||||
create_dept int8 NULL,
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.springblade.common.handler;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@MappedJdbcTypes(JdbcType.ARRAY)
|
||||
@MappedTypes(List.class)
|
||||
public class PgBigIntArrayToListTypeHandler extends BaseTypeHandler<List<Long>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<Long> parameter, JdbcType jdbcType) throws SQLException {
|
||||
// 将 List<Long> 转换为 PostgreSQL 的 bigint[]
|
||||
Array array = ps.getConnection().createArrayOf("bigint", parameter.toArray());
|
||||
ps.setArray(i, array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
// 从 ResultSet 中读取数组并转换为 List<Long>
|
||||
Array array = rs.getArray(columnName);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
// 从 ResultSet 中按列索引读取数组并转换为 List<Long>
|
||||
Array array = rs.getArray(columnIndex);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
// 从 CallableStatement 中读取数组并转换为 List<Long>
|
||||
Array array = cs.getArray(columnIndex);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,19 +8,19 @@
|
||||
<result column="spu_sn" property="spuSn"/>
|
||||
<result column="spu_name" property="spuName"/>
|
||||
<result column="main_img" property="mainImg"/>
|
||||
<result column="detail_img" property="detailImg" typeHandler="org.springblade.common.handler.TextArrayTypeHandler"/>
|
||||
<result column="top_img" property="topImg" typeHandler="org.springblade.common.handler.TextArrayTypeHandler"/>
|
||||
<result column="attribute" property="attribute"/>
|
||||
<result column="detail_img" property="detailImg" typeHandler="org.springblade.common.handler.PgStringArrayToListTypeHandler"/>
|
||||
<result column="top_img" property="topImg" typeHandler="org.springblade.common.handler.PgStringArrayToListTypeHandler"/>
|
||||
<result column="attribute" property="attribute" typeHandler="org.springblade.common.handler.PgStringArrayToListTypeHandler"/>
|
||||
<result column="unit" property="unit"/>
|
||||
<result column="category_id" property="categoryId"/>
|
||||
<result column="category_ids" property="categoryIds"/>
|
||||
<result column="category_ids" property="categoryIds" typeHandler="org.springblade.common.handler.PgBigIntArrayToListTypeHandler"/>
|
||||
<result column="cost_price" property="costPrice"/>
|
||||
<result column="original_price" property="originalPrice"/>
|
||||
<result column="retail_price" property="retailPrice"/>
|
||||
<result column="profit" property="profit"/>
|
||||
<result column="sales" property="sales"/>
|
||||
<result column="spu_qty" property="spuQty"/>
|
||||
<result column="tags" property="tags"/>
|
||||
<result column="tags" property="tags" typeHandler="org.springblade.common.handler.PgStringArrayToListTypeHandler"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_dept" property="createDept"/>
|
||||
|
||||
@@ -31,7 +31,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.common.handler.TextArrayTypeHandler;
|
||||
import org.springblade.common.handler.PgBigIntArrayToListTypeHandler;
|
||||
import org.springblade.common.handler.PgStringArrayToListTypeHandler;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
@@ -69,19 +70,19 @@ public class MallProductEntity extends BaseEntity {
|
||||
/**
|
||||
* 详情图(多图,逗号分割)
|
||||
*/
|
||||
@TableField(typeHandler = TextArrayTypeHandler.class)
|
||||
@TableField(typeHandler = PgStringArrayToListTypeHandler.class)
|
||||
@Schema(description = "详情图")
|
||||
private List<String> detailImg;
|
||||
/**
|
||||
* 顶图(多图,逗号分割)
|
||||
*/
|
||||
@TableField(typeHandler = TextArrayTypeHandler.class)
|
||||
@TableField(typeHandler = PgStringArrayToListTypeHandler.class)
|
||||
@Schema(description = "详情页顶图")
|
||||
private List<String> topImg;
|
||||
/**
|
||||
* 规格详情
|
||||
*/
|
||||
@TableField(typeHandler = TextArrayTypeHandler.class)
|
||||
@TableField(typeHandler = PgStringArrayToListTypeHandler.class)
|
||||
@Schema(description = "规格详情")
|
||||
private List<String> attribute;
|
||||
/**
|
||||
@@ -97,8 +98,9 @@ public class MallProductEntity extends BaseEntity {
|
||||
/**
|
||||
* cate_id分类
|
||||
*/
|
||||
@TableField(typeHandler = PgBigIntArrayToListTypeHandler.class)
|
||||
@Schema(description = "cate_id分类")
|
||||
private String categoryIds;
|
||||
private List<Long> categoryIds;
|
||||
/**
|
||||
* 成本价
|
||||
*/
|
||||
@@ -132,7 +134,8 @@ public class MallProductEntity extends BaseEntity {
|
||||
/**
|
||||
* 标签(多标签,逗号分割 )
|
||||
*/
|
||||
@Schema(description = "标签(多标签,逗号分割 )")
|
||||
private String tags;
|
||||
@TableField(typeHandler = PgStringArrayToListTypeHandler.class)
|
||||
@Schema(description = "标签")
|
||||
private List<String> tags;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user