??Spring?н??Dbunit??Dao???м?????????
???????????? ???????[ 2013/12/23 10:37:14 ] ????????
??????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()});
}
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11