`

There is no getter for property named '**' in 'class java.lang.String

阅读更多
报错原因:
1.用mybatis查询时,传入一个字符串传参数,且进行判断时,会报异常
2.mapper.xml 中id值有重复的(出现原因:拷贝上面的实现,修改下参数或SQL,忘记ID值唯一的修改了)
There is no getter for property named 'moduleCode' in 'class java.lang.String  

1.错误写法:
<select id="queryAllParentModule" resultType="jobModule" prameterType="jobModule">  
select modulecode,modulename,modulevalue,linkurl,rank,       parentmodule=isnull(parentmodule,1),moduledescription   
from job_module  
<where>           
<choose>    
<when test="moduleCode!=null and moduleCode!=''">modulecode = #{moduleCode} 
</when> 
</choose>    
</where>   
</select>  


需要修改成:
<select id="queryModuleByCode" resultType="jobModule" parameterType="string">  
select modulecode, modulename,modulevalue,linkurl, rank,parentmodule=isnull(parentmodule,1),moduledescription   
from job_module  
<where>           
<choose>    
<when test="_parameter!=null and _parameter!=''">modulecode = #{_parameter}</when>    
</choose>    
</where>   
</select>  

总结:不管你的参数是什么,都要改成"_parameter"

原文地址:http://txin0814.iteye.com/blog/1533645
参考文献:http://blog.csdn.net/noku_ln10/article/details/7977976
2.改写parameter_type为 map

接口:
public List<Long> viewUidsLikeName(Map<String, Object> params);


Mapper.xml
	<select id="viewUidsLikeName" resultType="java.lang.Long"
		parameterType="java.util.Map">
		SELECT
		id
		FROM
		usr_users
		where 1=1 
		<if test="username != null">
		  and username like concat ('%','${username}','%')
		</if>
		<if test="email != null">
		  and email like concat ('%','${email}','%')
		</if>		
	</select>


注意:
1.parameterType="java.util.Map"  Map为大写,若写成map会报错
2.或直接写成map

调用:
	public List<Long> selectUidsByUsername(String username) {
		if(StringUtil.isBlank(username)){
			return null ;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		if(UserUtils.isEmailAdress(username)){
			params.put("email", username);
		}else{
			params.put("username", username);
		}
		return userMapper.viewUidsLikeName(params);
	}


3.若封装在工具类中需要引用
  	<select id="selectscheduleTrackingsListPage" resultMap="BaseResultMap"
		parameterType="mybatis.utility.PageBean">
		SELECT
		<include refid="Base_Column_List" />

		from usr_merchant_schedule_tracking

		where 1 = 1

		<if test="parameter.startTime != null and parameter.startTime !=''">
			and date_format(create_time,'%Y-%m-%d') >=
			date_format(#{parameter.startTime},'%Y-%m-%d')
		</if>

		<if test="parameter.endTime != null and parameter.endTime !=''">
  				<![CDATA[ and date_format(create_time,'%Y-%m-%d') <= date_format(#{parameter.endTime},'%Y-%m-%d')  ]]>
		</if>
		
		<if test="parameter.merchantid != null and parameter.merchantid !=''">
			and  merchantid = #{parameter.merchantid,jdbcType=VARCHAR}
		</if>

	</select>


注意:
merchantid = #{parameter.merchantid,jdbcType=VARCHAR},若为
merchantid = #{merchantid,jdbcType=VARCHAR},就会出现上面的错误
分享到:
评论

相关推荐

    Mybatis单个参数的if判断报异常There is no getter for property named 'xxx' in 'class java.lang.Integer'的解决方案

    然而,当遇到单个参数是基本类型如`java.lang.Integer`或`java.lang.String`时,如果按照处理对象类型的参数方式直接在`&lt;if&gt;`中使用参数名,可能会遇到异常`There is no getter for property named 'xxx' in 'class ...

    使用Mybatis遇到的there is no getter异常

    在使用Mybatis框架进行数据库交互时,偶尔会遇到一个奇怪的问题,即在mapper接口中遇到"There is no getter for property"异常。这个异常的出现原因是由于Mybatis框架在映射实体类的属性时,无法找到对应的getter...

    mybatis 分页拦截器及拦截器配置

    MyBatis中的拦截器(Interceptor)是基于Java的动态代理机制实现的,它可以拦截执行SQL的生命周期中的某些环节,如:预处理、结果映射等。在分页拦截器中,它会在执行查询之前对SQL进行修改,自动添加LIMIT和OFFSET...

    支持条件查询的Mybatis分页插件

    Mybatis PageHelper分页插件是一款广泛使用的Java框架,它为Mybatis提供了强大的分页功能。在使用Mybatis进行数据库操作时,分页查询是非常常见且重要的需求,尤其是在处理大量数据时,避免一次性加载所有结果,提高...

    Struts常见错误及原因分析.

    #### 四、异常 javax.servlet.jsp.JspException: No getter method for property username of bean **异常描述**: 当使用Struts标签库访问Form Bean中的属性时,如果该属性没有对应的getter方法,则会出现此异常。...

    最新西南交通大学JAVA期末作业.doc

    public Book(String title, String author, String publisher) { this.title = title; this.author = author; this.publisher = publisher; } // Getter & Setter 方法 public String getTitle() { return ...

    CheckStyle结果分析

    String longString = "This string is very long and should be split into multiple lines to comply with the code style guidelines."; ``` --- ##### 13. 行中含有 Tab 字符 **提示**: Line contains a tab ...

    使用jsp和java.bean来构建一个网上书店

    在构建一个基于JSP(JavaServer Pages)和JavaBean的网上书店系统时,我们需要掌握一些核心的IT知识点。首先,让我们深入理解JSP和JavaBean技术,并探讨如何将它们结合起来创建一个功能完善的网上书店。 **1. JSP...

    java常用代码

    2. **处理日期Bean**(java处理日期bean.txt):在Java中,日期和时间的处理通常使用`java.util.Date`,`java.time`包(自Java 8引入)以及`java.text.SimpleDateFormat`等类。Bean是一种遵循特定规则的对象,用于...

    Hibernate中数据类型

    - **其他类型**:`java.lang.Class` 一般映射为 `VARCHAR`,`java.util.Locale` 存储为 `VARCHAR`,`java.util.TimeZone` 用 `VARCHAR` 表示,`java.util.Currency` 也映射到 `VARCHAR` 类型。 **2. 数据库差异** ...

    Java反射中java.beans包学习总结.docx

    public static &lt;T&gt; T convert(Map&lt;String, String&gt; parameters, Class&lt;T&gt; clazz) throws Exception { T bean = clazz.getDeclaredConstructor().newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo...

    Java Bean 遍历和使用注解给Bean的属性添加属性值

    - **运行时反射**:除了编译时处理,还可以在运行时通过反射获取注解的值,如`MyAnnotation myAnno = field.getAnnotation(MyAnnotation.class); String value = myAnno.value();` 3. **工具支持**: - **Apache ...

    courseware

    字符串(String)在Java中是不可变对象,常用于数据处理。数组是存储固定数量同类型元素的数据结构,理解其创建、遍历和操作是基础。 4. **J1410_NIO.pdf**:非阻塞I/O(New I/O,NIO)是Java提供的异步I/O模型,包括...

    Struts 2.0整合Hibernate 3.2开发注册登录系统

    &lt;property name="name" type="java.lang.String" length="20"/&gt; &lt;property name="pwd" type="java.lang.String" length="20"/&gt; &lt;/class&gt; ``` - `tb_user`为数据库中的表名。 - `id`字段为主键,采用`native`...

    ibatis 一个简单的项目详解

    - **DWR for Struts2**:dwr4struts2.jar - **Freemarker模板引擎**:freemarker-2.3.8.jar - **JSON处理**:jsonplugin-0.31.jar - **ibatis核心库**:ibatis-2.3.0.677.jar - **Spring框架**:spring.jar - **...

    JAVA实验项目.docx

    ### JAVA实验项目知识点详解 #### 项目一:Java 语言基础(一) 1. **编写控制台输出“Hello World!”的 Java 应用程序** - **记事本编写** ```java public class HelloWorld { public static void main...

    java.图书信息

    在Java编程语言中,"图书信息"通常涉及到数据结构、对象和类的设计,以及文件处理。在这个场景下,我们可以创建一个图书类(Book)来存储关于书籍的各种信息,如书名、作者、出版年份等。`import java.awt.event`是...

    learn-mybatis-plus:学习mybatis-plus配置,解决save时乱码,解决mybatis映射时日期格式问题。为什么不用mybatis-plus-boot-starter?配置多数据源时,要让spring-boot不自动注入data-source和sqlSessionFactory。

    常问问题1,出现了如下BUG org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'statement' in 'class ...

    【良心出品】java编程题.doc

    ### Java编程题解析 #### 一、一维数组操作与排序 **题目描述**: 定义一个包含10个元素的一维整型数组,通过从键盘输入的10个整数来初始化数组。然后,将数组中的元素按照从小到大的顺序进行排序,并在屏幕上...

Global site tag (gtag.js) - Google Analytics