Просмотр исходного кода

fix(handler): 修复mysqlplus查询list转换问题-回退

lixuesong 4 лет назад
Родитель
Сommit
a1ed3dfb43

+ 8 - 6
hnqz-common/hnqz-common-data/src/main/java/com/qunzhixinxi/hnqz/common/data/handler/ListToStringTypeHandler.java

@@ -1,5 +1,6 @@
 package com.qunzhixinxi.hnqz.common.data.handler;
 
+import cn.hutool.core.collection.CollectionUtil;
 import org.apache.ibatis.type.JdbcType;
 import org.apache.ibatis.type.MappedJdbcTypes;
 import org.apache.ibatis.type.MappedTypes;
@@ -18,17 +19,18 @@ import java.util.List;
  * @author lixuesong
  * @date 2021年07月15日 17:10
  */
-@MappedTypes(value = { List.class })
-@MappedJdbcTypes(value = JdbcType.VARCHAR)
+// 加上下面两行,可以解决mybatis plus的list、getone等查询方法 查不到List<String>的问题
+//@MappedTypes(value = { List.class })
+//@MappedJdbcTypes(value = JdbcType.VARCHAR)
 public class ListToStringTypeHandler implements TypeHandler<List<String>> {
 
 	@Override
 	public void setParameter(PreparedStatement preparedStatement, int i, List<String> strings, JdbcType jdbcType) throws SQLException {
-		StringBuffer sb = new StringBuffer();
-		for (String s : strings) {
-			sb.append(s).append(",");
+		if (CollectionUtil.isNotEmpty(strings)) {
+			preparedStatement.setString(i, String.join(",", strings));
+		} else {
+			preparedStatement.setString(i, "");
 		}
-		preparedStatement.setString(i, sb.toString().substring(0, sb.toString().length() - 1));
 	}
 
 	@Override