packagenet.huawei.hrsys_ssm.mapper;importnet.huawei.hrsys_ssm.bean.Employee;importorg.apache.ibatis.annotations.*;importjava.util.List;@MapperpublicinterfaceEmployeeMapper{@Insert("insert into employee (age, gender, name, number, dep_id) "+"values (#{age}, #{gender}, #{name}, #{number}, #{depId})")intinsert(Employee employee);@Delete("delete from employee where id = #{id}")intdeleteById(int id);@Update("update employee set age = #{age}, gender = #{gender}, "+"name = #{name}, number = #{number}, dep_id = #{depId} where id = #{id}")intupdate(Employee employee);@Select("select * from employee where id = #{id}")EmployeefindById(int id);@Select("select * from employee")List<Employee>findAll();}
2. 测试员工映射器接口
2.1 自动装配员工映射器
使用@Autowired注解自动装配EmployeeMapper。
2.2 测试按标识符查询员工方法
创建testFindById()测试方法。
@TestpublicvoidtestFindById(){int id =1;Employee employee = employeeMapper.findById(id);if(employee !=null){System.out.println(employee);}else{System.out.println("标识符为["+ id +"]的员工不存在~");}}