您的位置:首页 > 其它

mybatis

2016-04-07 15:15 176 查看
在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>

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis namespace