开发者社区> 问答> 正文

spring mybitis 集成使用时,DAO 中参数能同时使用实体类和参数吗??报错

List<Admin> selectBySelective(@Param("offset") Long offset, @Param("rows") Long rows,Admin record);


总是报错:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'adminid' not found. Available parameters are [2, param1, param2, param3, offset, rows]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)
at com.sun.proxy.$Proxy10.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy12.selectBySelective(Unknown Source)
at com.huacheng.cms.service.AdminService.getListByObj(AdminService.java:60)
at com.test.dao.AdminTest.getAdminListOfObj(AdminTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'adminid' not found. Available parameters are [2, param1, param2, param3, offset, rows]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:160)
at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:120)
at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:49)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29)
at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:30)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:275)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
... 36 more


展开
收起
爱吃鱼的程序员 2020-06-22 13:23:26 562 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    @Param("offset")Longoffset,@Param("rows")Longrows,@Param("record")Adminrecord



    然后xml里使用record.属性来使用

    当然可以。把你的mapper发上来

    引用来自“烤蕃薯的野孩子”的答案

    当然可以。把你的mapper发上来 <selectid="selectBySelective"resultType="com.huacheng.cms.model.Admin"<!--你参数有多个类型的是时候,不要去指定parameterType="com.huacheng.cms.model.Admin"-->>select*from`admin`where1=1<iftest="adminId!=null">ANDadminId=#{adminid,jdbcType=BIGINT}</if><iftest="email!=null">ANDemail=#{email,jdbcType=VARCHAR}</if><iftest="name!=null">AND`name`=#{name,jdbcType=VARCHAR}</if><iftest="password!=null">AND`password`=#{password,jdbcType=VARCHAR}</if><iftest="status!=null">AND`status`=#{status,jdbcType=VARCHAR}</if><iftest="createtime!=null">ANDcreateTime=#{createtime,jdbcType=TIMESTAMP}</if><iftest="lasttime!=null">ANDlasttime=#{lasttime,jdbcType=TIMESTAMP}</if><iftest="ip!=null">ANDip=#{ip,jdbcType=VARCHAR}</if>ORDERBYadminIdDESClimit#{offset},#{rows}</select>



    引用来自“烤蕃薯的野孩子”的答案

    <selectid="selectBySelective"resultType="com.huacheng.cms.model.Admin"<!--你参数有多个类型的是时候,不要去指定parameterType="com.huacheng.cms.model.Admin"-->>select*from`admin`where1=1<iftest="adminId!=null">ANDadminId=#{adminid,jdbcType=BIGINT}</if><iftest="email!=null">ANDemail=#{email,jdbcType=VARCHAR}</if><iftest="name!=null">AND`name`=#{name,jdbcType=VARCHAR}</if><iftest="password!=null">AND`password`=#{password,jdbcType=VARCHAR}</if><iftest="status!=null">AND`status`=#{status,jdbcType=VARCHAR}</if><iftest="createtime!=null">ANDcreateTime=#{createtime,jdbcType=TIMESTAMP}</if><iftest="lasttime!=null">ANDlasttime=#{lasttime,jdbcType=TIMESTAMP}</if><iftest="ip!=null">ANDip=#{ip,jdbcType=VARCHAR}</if>ORDERBYadminIdDESClimit#{offset},#{rows}</select>



    你想实现分页的功能可以自己封装一个PagerBean啊。里面有你想要的属性(Model,Limit参数)本人新创建一开发技术群、、、群号:337613367欢迎热爱技术的朋友加入cc
    2020-06-22 13:23:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
The Reactive Cloud Native Arch 立即下载
集成智能接入网关APP:优化企业级移动办公网络 立即下载
云效助力企业集成安全到DevOps中 立即下载

相关实验场景

更多