首页 新闻 会员 周边

mybatis接口编程

0
悬赏园豆:20 [已关闭问题] 关闭于 2013-12-20 22:45

我用mybatis 3.2.3版本接口编程,实现查询

配置如下:

<select id="selectOnly" resultType="Student" parameterType="int">
  select * from student where stuid = #{stuid}
</select>

 

然后定义接口

public interface IStudentDAO{
  //方法名与配置文件中的id相同
  Student selectOnly(int stuid);
}

接下来:

SqlSession session = sqlfactory.openSession();

IStudentDAO isdao = session.getMapper(IStudentDAO.class);
Student stu = isdao.selectOnly(id);
System.out.println(stu);
session.close();

注:sqlfactory不为空,测试过

然后运行时报错:

Exception in thread "main" org.apache.ibatis.binding.BindingException: Type interface com.lc.inter.IStudentDAO is not known to the MapperRegistry.
at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:42)
at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:655)
at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:218)
at com.lc.dao.StudentDao.TestInterfaceOnly(StudentDao.java:67)
at com.lc.dao.StudentDao.main(StudentDao.java:77)

求解答啊,困惑了很久了!

C_林先森的主页 C_林先森 | 初学一级 | 园豆:60
提问于:2013-12-20 22:39
< >
分享
所有回答(2)
0

namespace 定义的不对了吧。 可以参考:http://blog.csdn.net/chris_mao/article/details/48836039

..小树苗 | 园豆:202 (菜鸟二级) | 2016-04-17 02:50
0

这应该是你的xml文件里的<mapper namespace="">配置错误这个要和你的IStudentDAO路径一样才行。

ckx0709 | 园豆:414 (菜鸟二级) | 2016-11-19 14:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册