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

mybatis获取自增长id

来源:互联网 收集:自由互联 发布时间:2021-06-28
mybatis获取自增长id insert into bill (storeId, no, menthod, amount, type, account, orderNo, description, createTime ) values ( ${storeId}, #{no}, ${menthod}, #{amount}, #{type}, ${account}, #{orderNo}, #{description}, now() ) select *
mybatis获取自增长id
 



 
	
  
    insert into bill (storeId, no, menthod, amount, type, account, orderNo, description, createTime ) values ( ${storeId}, #{no}, ${menthod}, #{amount}, #{type}, ${account}, #{orderNo}, #{description}, now() ) 
  
	
	
  

 



package mybatis;

import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

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.junit.Before;
import org.junit.Test;

public class BillService {
	SqlSession sqlSession = null;
	@Before
	public void init() throws IOException{
		/**
		 * 初始化SqlSession
		 */
		Reader reader = Resources.getResourceAsReader("mybatis.xml");
		SqlSessionFactory  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		sqlSession = sqlSessionFactory.openSession(true);
		
	}
	
	@Test
	public void m1(){
		Map
 
   param = new HashMap
  
   (); param.put("storeId", 1); param.put("no", "123456789"); param.put("menthod", 1); param.put("amount", 12333); param.put("type", 1); param.put("account", 123); param.put("orderNo", "45678"); param.put("description", "description"); int x =sqlSession.insert("bill.addBill",param); sqlSession.commit();//重要,一定要提交事务 sqlSession.selectList("bill.getBill"); System.out.println(x); System.out.println("id:"+param.get("id")); } }
  
 
网友评论