标签:from mybatis sys session tsql ati result span exception
(1)接口中对应的方法
public Emp getEmpById(Integer id);
(2)Mapper文件
1 <resultMap type="com.eu.bean.Emp" id="emp"> 2 <id column="id" property="id"/> 3 <result column="last_name" property="lastName"/> 4 <result column="gender" property="geder"/> 5 <result column="email" property="email"/> 6 </resultMap> 7 8 9 <select id="getEmpById" resultMap="emp"> 10 select * from emp where id = #{id} 11 </select>
(3)测试
1 public SqlSessionFactory getSqlSessionFactory() throws IOException { 2 String resource = "conf/mybatis-config.xml"; 3 InputStream inputStream = Resources.getResourceAsStream(resource); 4 return new SqlSessionFactoryBuilder().build(inputStream); 5 } 6 7 @Test 8 public void testMapper() throws IOException { 9 SqlSessionFactory sqlSessionFactory = getSqlSessionFactory(); 10 //1.获取到sqlsession 不会自动提交数据 11 SqlSession openSession = sqlSessionFactory.openSession(); 12 EmpDao mapper = openSession.getMapper(EmpDao.class); 13 14 Emp emp = mapper.getEmpById(4); 15 System.out.println(emp); 16 17 //手动提交数据 18 openSession.commit(); 19 openSession.close(); 20 }
标签:from mybatis sys session tsql ati result span exception
原文地址:https://www.cnblogs.com/wanerhu/p/10719006.html