mybatis中加了if标签做判断,为什么报如下错误
<select id="selectcallHour" parameterType="java.lang.String" resultType="com.sunyard.monitor.domain.General" resultMap="callHour">
select *
from abc t1
left join def t2
on t1.object_id = t2.object_id
where t2.object_name in
<if test="opt!=null and '0'== opt">
('GRQU_ALL')
</if>
<if test="opt!=null and '1' == opt">
('ZH_MM','XYK_MM')
</if>
and substr(time_key, 1, 8) = to_char(trunc(sysdate), 'yyyymmdd')
</select>
2021-08-11 17:39:19.169 INFO 72216 --- [ main] com.sunyard.monitor.runner.GenesysInit : 项目启动完毕,初始化genesys完毕
2021-08-11 17:39:23.406 INFO 72216 --- [nio-8000-exec-2] o.a.c.c.C.[.[localhost].[/monitor] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-08-11 17:39:23.410 INFO 72216 --- [nio-8000-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-08-11 17:39:23.412 INFO 72216 --- [nio-8000-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'opt' in 'class java.lang.String'
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy59.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy60.selectcallHour(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先mybatis查询入参一般使用@Param注解
之后可以在sql中使用opt进行条件判断/#{opt}取到值
其次mybatis不支持IN (XXX,XXX)的直接写法,需要将IN的集合处理为入参查询;
多个list入参需要构造一个entity传参,下面我给你补充了
1. 多list入参查询entity
2.入参处理+mapper方法调用
3.mapper.java
4.mapper.xml
控制台sql+输出打印
1.不传opt(null)
2.opt=0
3.opt=1
你可以去掉parameterType="java.lang.String"
mapper
xml