mybatis


在mybatis中,映射文件中的namespace是用於綁定Dao接口的,即面向接口編程。當namespace綁定接口後,可以不用寫接口實現類,mybatis會通過該綁定自動找到對應要執行的SQL語句,如下:
接口:
public interface UserDAO {
	public User login(User u);	
}

接口中的方法與映射文件中的SQL語句的ID一一對應

映射文件:
<mapper namespace="com.demo.dao.UserDAO">
	<resultMap type="User" id="UserRes">
		<result column="id" property="id"/>
		<result column="userName" property="userName"/>
		<result column="password" property="password"/>
	</resultMap>
	<select id="login" parameterType="User" resultMap="UserRes">
		select * from t_user where userName=#{userName} and password=#{password}
	</select>
</mapper>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章