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

mybatis 初应用

来源:互联网 收集:自由互联 发布时间:2021-07-03
gistfile1.txt public class Test {public static void main(String[] args) throws Exception {String resource = "mybatis.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = new SqlSession
gistfile1.txt
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();
		
		
		//Users info=session.selectOne("user.getUserById",230);
		//info.setName("说的是");
		//info.setPass("241441");
		
		//session.update("user.update",info);
		
		session.delete("user.deleteById",230);
	//	Users info=new Users(230, "道德 ", "123");
		Map
 
   map=new HashMap
  
   (); map.put("id", 230); map.put("name", "老子"); map.put("pass", "123456"); System.out.println(session.insert("user.add",map)); // System.out.println(session.selectOne("user.getUserById",1)); Map
   
     map1=new HashMap
    
     (); map1.put("sql", "select * from users order by id"); List
     
       list= session.selectList("user.selectBySql",map1); for (Users userInfo : list) { System.out.println(userInfo); } // List
      
        list=session.selectList("user.getUserAll"); // System.out.println(list); session.commit(); session.close(); } }
      
     
    
   
  
 
网友评论