我想使用mybatis来修改字符串列表。我正在使用以下代码,但是如下所示获取illegalArgument异常:
javax.servlet.ServletException: org.mybatis.spring.MyBatisSystemException: SqlSession operation; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for java.lang.Object.toString
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
Mybatis配置:
<select id="fetchIds" resultType="java.lang.String" >
SELECT distinct ids
FROM abc.emp
</select>
我的Dao方法是:
@Override
public List<String> fetchIds() {
System.out.println("Inside fetchIds");
SqlSession session = null;
List retrieveList = null;
try{
session = sqlSessionFactory.openSession();
System.out.println("After session creation:"+session);
retrieveList = session.selectList("fetchIds");
}finally{
session.close();
}
return retrieveList;
}
任何人都可以建议我们如何实现这一目标。
答案 0 :(得分:13)
将List
定义为List<String>
。这里你的代码看起来像
<select id="fetchIds" resultType="string" >
SELECT distinct ids
FROM abc.emp
</select>
和Dao方法
@Override
public List<String> fetchIds() {
System.out.println("Inside fetchIds");
SqlSession session = null;
List<String> retrieveList = null;
try{
session = sqlSessionFactory.openSession();
System.out.println("After session creation:"+session);
retrieveList = session.selectList("fetchIds");
}finally{
session.close();
}
return retrieveList;
}
mapper interface.java文件的方法签名如下。
String[] fetchIds()throws Exception;