??????Dao???е?????????????????·?????Mock??????????API????Mock??????Hibernate??JDBC?????ж???????????????????????????????????ж????????????????д???????????£??????????????????????ORM???????jdbcTemplate??????£?dao?????м?????д?????и?????????Mock???????????????壬?????????????Hibernate mapping????????ibatis sql?????????????????д?????????????ж????dao?????????????????????????????

?????????????????????????????????????????????????????????????????????д?????????????漰?????????????????????????????????????????????????????鷳?????????????????Dbunit????Xml???????Excel?м???????????????????????????????????????????????Dbunit???????????????????ж?????????????????????????????????????Spring TransactionalTests??????????????????
????Dbunit??????????????????????б?????????????????????????????????????????????????????????????????????????????и????????????????????????????????????????????£???????д????????Щ?????
?????????????

 

package com.test.dbunit.dao.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.test.dbunit.dao.UserDao;
import com.test.dbunit.entity.User;
public class DefaultUserDao extends BaseDao implements UserDao {
private static String QUERY_BY_NICK = "select * from user where user.nick = ?";
private static String REMOVE_USER = "delete from user where user.nick = ?";
private static String INSERT_USER = "insert into user(nick??password) values(??? ?)";
private static String UPDATE_USER = "update user set user.password = ? where user.nick = ?";
@Override
public User getUserByNick(String nick) {
return (User) getJdbcTemplate().queryForObject(QUERY_BY_NICK??new Object[]{nick}?? new RowMapper(){
@Override
public Object mapRow(ResultSet rs?? int index) throws SQLException {
User user = new User();
user.setNick(rs.getString("nick"));
user.setPassword(rs.getString("password"));
return user;
}
});
}
@Override
public void remove(String nick) {
getJdbcTemplate().update(REMOVE_USER?? new Object[]{nick});
}
@Override
public void save(User user) {
getJdbcTemplate().update(INSERT_USER?? new Object[]{user.getNick()?? user.getPassword()});
}
@Override
public void update(User user) {
getJdbcTemplate().update(UPDATE_USER?? new Object[]{user.getPassword()?? user.getNick()});
}
}