Search in sources :

Example 21 with Criteria

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();
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) User(com.cas.sim.tis.entity.User) ServerException(com.cas.sim.tis.services.exception.ServerException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) Criteria(tk.mybatis.mapper.entity.Example.Criteria) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) ServerException(com.cas.sim.tis.services.exception.ServerException)

Example 22 with Criteria

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;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PageInfo(com.github.pagehelper.PageInfo) User(com.cas.sim.tis.entity.User) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 23 with Criteria

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;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PageInfo(com.github.pagehelper.PageInfo) User(com.cas.sim.tis.entity.User) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 24 with Criteria

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());
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) User(com.cas.sim.tis.entity.User) Criteria(tk.mybatis.mapper.entity.Example.Criteria) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Criteria

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);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Resource(javax.annotation.Resource) Criteria(tk.mybatis.mapper.entity.Example.Criteria) PageInfo(com.github.pagehelper.PageInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Condition (tk.mybatis.mapper.entity.Condition)25 Criteria (tk.mybatis.mapper.entity.Example.Criteria)25 PageInfo (com.github.pagehelper.PageInfo)6 User (com.cas.sim.tis.entity.User)4 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)3 Library (com.cas.sim.tis.entity.Library)2 Resource (com.cas.sim.tis.entity.Resource)2 ResourceMapper (com.cas.sim.tis.mapper.ResourceMapper)2 ArrayList (java.util.ArrayList)2 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BrowseHistory (com.cas.sim.tis.entity.BrowseHistory)1 Catalog (com.cas.sim.tis.entity.Catalog)1 Collection (com.cas.sim.tis.entity.Collection)1 ElecComp (com.cas.sim.tis.entity.ElecComp)1 LibraryAnswer (com.cas.sim.tis.entity.LibraryAnswer)1 LibraryPublish (com.cas.sim.tis.entity.LibraryPublish)1