package com.manage;

import com.manage.dao.Power_MenuMapper;
import com.manage.dao.T_MenuMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:config/applicationContext.xml"})
public class MapperTest {
	
	@Autowired
    T_MenuMapper t_menuMapper;

	/**
	 * 测试角色mapper
	 */
	@Test
	public void testCRUD(){
		//1、创建SpringIOC容器
        ApplicationContext ioc=new FileSystemXmlApplicationContext("classpath:config/applicationContext.xml");
		T_MenuMapper menuMapper=ioc.getBean(T_MenuMapper.class);
		System.out.println(menuMapper);
		//Power_MenuMapper powerMenuMapper=ioc.getBean(Power_MenuMapper.class);
		//System.out.println(powerMenuMapper);

		//menuMapper.selectByPrimaryKey(1);

        //ApplicationContext ioc=new ClassPathXmlApplicationContext("config/applicationContext.xml");
		//2、从容器中获取mapper
		//T_RoleMapper bean=ioc.getBean(T_RoleMapper.class);
		//System.out.println(t_roleMapper);

		//1、插入角色
		//t_roleMapper.insertSelective(new T_Role(null,"vip用户","注册的用户","1","admin","2018-03-03 18:18:00","admin","2018-03-03 18:18:00"));
		//1、插入用户
		//t_userMapper.insertSelective(new T_User(null,"user6","user6",1,23,"1350167656","123484896@qq.com","福建省***","***","游客用户","1","admin","2018-03-03 18:18:00","admin","2018-03-03 18:18:00",3));
		//3、批量插入用户，使用可以执行批量操作的sqlSession
		/*T_UserMapper mapper=sqlSession.getMapper(T_UserMapper.class);
	    for(int i=0;i<10;i++){
	    	String uuid=UUID.randomUUID().toString().substring(0,6)+""+i;
	    	mapper.insertSelective(new T_User(null,uuid,uuid,1,23,"135016735"+i,uuid+"@qq.com","福建省***","***","游客用户","1","admin","2018-03-03 18:18:00","admin","2018-03-03 18:18:00",3,""));
	    }
	    System.out.println("批量完成");*/
		//修改
		/*T_User user=new T_User();
		user.setUserId(1);
		t_userMapper.updateByPrimaryKey(user);*/
        System.out.println(123);
	}
}
