日期:2014-05-19 浏览次数:20684 次
package test;
import www.am8.manage.TestManageImpl;
public class SSHTest {
public static void main(String args[])
{
TestManageImpl tmi=new TestManageImpl();
tmi.shiwuSaveTest();
}
}
package www.am8.manage;
import java.util.Calendar;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import www.am8.iface.TestManage;
import www.am8.pojo.Test;
import www.am8.pojo.TestDAO;
public class TestManageImpl implements TestManage {
private TestDAO iTestDAO;
public TestDAO getiTestDAO() {
return iTestDAO;
}
public void setiTestDAO(TestDAO iTestDAO) {
this.iTestDAO = iTestDAO;
}
public void shiwuSaveTest() {
Resource res =new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(res);
//从BeanFactory获取UserDAO
TestDAO testDAO = (TestDAO) factory.getBean("TestDAO");
Test t = new Test();
Calendar c = Calendar.getInstance();
t.setTestId(21);
t.setShiJian(c.getTime());
t.setVar2("中文!!");
t.setChangZhengShu(23551);
t.setShiJian2("");
testDAO.save(t);
//testDAO.getHibernateTemplate().getSessionFactory().close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmln