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

mybatis入门

来源:互联网 收集:自由互联 发布时间:2021-07-03
配置和使用mybatis select * from userinfo select * from userinfo where id=#{id} delete userinfo where id=#{id} package org.jxnd.test;import java.io.IOException;import java.io.InputStream;import java.util.List;import org.apache.ibatis.io
配置和使用mybatis
 


 
  
   
    
     
     
      
      
      
      
     
    
  
  
   
    
  

 











 


 
  
  
  
  
  
  
    delete userinfo where id=#{id} 
  

 







package org.jxnd.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.jxnd.bean.UserInfo;

public class Test {
	public static void main(String[] args) throws Exception {
		String resource = "mybatis.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		
		SqlSession session =sqlSessionFactory.openSession();
//		session.delete("user.deleteById", 15);
		
		System.out.println(session.selectOne("user.getUserById",15));
		
//		List
 
  list=session.selectList("user.getAllUsers");
//		for (UserInfo userInfo : list) {
//			System.out.println(userInfo);
//		}
		session.commit();
		session.close();
	}
}
 
上一篇:tomcat启动 war文件
下一篇:EasyUI运用测试
网友评论