当前使用版本(必填,否则不予处理)

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

该问题是如何引起的?(确定最新版也有问题再提!!!)

生产项目无法升级.编写实现AbstractMethod类做通用关联查询

重现步骤(如果有就写完整)

public class SelectLastDataGroupByPointId extends AbstractMethod { private static final String MAPPER_METHOD = "selectLastDataGroupByPointId";

private static final String SQL_TEMPLATE3 = "<script>select a.*\n" +
        "from %s a,\n" +
        "     (select measure_point_id, max(time) time  from %s group by measure_point_id) b\n" +
        "where a.measure_point_id = b.measure_point_id\n" +
        "  and a.time = b.time</script>";
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(SQL_TEMPLATE3,
            tableInfo.getTableName(), tableInfo.getTableName()), modelClass);
    return this.addSelectMappedStatementForTable(mapperClass, MAPPER_METHOD, sqlSource, tableInfo);
}

}

调用selectLastDataGroupByPointId方法就会报错. 改写sql为:"" 就没有问题.

报错信息

; Column index out of range.; nested exception is java.sql.SQLException: Column index out of range. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:110) ~[spring-jdbc-5.3.8.jar:5.3.8] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) ~[spring-jdbc-5.3.8.jar:5.3.8] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173) ~[mybatis-plus-core-3.4.2.jar:3.4.2] at chc.service.base.IMyService.selectLastDataGroupByPointId(IMyService.java:59) ~[classes/:na] ... Caused by: java.sql.SQLException: Column index out of range. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.23.jar:8.0.23] at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData.getColumnLabel(ShardingSphereResultSetMetaData.java:106) ~[shardingsphere-jdbc-core-5.1.1.jar:5.1.1] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ~[mybatis-spring-2.0.5.jar:2.0.5]

Comment From: nieqiurong

看不清你的,提供复现工程.

Comment From: MoonLionK

找到原因了是mysql数据库json类型字段转换到对象JsonObject类型的问题.如何在这里统一处理呢?

Comment From: HillCheuang

可能我的情况与你不一致,但是我是这么解决的 在实体类加上@TableName 一定要设置 autoResultMap =true 其次在List字段上面设置 @TableField(typeHandler = FastjsonTypeHandler.class) 具体代码如下:

@Data
@TableName(value = "test", autoResultMap = true)
public class Test {

    @TableId(type = IdType.AUTO)
    private Long id;



    @TableField(typeHandler = FastjsonTypeHandler.class)
    private List<TestA> testAList;


    @Data
    @Accessors(chain = true)
    public static class TestA {

        private String idNo;


    }

}