代码如下: 测试类: package com.test;
import com.dao.PersonDao; import com.po.Person;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;
public class PersonDaoTest { public static void main(String[] args) throws Exception { ApplicationContext applicationContext=new FileSystemXmlApplicationContext("WebRoot/WEB-INF/classes/applicationContext.xml"); PersonDao personDao=(PersonDao)applicationContext.getBean("personDaoImpl"); Person person=new Person(); person.setAge(22); person.setName("xqy1"); System.out.println("导入数据开始......."); personDao.insert(person); System.out.println("导入数据结束......."); } }
配置文件:Person.hbm.xml
运行结果: log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext). log4j:WARN Please initialize the log4j system properly. 导入数据开始....... 导入数据结束.......
我用的是mysql,数据库就是没数据,急死俺列!!