testpersondao.java

来自「Struts、Spring、Hibernate实现的登陆程序」· Java 代码 · 共 71 行

JAVA
71
字号
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 + =
减小字号Ctrl + -
显示快捷键?