1. 程式人生 > >There is no getter for property named 'X' in 'class java.lang.XX'

There is no getter for property named 'X' in 'class java.lang.XX'

UserDao.java程式碼如下:

package soc.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import soc.entity.User;

public interface UserDao {
	@Select("select * from user where id=#{id}")
	public User getUserById(@Param("id") Integer id);

	public List<User> query();
	
	public List<Map> querySection(Integer id);

}

userMapper.xml內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="soc.dao.UserDao">
	<cache readOnly="true" eviction="FIFO" flushInterval="60000" />
	<resultMap id="BaseResultMap" type="soc.entity.User">
		<result column="id" property="id" />
		<result column="name" property="name" />
		<result column="salary" property="salary" />
		<result column="birthday" property="birthday" />
	</resultMap>
	<sql id="Base_Column_List">
		id,name,salary,birthday
	</sql>
	<select id="query" resultMap="BaseResultMap" useCache="true">
		select
		<include refid="Base_Column_List" />
		from user
	</select>
	<select id="querySection" resultType="map" parameterType="integer"
		useCache="true">
		select
		name,salary
		from user where
		<if test="id !=null"></if>
		id=#{id}
	</select>

</mapper>

結果執行querySection()後報錯如下:

解決方法是:

1.在userMapper.xml中將<if test="id !=null"></if>去掉,即不加判斷條件;

2.在userMapper.xml中將<if test="id !=null"></if>id=#{id}改為<if test="_parameter !=null"></if>id=#{_parameter}

3.仍然是<if test="id !=null"></if>id=#{id},但在userDao.java裡將querySection(Integer id)方法改成querySection(@Param("id") Integer id).