• 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);
    
  • 相关阅读:
    JDk和Mevan安装和配置
    如何修改windows系统的host文件
    字符串格式化
    可变和不可变的数据类型
    拦截
    eclipse格式化代码模板
    oracle语法练习汇总
    PLSQL语法
    oracle创建完实例删除的时候报ORA-01031:insufficient privileges错误,解决办法
    socket多线程方式案例
  • 原文地址:https://www.cnblogs.com/mzdljgz/p/12656850.html
Copyright © 2020-2023  润新知