扩展服务
This commit is contained in:
@@ -35,6 +35,11 @@
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.13</version> <!-- 推荐使用最新稳定版本 -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -31,4 +31,5 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode SKU_SERVICE_MATERIAL_NOT_EXISTS = new ErrorCode(10019, "服务物料详情不存在");
|
||||
ErrorCode SKU_SERVICES_FORM_NOT_EXISTS = new ErrorCode(10021, "商品SKU扩展服务表单不存在");
|
||||
ErrorCode SKU_SERVICE_TRANSPORT_NOT_EXISTS = new ErrorCode(10022, "服务遗体运输不存在");
|
||||
ErrorCode SKU_SERVICE_DETAILS_NOT_EXISTS = new ErrorCode(10023, "服务详情不存在");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.tashow.cloud.productapi.general;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 处理 List<String> 与数据库逗号分隔字符串之间的转换
|
||||
*/
|
||||
public class StringListTypeHandler extends BaseTypeHandler<List<String>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
|
||||
// 将 List 转为逗号分隔的字符串
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int j = 0; j < parameter.size(); j++) {
|
||||
if (j > 0) sb.append(",");
|
||||
sb.append(parameter.get(j));
|
||||
}
|
||||
ps.setString(i, sb.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String str = rs.getString(columnName);
|
||||
return parseStringToList(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String str = rs.getString(columnIndex);
|
||||
return parseStringToList(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String str = cs.getString(columnIndex);
|
||||
return parseStringToList(str);
|
||||
}
|
||||
|
||||
private List<String> parseStringToList(String str) {
|
||||
if (str == null || str.trim().length() == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(str.split(","));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user