zoukankan      html  css  js  c++  java
  • jpa模糊查询(表中的某些数据)

    业务代码

    Controller

       @GetMapping({"/task/project"})
        public ResponseEntity findByProjectTitle(@RequestParam(required = false, defaultValue = "") String title) {
            return ResponseEntity.ok(projectService.findAllByUserPidAndProjectTitleLikeAndVersionIs(getOperatorId(), title));
        }
    

    Service

        @Transactional(readOnly = true)
        public List<ProjectInfoRepository.ProjectSimpleInfo> findAllByUserPidAndProjectTitleLikeAndVersionIs(String operatorId, String title) {
            title = StringUtils.hasText(title) ? "%" + title + "%" : "%%";
            return repository.findAllByUserPidAndProjectTitleLikeAndVersionIs(operatorId, title, 3, ProjectInfoRepository.ProjectSimpleInfo.class);
        }
    

    此方法findAllByUserPidAndProjectTitleLikeAndVersionIs(operatorId, title, 3, ProjectInfoRepository.ProjectSimpleInfo.class)第三个参数

    ProjectRepository

    public interface ProjectInfoRepository extends JpaRepository<ProjectInfo, String>, JpaSpecificationExecutor<ProjectInfo>, ProjectInfoCustomRepository {
    
        <T> List<T> findAllByUserPidAndProjectTitleLikeAndVersionIs(String userPid, String projectTitle, Integer version, Class<T> type);
    
        Optional<ProjectInfo> findByPid(String pid);
    
        interface ProjectSimpleInfo {
            String getPid();
    
            String getProjectTitle();
        }
    }
    

    Repository

    <T> List<T> findAllByUserPidAndProjectTitleLikeAndVersionIs(String userPid, String projectTitle, Integer version, Class<T> type);
    
  • 相关阅读:
    我的第一个博客在博客园安家了,哈哈~欢迎大家光临
    JS未设置对象问题解决方案
    关于Oracle的优化
    USACO 1.2 Milking Cows
    C语言的文件操作 freopen
    USACO 1.2 Palindromic Squares
    USACO 1.1 Broken Necklace
    ACM征程再次起航!
    USACO 1.3 Barn Repair
    USACO 1.2 Transformations
  • 原文地址:https://www.cnblogs.com/mzdljgz/p/12656850.html
Copyright © 2011-2022 走看看