@Mapper
public interface EmpMapper {
// 根据id删除员工信息
@Delete
("delete from mybatis.emp where id=#{id}")
public int EmpDelete(Integer id);
// 查询所有员工信息
@Select("select * from emp")
public List<Emp> EmpSelect();
//将自动增长的id封装到emp对象的id属性中
@Options(useGeneratedKeys = true, keyProperty="id")
//向emp表中插入一条数据
@Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
"values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
public void EmpInsert(Emp emp);
//更新emp表中的数据
@Update("update emp set username=#{username},name=#{name},gender=#{gender},image = #{image},"+
"job=#{job},entrydate=#{entrydate},dept_id = #{deptId},update_time=#{updateTime} where id=#{id}")
public void update(Emp emp);
//方案一:为字段起别名,让MySQL中的字段和java类中的字段名一致,这样mybatis 就能获取MySQL中相对应的字段数据了
// @Select("select id, username, password, name, gender, image, job, entrydate, dept_id as deptId, create_time as createTime, " +
// "update_time as updateTime from emp where id = #{id}")
// public Emp Search(Integer id);
// // 方案二:在Results注解中将数据库表中的dept_id列映射到Java对象中的deptId属性
// @Results({
// //MySQL中的字段名和Java类中对应的属性名
// @Result(column = "dept_id",property = "deptId"),
// @Result(column = "create_time",property = "createTime"),
// @Result(column = "update_time",property = "updateTime")
//
// })
// @Select("select * from emp where id = #{id}")
// public Emp Search(Integer id);
//方案三:在配置文件中开启mybatis的驼峰命名自动映射开关mybatis.camel,无需动原代码自动映射
// 根据id查询员工信息
@Select("select * from emp where id = #{id}")
public Emp Search(Integer id);
@Select("select * from emp where name like concat('%',#{name},'%') and gender= #{gender} and entrydate between #{begin} and #{end} order by update_time desc")
//条件查询
public List<Emp> conditionSearch(String name , Short gender , LocalDate begin , LocalDate end);
}