简体   繁体   中英

Passing an entire sql query as a parameter into a mapper in MyBatis

I'm starting to use MyBatis with annotations and I tried to pass an entire query in a mapper like this:

public interface Mapper {   

    @Select("#{sql}")
    public HashMap<String,String> getResult(String sql);    

}

This is how I call the method:

String sql = "select * from table";
List<Object> list = session.selectList("getResult",sql);

When I executed the program I got this exception:

 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 

You can't, because the sql string isn't a "sql parameter"! Instead, you can use this solution: How to run arbitrary sql with mybatis?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM