📄 testpersondao.java
字号:
package org.darkness.sshlogin.test;
import junit.framework.TestCase;
import org.darkness.sshlogin.dao.PersonDAO;
import org.darkness.sshlogin.vo.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestPersonDAO extends TestCase {
public void testIsLogin() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
Person per = new Person();
per.setId("darkness");
per.setPassword("wind");
System.out.println(personDao.isLogin(per));
System.out.println(per.getName());
}
public void testRegister(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
Person per = new Person();
per.setId("darkness4");
per.setName("sky");
per.setPassword("wind");
try {
personDao.register(per);
System.out.println("注册成功!");
} catch (Exception e) {
System.out.println("注册失败!");
e.printStackTrace();
}
}
public void testUpdate() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
Person per = new Person();
per.setId("darkness");
per.setName("dark");
per.setPassword("sky");
try {
personDao.update(per);
System.out.println("修改成功!");
} catch (Exception e) {
System.out.println("修改失败!");
e.printStackTrace();
}
}
public void testDelete() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDAO personDao = (PersonDAO)ctx.getBean("persondaoimpl");
try {
personDao.delete("sky");
System.out.println("删除成功!");
} catch (Exception e) {
System.out.println("删除失败!");
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -