首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

关于ibatis动态查询有关问题

2011-12-07 
关于ibatis动态查询问题pojo:public class User {public int userIdpublic String userNamepublic Strin

关于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;

热点排行