MyBatis操做-查询

1 阅读1分钟

用到的SQL语句

select * from emp where id = 1;

实体类Emp

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Emp {
    private Integer id;
    private String username;
    private String password;
    private String name;
    private Short gender;
    private String image;
    private Short job;
    private LocalDate entrydate;
    private Integer deptId;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
}

映射EmpMapper

public interface EmpMapper {
    //根据id查询数据
    @Select("select * from emp where id = 1")
    public Emp selectById(Integer id);
}

测试

@Test
public void testSelect(){
    Emp emp = empMapper.selectById(5);
    System.out.println(emp);
}