日期:2014-05-20  浏览次数:20726 次

关于ibatis动态查询问题
pojo:
  public class User {
public int userId;
public String userName;
public String passWord;
public String email;
public Date createDate;
public int bound;


sqlMap:
  <typeAlias alias="user" type="com.credit.entity.User"/>
  <resultMap id="userResult" class="user">
  <result property="userId" column="userid"/>
  <result property="userName" column="username"/>
  <result property="passWord" column="password"/>
  <result property="email" column="email" />
  <result property="createDate" column="createdate"/>
  <result property="bound" column="bound" >
  </resultMap>


  <!-- 根据username查询 -->
<select id="queryUserByName" parameterClass="String" resultMap="userResult">
  select * from DemoUser
<dynamic prepend="WHERE">
<isNotEmpty prepend="AND" property="userName">
(username like '%$userName$%')  
</isNotEmpty>
</dynamic>
</select>


调用代码:List list = dus.queryUserByName("zhangsan");


错误:
--- Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'userName' in class 'java.lang.String'; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/credit/entity/maping/User.xml.  
--- The error occurred while preparing the mapped statement for execution.  
--- Check the queryUserByName.  
--- Check the parameter map.  




------解决方案--------------------
parameterClass="String"

如果参数是String,那么请改成
<isNotEmpty prepend="AND" property="value">
(username like '%$value$%')
</isNotEmpty>
------解决方案--------------------
不会吧,你的ibatis的版本是多少,可以用2.3.4,这是个稳定版本!
------解决方案--------------------
试试~~~~
pojo:
public class User {
public Integer userId;
public String userName;
public String passWord;
public String email;
public Date createDate;
public Integer bound;