将整个 sql 查询作为参数传递给 MyBatis 中的映射器
Passing an entire sql query as a parameter into a mapper in MyBatis
我开始使用带注释的 MyBatis,我试图在映射器中传递整个查询,如下所示:
public interface Mapper {
@Select("#{sql}")
public HashMap<String,String> getResult(String sql);
}
我是这样调用方法的:
String sql = "select * from table";
List<Object> list = session.selectList("getResult",sql);
当我执行程序时,我得到了这个异常:
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111
你不能,因为 sql 字符串不是 "sql parameter"!相反,您可以使用此解决方案:How to run arbitrary sql with mybatis?
我开始使用带注释的 MyBatis,我试图在映射器中传递整个查询,如下所示:
public interface Mapper {
@Select("#{sql}")
public HashMap<String,String> getResult(String sql);
}
我是这样调用方法的:
String sql = "select * from table";
List<Object> list = session.selectList("getResult",sql);
当我执行程序时,我得到了这个异常:
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111
你不能,因为 sql 字符串不是 "sql parameter"!相反,您可以使用此解决方案:How to run arbitrary sql with mybatis?