⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentdaotest.java

📁 Struts+Spring+Hibernate 增删改查
💻 JAVA
字号:
package com.yumeng.ssidemo.test;

import java.sql.SQLException;

import junit.framework.TestCase;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.yumeng.ssidemo.dao.StudentDAO;
import com.yumeng.ssidemo.po.Student;

public class StudentDAOTest extends TestCase {
	Student student = null;

	StudentDAO studentDAO = null;

	public StudentDAOTest(String arg0) {
		super(arg0);
		ApplicationContext context = new FileSystemXmlApplicationContext(
				"/WebRoot/WEB-INF/applicationContext.xml");
		studentDAO = (StudentDAO) context.getBean("studentDAO");
		student = new Student();
		student.setName("小龙");
		student.setSex("男");
		student.setAge(20);
		student.setNationality("汉族");
		student.setAddress("中国湖北武汉黄陂");
		student.setPhonenumber(65200293);
	}

	public void testDeleteStudent() {
		System.out.println("has deleted");
	}

	public void testInsertStudent() {
		try {
			studentDAO.insertStudent(student);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void testUpdateStudent() {
		Student st = new Student();
		st.setId(3);
		st.setName("大龙");
		st.setSex("女");
		st.setAge(18);
		st.setNationality("苗族");
		st.setAddress("四川成都");
		try {
			studentDAO.updateStudent(st);
		} catch (SQLException e) {
		
			e.printStackTrace();
		}
	}

	public void testSelectAllStudent() {
		fail("Not yet implemented");
	}

	public void testSelectStudentById() {
		Student s = null ;
		try {
			s = studentDAO.selectStudentById(12);
		} catch (SQLException e) {

			e.printStackTrace();
		}

		System.out.println(s.getId());
		System.out.println(s.getName());
		System.out.println(s.getSex());
		System.out.println(s.getAge());
		System.out.println(s.getNationality());
		System.out.println(s.getAddress());
		System.out.println(s.getPhonenumber());

	}

	public void testSelectStudentByName() {
		Student s = null ;
		try {
			String name="2";
			s = studentDAO.selectStudentByName(name);
		} catch (SQLException e) {

			e.printStackTrace();
		}

		System.out.println(s.getId());
		System.out.println(s.getName());
		System.out.println(s.getSex());
		System.out.println(s.getAge());
		System.out.println(s.getNationality());
		System.out.println(s.getAddress());
		System.out.println(s.getPhonenumber());

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -