Mybatis查询
使用Mybatis查询时,其参数可以是基本数据类型或者像Integer和String这样的简单的数据对象,也可以是复杂对象(一般是指JavaBean)或者map等,当使用基本数据类型的参数时,若这个参数的使用放在了判断条件中,如下查询语句:
<select id="getNameList" parameterType="String" resultType="String"> <![CDATA[ SELECT DISTINCT NAME FROM T_PERSION WHERE 1=1 ]]> <if test="age!=null"> AND AGE = #{age} </if> </select>
则可能会出现:
org.apache.ibatis.reflection.ReflectionException:There is no getter for property named 'XXX' in 'class java.lang.XXX
的异常,问题的直接原因是由于上面的parameterType是基本的简单类型而后面有判断的if条件,若没有后面的判断条件,而是:
<select id="getNameList" parameterType="String" resultType="String"> <![CDATA[ SELECT DISTINCT NAME FROM T_PERSION WHERE 1=1 AND AGE = #{age} ]]> </select>
则没有任何异常。
对上面的异常,网上说问题原因是Mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式获取传入的变量值,解决方法有两个:
1.将参数名(上面的例子为‘age’)替换为"_parameter" ,即:
<select id="getNameList" parameterType="String" resultType="String"> <![CDATA[ SELECT DISTINCT NAME FROM T_PERSION WHERE 1=1 ]]> <if test="_parameter!=null"> AND AGE = #{_parameter} </if> </select>
2,在接口中定义方法时 增加“@Param("参数名")” 标记,例如:
List<String> getNameList(@Param("age")String age);
相关推荐
今天小编就为大家分享一篇关于Mybatis单个参数的if判断报异常There is no getter for property named 'xxx' in 'class java.lang.Integer'的解决方案,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,...
主要介绍了使用Mybatis遇到的there is no getter异常,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
解决Mybatis 分页插件pagehelper不支持逆向工程Example条件查询.含源码和jar包
/** finder.mybatis **/ 1、项目摘要:mybatis hello,world demo 2、开发环境:开发工具-->Myeclipse10.0 java环境-->JDK1.6 数据库环境-->Oracle11g Mybatis版本:3.2.2 log4j版本:1.2.17 3、数据库: ...
SpringBoot 整合 MyBatis。解决因Mybatis-Spring版本过高引起的“Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required”异常
两天因为项目需要整合spring、struts2、mybatis三大框架,但启动的时候总出现这个错误,困扰我好久,折腾了好久终于找到问题根源,下面小编给大家分享下问题所在及解决办法,一起看看吧
NULL 博文链接:https://listen-raining.iteye.com/blog/1962065
MyBatis SQL mapper framework for Java.zip
常问问题1,出现了如下BUG org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'statement' in 'class ...
主要给大家介绍了mybatis中foreach报错:_frch_item_0 not found的解决方法,文章通过示例代码介绍了详细的解决方法,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
Spring+Jersey+Mybatis小实例,为了搭建这个折腾了两天,其中一天是因为jar包版本引起的,一直报异常:java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/...
nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis- config.xml]; nested exception is org.apache.ibatis.builder....
Java.Persistence.with.MyBatis3。市场上非常经典的Mybatis书籍。
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:orcl4" userId="xxx" password="xxxx" /> <javaTypeResolver> <property name=...
free-idea-mybatis is an enchange plugin for idea to supoort mybatis,here is the main functions: generate mapper xml files navigate from the code to mapper and from the mapper back to code auto code...
已修改 注释添加 生成路径不存在报异常
1.Configuration.xml 是 mybatis 用来建立 sessionFactory 用的,里面主要包含了数据库连接相关东西,还有 java 类所对应的别名,比如 <typeAlias alias="User" type="com.yihaomen.mybatis.model.User"/> 这个别名...
创建主配置文件:mybatis.xml 4.创建分层包 5.编写工具类 6.编写实体类 7.编写数据访问层接口 8.创建sql映射文件:接口名称.xml 9.编写测试类,测试接口方法:接口名称+方法+Test.class cn.edu.xxxx. util ...
>Window->prefenrence->XML->XML Catalog->User Specifiled Entreis->Add->Location(此处是你放dtd文件的位置例如:D:\mybatis\mybatis-3-config.dtd)->Key(如果更改config,此处应该是:-//mybatis.org//DTD ...
主要介绍了Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法的相关资料,需要的朋友可以参考下