-- ================插入=================
insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) values (
'tom','塔姆','tom',1 , '1.png' ,now(),1,now(),now()
@Options(keyProperty = "id",useGeneratedKeys = true)
@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 insert(Emp emp);
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Emp {
private Integer id; // Id
private String username; //用户名
private String password; //用户密码
private String name ; //姓名
private short gender; //性别 1男 2女
private String image; //头像 url
private short job ; // 工作职位 1班主任 2讲师 3 学工主管 4 教研主管 5 咨询师
private LocalDate entrydate ; //入职时间
private Integer deptId; // 部门ID
private LocalDateTime createTime; //创建时间
private LocalDateTime updateTime; // 修改时间
@Test
public void testInsert(){
//构造员工对象
Emp emp =new Emp();
emp.setUsername("tom2");
emp.setName("塔姆");
emp.setImage("1.jpg");
emp.setGender((short)1);
emp.setJob((short)1);
emp.setEntrydate(LocalDate.of(2000,1,1));
emp.setCreateTime(LocalDateTime.now());
emp.setUpdateTime(LocalDateTime.now());
emp.setDeptId(1);
empMapper.insert(emp);
System.out.println(emp.getId());
}
//的一种
@Select("select id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id=#{di}")
public Emp getById (Integer id);
//第二种
@Results({
@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 getById(Integer id);
#开启 mybatis的驼峰命名自动映射开关 变成 a_column--->aColumn
mybatis.configuration.map-underscore-to-camel-case=true
@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 list(String name, Short gender, LocalDate begin ,LocalDate end);
@Test
public void testList(){
List empList= empMapper.list("张",(short)1,LocalDate.of(2010,1,1)
,LocalDate.of(2020,1,1));
System.out.println(empList);
}