当前位置 : 主页 > 编程语言 > c++ >

mybatis初涉

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt public class Test {static SqlSessionFactory sqlSessionFactory;public static void main(String[] args) {SqlSession session1 = getSqlSession();//面向接口,必须这样实现IUserInfoDao dao = session1.getMapper(IUserInfoDao.
gistfile1.txt
public class Test {
	static SqlSessionFactory sqlSessionFactory;
	public static void main(String[] args) {
		SqlSession session1 = getSqlSession();
		//面向接口,必须这样实现
		IUserInfoDao dao = session1.getMapper(IUserInfoDao.class);
		System.out.println(dao.getUserById(1));
	
	}
	
	private static SqlSession getSqlSession() {
		return sqlSessionFactory.openSession();
	}

	static{
		try {
			String resource = "mybatis.xml";
			InputStream inputStream = Resources.getResourceAsStream(resource);
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
mybatis.xml
 

  
 
  
  
  
  
  
  
  
   
    
  
  
  
  	
   
    
     
     
     
      
      
      
      
     
    
  
  	
  	
  
  	
   
    
    
  
  
 
UserInfoMapper.xml
 


 

 

  
	
  
	
  
	
  
	
  
	
	
  
	
	
  
	
  
	
	
  
	
  
	
   
   
     select seq.nextval from dual 
    insert into userinfo values(#{id},#{name},#{pwd},#{rolesid}) 
  
	

 
包结构.PNG
网友评论