在进行条件查询时,没有查出数据库中的该记录,感觉可能是传参数的问题,有点奇怪,请哪位兄弟帮我看下 <select id="getBlackList" parameterClass="String" resultClass="BlackList">
   select * from black_list where phone_number=#phoneNumber# //字符串参数也应该是这样传的,可就是查不出
 </select>下面是java 中的调用代码:@Test
public void t()
{
BlackList bl = new BlackList();

bl = DaoFactory.getBlackListDaoInstance().findByNumber("150");

System.out.println(bl.getListId()); //取得查出的该条记录的id,可就查不出,查出的结果是0,数据库中有该记录的
}
下是log4j打印出的:2009-09-29 09:37:37,875 DEBUG [com.ibatis.common.jdbc.SimpleDataSource] - Created connection 30936685.
2009-09-29 09:37:37,906 DEBUG [java.sql.Connection] - {conn-100000} Connection
2009-09-29 09:37:37,906 DEBUG [java.sql.Connection] - {conn-100000} Preparing Statement:       select * from black_list where phone_number=?    
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Executing Statement:       select * from black_list where phone_number=?    
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Parameters: [150]
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Types: [java.lang.String]
2009-09-29 09:37:38,000 DEBUG [java.sql.ResultSet] - {rset-100002} ResultSet2009-09-29 09:37:38,046 DEBUG [com.ibatis.common.jdbc.SimpleDataSource] - Returned connection 30936685 to pool.

解决方案 »

  1.   

    DAO也贴出来嘛  还有你的BlackList里面的代码也贴出来嘛
      

  2.   

    BlackList 实体类:private static final long serialVersionUID = 6218562431438580204L;

    private long listId; //名单id
    private String phoneNumber ; //手机号
    private String numberType ; //手机号所属的类别

    public long getListId() {
    return listId;
    }
    public void setListId(long listId) {
    this.listId = listId;
    }

    public String getPhoneNumber() {
    return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
    this.phoneNumber = phoneNumber;
    }
    public String getNumberType() {
    return numberType;
    }
    public void setNumberType(String numberType) {
    this.numberType = numberType;
    }
    DAO中查询的方法:public BlackList findByNumber(String phoneNumber) {
    BlackList bl = null;

    try {

    bl = (BlackList)sqlMap.queryForObject("getBlackList", phoneNumber);
    }catch(SQLException e){
    e.printStackTrace();
    }
    return bl;
    }
      

  3.   

    你的数据库表 black_list  字段listId  跟pojo类的listId是一致的吗? select 
               listid as listId,
               phoneNumber as phoneNumber,
               numberType as numberType 

    from 
               black_list where phone_number=#phoneNumber# 推荐这样写
      

  4.   

    按4楼那办法能查出了,但我在xml中配置了数据库字段和属性间的映射关系啊,直接查的话怎么查不到<resultMap id="BlackListResult" class="BlackList">
        <result property="listId" column="list_id"/>
        <result property="phoneNumber" column="phone_number"/>
        <result property="numberType" column="number_type"/>
      </resultMap>
      

  5.   

    <select id="getBlackList" parameterClass="String" resultClass="BlackList">
       select * from black_list where phone_number=#phoneNumber# //字符串参数也应该是这样传的,可就是查不出
     </select>
    resultClass 不应该是BlackList把