在进行条件查询时,没有查出数据库中的该记录,感觉可能是传参数的问题,有点奇怪,请哪位兄弟帮我看下 <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.
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.
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;
}
listid as listId,
phoneNumber as phoneNumber,
numberType as numberType
from
black_list where phone_number=#phoneNumber# 推荐这样写
<result property="listId" column="list_id"/>
<result property="phoneNumber" column="phone_number"/>
<result property="numberType" column="number_type"/>
</resultMap>
select * from black_list where phone_number=#phoneNumber# //字符串参数也应该是这样传的,可就是查不出
</select>
resultClass 不应该是BlackList把