@Repository
public class BookDaoImpl implements BookDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void add(Book book) {
String sql="insert into t_book values(?,?,?)";
int update=jdbcTemplate.update(sql,
book.getUserId(),book.getUsername(),book.getUstatus());
System.out.println("添加成功:"+update);
}
@Override
public void myupdate(Book book) {
String sql="update t_book set username=?,ustatus=? where user_id=?";
int update=jdbcTemplate.update(sql,
book.getUsername(),book.getUstatus(),book.getUserId());
System.out.println("修改成功:"+update);
}
@Override
public void delete(String id) {
String sql="delete from t_book where user_id=?";
int update=jdbcTemplate.update(sql, id);
System.out.println("删除成功:"+update);
}
}
public class TestBook {
@Test
public void testAccount() {
ApplicationContext context =
new ClassPathXmlApplicationContext("bean1.xml");
BookService bookService = context.getBean("bookService", BookService.class);
bookService.deleteBook("1");
}
}