CUDThe true power of MyBatis is in the Mapped Statements. This is where the magic happens.
mybatis运行CUD直接定义以下类型返回值
Integer,Long,Boolean 我们需要手动提交数据
sqlSessionFactory.openSession();—>手动提交sqlSessionFactory.openSession(true);—>自动提交
接口:
package com.atguigu.mybatis.dao;
import com.atguigu.mybatis.bean.Employee;
public interface EmployeeMapper {
public Employee getEmpById(Integer id);
public Long addEmp(Employee employee);
public boolean updateEmp(Employee employee);
public void deleteEmpById(Integer id);
}
映射文件:
在这里就测试一个addEmp函数:
@Test
public void test02() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
try
{
EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
Employee employee = new Employee(null, "jack", "jack@qq.com", "1");
mapper.addEmp(employee);
//手动提交数据
sqlSession.commit();
}finally {
sqlSession.close();
}
}


![[mybatis]Mapper XML Files [mybatis]Mapper XML Files](http://www.mshxw.com/aiimages/31/715572.png)
