Search in sources :

Example 11 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class ResourceServiceImpl method findResourcesByCreator.

@Override
public PageInfo<Resource> findResourcesByCreator(int pagination, int pageSize, List<Integer> resourceTypes, String keyword, String orderByClause, Integer creator) {
    // 获取当前登陆者身份信息
    Condition condition = new Condition(Resource.class);
    // 条件1、查找用户指定的几种资源类型
    if (resourceTypes.size() == 0) {
        return new PageInfo<Resource>(new ArrayList<Resource>());
    } else {
        Criteria criteria = condition.createCriteria();
        criteria.andIn("type", resourceTypes);
    }
    // 条件2、关键字搜索
    if (keyword != null && !"".equals(keyword)) {
        Criteria criteria = condition.createCriteria();
        List<String> words = StringUtil.split(keyword, ' ');
        for (String word : words) {
            criteria.orLike("keyword", "%" + word + "%");
        }
        condition.and(criteria);
    }
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("creator", creator);
    condition.and(criteria);
    // 开始分页查询
    PageHelper.startPage(pagination, pageSize, orderByClause);
    List<Resource> result = findByCondition(condition);
    PageInfo<Resource> page = new PageInfo<Resource>(result);
    // 查到的总记录数
    // 解释一下:这个page.getTotal(),是所有符合条件的记录数。
    // result.size():是当前页中的数据量 <= pageSize
    LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pagination, pageSize, page.getPages());
    return page;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PageInfo(com.github.pagehelper.PageInfo) Resource(com.cas.sim.tis.entity.Resource) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 12 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class CatalogServiceImpl method findCatalogsByParentId.

@Override
public List<Catalog> findCatalogsByParentId(Integer rid) {
    Condition condition = new Condition(Catalog.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("rid", rid);
    criteria.andEqualTo("del", 0);
    CatalogMapper catalogMapper = (CatalogMapper) mapper;
    catalogMapper.selectByCondition(condition);
    List<Catalog> catalogs = null;
    try {
        catalogs = catalogMapper.selectByCondition(condition);
        LOG.debug("查询到子节点数量:{}", catalogs.size());
    } catch (Exception e) {
        LOG.error("查询ID{}下子节点失败!", rid);
        catalogs = Collections.emptyList();
    }
    return catalogs;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) CatalogMapper(com.cas.sim.tis.mapper.CatalogMapper) Criteria(tk.mybatis.mapper.entity.Example.Criteria) Catalog(com.cas.sim.tis.entity.Catalog)

Example 13 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class ClassServiceImpl method findClassesByTeacher.

@Override
public List<Class> findClassesByTeacher(int teacherId) {
    Condition condition = new Condition(Class.class);
    condition.orderBy("createDate").desc();
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("teacherId", teacherId);
    criteria.andEqualTo("del", 0);
    return findByCondition(condition);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 14 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompServiceImpl method findElecCompByModel.

@Override
public ElecComp findElecCompByModel(String model) {
    ElecCompMapper dao = (ElecCompMapper) mapper;
    Condition condition = new Condition(ElecComp.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("model", model);
    List<ElecComp> compList = dao.selectByCondition(condition);
    if (compList.size() == 0) {
        return null;
    } else if (compList.size() > 1) {
        throw new TooManyResultsException();
    }
    return compList.get(0);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) ElecCompMapper(com.cas.sim.tis.mapper.ElecCompMapper) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ElecComp(com.cas.sim.tis.entity.ElecComp) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 15 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class QuestionServiceImpl method countQuestionByLibrary.

@Override
public int countQuestionByLibrary(int rid) {
    Condition condition = new Condition(Question.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("relateId", rid);
    return getTotalBy(condition);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

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