package SpringAndHibernate.type1;

import java.util.List;

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

import module.dao.UserDao;
import module.pojo.UserPo;
/**
 * Spring配置文件中的 sf配置: 配置
 * @ClassName:Test.java
 * @Description:
 * @author:孙晓宁
 * @date:2016-9-21上午9:57:14
 */
public class Test {
	
	public static void main(String[] args) {
//		testSave();
		
		testSearchAll();
	}
	
	static void testSave() {
		//之前是自己new的实现类,跟框架没任何关系
		//UserDao userDao = new UserDaoImpl();
		
//		使用了Spring整合Hibernate,所以要从Spring容器中得到你想要的对象
		String path = "SpringAndHibernate/type1/beans.xml";
		ApplicationContext ac = new ClassPathXmlApplicationContext(path);
		UserDao userDao = (UserDao) ac.getBean("userDao");

		UserPo user = new UserPo(1, "悟空", "w", 18);
		user = new UserPo(20, "八戒00", "b00", 19);
		boolean isOk = userDao.userSave(user);
		System.out.println("保存结果:" + isOk);
	}
	
	static void testSearchAll() {
		String path = "SpringAndHibernate/type1/beans.xml";
		ApplicationContext ac = new ClassPathXmlApplicationContext(path);
		UserDao userDao = (UserDao) ac.getBean("userDao");
		
		List list = userDao.userSearchAll();
		System.out.println("查询全部结果"+list);
	}
	
}
最近下载更多
新的心跳hhl  LV10 2019年6月3日
xiaoyu1200231  LV13 2019年5月25日
develop  LV10 2018年5月27日
1084627032  LV1 2018年5月8日
IODBUGG  LV19 2018年1月6日
liuhui1234  LV2 2017年7月27日
asd987  LV12 2017年6月13日
8008208820  LV6 2017年6月8日
罗辉娟  LV12 2017年5月9日
udbnnh  LV6 2017年2月22日
最近浏览更多
WBelong  LV7 2023年12月28日
shaoqi 2023年7月26日
暂无贡献等级
星辰xc  LV2 2023年5月7日
qfch120  LV8 2023年3月28日
微信网友_6263159342649344  LV7 2022年12月16日
fengshengtian  LV8 2022年2月19日
dafqrf  LV1 2021年12月8日
sprrow23  LV2 2021年6月20日
MARTIN66666  LV1 2020年12月26日
lsglsg9  LV22 2020年12月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友