第一种
原始dao开发,程序猿要写dao接口和dao实现类。
第二种
mapper代理,程序猿只要写mapper接口,但是需要注意以下4个开发规范。
1,在mapper.xml中的nameSpace(命名空间),要和mapper接口的地址相同
mapper.xml中这样写:
mapper.java接口中这样写:
public User findById(int uid) throws Exception;
4,mapper.java接口中的返回值类ixnghemapper.xml中的statement的ResultType指定类型一致
例子:
接口中代码:
public interface IUserDAo {
/**
* 查询单个用户,根据id
* @param uid
* @return
* @throws Exception
*/
public User findById(int uid) throws Exception;
public List findUserByName(String uname) throws Exception;
public void addUser(User user) throws Exception;
}
select LAST_INSERT_ID()
insert into user(uname,uage) values(#{uname},#{uage})
别忘记在sqlMapperConfig.xml中挂载配置的映射文件,否则会报not found的错误