use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class UserServiceImpl method login.
@Override
public User login(String usercode, String password) {
Condition condition = new Condition(User.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("code", usercode);
criteria.andEqualTo("password", password);
criteria.andEqualTo("del", 0);
List<User> user = null;
try {
user = mapper.selectByCondition(condition);
} catch (Exception e) {
throw new ServerException("服务器异常", e);
}
if (user.size() == 1) {
return user.get(0);
} else if (user.size() == 0) {
throw new ServiceException("用户名或密码错误!");
} else {
throw new TooManyResultsException();
}
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class UserServiceImpl method findTeachers.
@Override
public PageInfo<User> findTeachers(int pageIndex, int pageSize) {
Condition condition = new Condition(User.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("role", RoleConst.TEACHER);
criteria.andEqualTo("del", 0);
condition.orderBy("createDate").desc();
PageHelper.startPage(pageIndex, pageSize);
List<User> result = findByCondition(condition);
PageInfo<User> page = new PageInfo<>(result);
LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pageIndex, pageSize, page.getPages());
return page;
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class UserServiceImpl method findStudents.
@Override
public PageInfo<User> findStudents(int pageIndex, int pageSize, int classId) {
Condition condition = new Condition(User.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("role", RoleConst.STUDENT);
criteria.andEqualTo("classId", classId);
criteria.andEqualTo("del", 0);
condition.orderBy("createDate").desc();
PageHelper.startPage(pageIndex, pageSize);
List<User> result = findByCondition(condition);
PageInfo<User> page = new PageInfo<>(result);
LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pageIndex, pageSize, page.getPages());
return page;
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class DBTest method testAdminLogin.
@Test
public void testAdminLogin() throws Exception {
Condition condition = new Condition(User.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("code", "admin");
criteria.andEqualTo("password", "123456");
List<User> users = userMapper.selectByCondition(condition);
Assert.assertEquals(1, users.size());
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class PageHelpTest method testPage.
@Test
public void testPage() throws Exception {
Condition condition = new Condition(com.cas.sim.tis.entity.Resource.class);
Criteria criteria = condition.createCriteria();
// 条件1、查找用户指定的几种资源类型
criteria.andIn("type", new ArrayList<>(Arrays.asList(1, 4)));
// 条件2、只能查找管理员或自己上传的资源。
// 属于自己的资源
// criteria.andEqualTo("creatorId", 2);
// 或者是公开的资源
criteria.orEqualTo("share", true);
PageHelper.startPage(0, 2);
List<com.cas.sim.tis.entity.Resource> resources = resourceService.findByCondition(condition);
PageInfo<com.cas.sim.tis.entity.Resource> page = new PageInfo<com.cas.sim.tis.entity.Resource>(resources);
System.out.println(page.getTotal());
Assert.assertEquals(4, resources.size());
resources.stream().forEach(System.out::println);
}
Aggregations