MyBatis-Plus 字段类型处理器TypeHandler

时间:2025-03-19 08:28:46

@MappedJdbcTypes()  //数据库类型

@MappedTypes({List.class})          //java数据类型

@Log

public class ListTypeHandler implements TypeHandler<List<String>> {

 

    @Override

    public void setParameter(PreparedStatement ps, int i,

                             List<String> parameter, JdbcType jdbcType) throws SQLException {

        ("method ====>>> setParameter");

        String hobbys = dealListToOneStr(parameter);

        (i , hobbys);

    }

 

    /**

     * 集合拼接字符串

     * @param parameter

     * @return

     */

    private String dealListToOneStr(List<String> parameter){

        if(parameter == null || () <=0)

            return null;

        String res = "";

        for (int i = 0 ;i < (); i++) {

            if(i == ()-1){

                res+=(i);

                return res;

            }

            res+=(i)+",";

        }

        return null;

    }

     

    @Override

    public List<String> getResult(ResultSet rs, String columnName)

            throws SQLException {

        ("method ====>>> getResult(ResultSet rs, String columnName)");

        return ((columnName).split(","));

    }

 

    @Override

    public List<String> getResult(ResultSet rs, int columnIndex)

            throws SQLException {

        ("method ====>>> getResult(ResultSet rs, int columnIndex)");

        return ((columnIndex).split(","));

    }

 

    @Override

    public List<String> getResult(CallableStatement cs, int columnIndex) throws SQLException{

        ("method ====>>> getResult(CallableStatement cs, int columnIndex)");

        String hobbys = (columnIndex);

        return ((","));

    }

}