ibatis参数和返回值

<sqlMap namespace="User"> 
<typeAlias alias="user" type="org.lq.news.db.User"/>      
  <select id="getUserByUsernameAndPassword" parameterClass="java.lang.String" resultClass="user"> 
          SELECT col_username, col_password  FROM tb_user WHERE col_username = #username# 
     </select> 
       
</sqlMap> 

<sqlMap namespace="User">
  <typeAlias alias="user" type="org.lq.news.db.User"/>
<insert id="insertUser" parameterClass="user">
INSERT INTO tb_user (col_id, col_username, col_password)
VALUES (#id#, #username#, #password#)
</insert>
<select id="getUserByUsernameAndPassword" parameterClass="java.lang.String" resultClass="user">
SELECT col_username, col_password  FROM tb_user WHERE col_username = #username#
</select>

</sqlMap>



还是把问题定位到属性和数据库字段的映射上面,既然返回值是user,但是select语句是数据库的字段,现在还没有配置映射关系。改成这样就可以了。
Xml代码

   1. <select id="getUserByUsernameAndPassword" parameterClass="java.lang.String" resultClass="user"> 
   2.         SELECT col_username as username, col_password as password FROM tb_user WHERE col_username = #username# 
   3.     </select> 

<select id="getUserByUsernameAndPassword" parameterClass="java.lang.String" resultClass="user">
SELECT col_username as username, col_password as password FROM tb_user WHERE col_username = #username#
</select>

给数据库字段取个别名映射成为User类里面的属性名。

你可能感兴趣的:(xml,ibatis)