[java]代码库
//删除
@Test
public void dele(){
ApplicationContext ac=new AnnotationConfigApplicationContext(SpringConfiguration.class);
try {
accountService= (AccountService) ac.getBean("accountService");
int a= accountService.deleteAccount(3);
System.out.println(a+"删除成功!!!");
} catch (SQLException e) {
e.printStackTrace();
}
}
//修改
@Test
public void update(){
ApplicationContext ac=new AnnotationConfigApplicationContext(SpringConfiguration.class);
try {
accountService= (AccountService) ac.getBean("accountService");
Account account= accountService.findByID(4);
account.setName("王五");
account.setMoney(3000.0);
int a= accountService.updateAccount(account);
System.out.println(a+"修改成功!!!");
} catch (SQLException e) {
e.printStackTrace();
}
}
//添加
@Test
public void add(){
ApplicationContext ac=new AnnotationConfigApplicationContext(SpringConfiguration.class);
try {
accountService= (AccountService) ac.getBean("accountService");
Account account=new Account();
account.setName("Lucy");
account.setMoney(5000.0);
int a= accountService.add_account(account);
System.out.println(a+"添加成功!!!");
} catch (SQLException e) {
e.printStackTrace();
}
}
//全查
@Test
public void findAll(){
//加载配置类
ApplicationContext ac=new AnnotationConfigApplicationContext(SpringConfiguration.class);
//创建业务层对象
AccountService accountService= (AccountService) ac.getBean("accountService");
try {
List<Account> accounts= accountService.findAll();
for (Account a: accounts) {
System.out.println(a);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
[源代码打包下载]