首页 > 数据库 > 其他综合 >

mybatisDAO和Mapper的传值问题

2016-12-10

今天在Mapper中使用到了多表关联查询,于是乎就用到了多参数。所以按照以往的思维,写出了如下的代码List selectByAll(String buildingName,int roomNumber, int bedNumber);

今天在Mapper中使用到了多表关联查询,于是乎就用到了多参数。所以按照以往的思维,写出了如下的代码

List selectByAll(String buildingName,int roomNumber, int bedNumber);

写完了其他剩余代码,高高兴兴去测试了,结果是这样的:

rg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'buildingName' not found. Available parameters are [0, roomNumber, bedNumber, param3, param1, param2]
    org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
    org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
    com.sun.proxy.$Proxy26.selectList(Unknown Source)
    org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
    org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
    org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
    org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    com.sun.proxy.$Proxy30.selectByAll(Unknown Source)
    com.willu.serviceImpl.currency.Accomodation.AccomodationQueryInfo(Accomodation.java:20)
    com.willu.serviceImpl.manager.Manager.selectAccomodation(Manager.java:38)
    com.willu.rest.ManagerRest.getTest(ManagerRest.java:53)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

楼楼顿时傻住了,开始以为是model中写的不对,后面才知道是参数的问题。百度之后,知道应该这样写

List selectByAll(@Param("buildingName") String buildingName,@Param("roomNumber")int roomNumber,@Param("bedNumber") int bedNumber);

自己个人就稍微总结了一下,之前用到的参数都是表内有的参数,所以碰巧能查询,但是这次是表内没有的字段,所以无法识别参数。希望对大家有所帮助。

相关文章
最新文章
热点推荐