<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                Spring Data Jpa的主要類   七個Repository接口:     1.Repository     2.CrudRepository     3.PagingAndSortingRepository     4.QueryByExampleExecutor     5.JpaRepository     6.JpaSpeccificationExecutor     7.QueryDslPredicateExecutor   兩個實現類:     1.SimpleJpaRepository     2.QueryDslJpaRepository ***** 本框架中`JpaPlusRepository`實現了`JpaRepositoryImplementation`、`QuerydslPredicateExecutor` 在保留原方法基礎上新增對`QueryDsl`的支持。 ``` public interface JpaPlusRepository<T, ID> extends JpaRepositoryImplementation<T, ID>, QuerydslPredicateExecutor<T> { T findOne(ID id); Page<T> findAll(JPAQuery<T> query, Pageable pageable); Page<T> findAll(JPAQuery<T> query, Pageable pageable, OrderSpecifier<?>... orders); <S extends T> S insertOrUpdate(S entity); <S extends T> List<S> insertOrUpdate(S... entities); <S extends T> List<S> insertOrUpdate(List<S> entities); int insertOrUpdateRow(T entity); int insertOrUpdateRow(T... entities); int insertOrUpdateRow(List<T> entities); @Deprecated int insert(T entity); int update(T entity, Predicate... predicate); int delete(ID... ids); int delete(List<ID> ids); int delete(Predicate... predicate); } ``` ### 依賴模塊 ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> ``` ### 啟用注解 @EnableJpaPlusRepositories ``` @EnableJpaPlusRepositories @SpringBootApplication public class GotvApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication app = new SpringApplication(GotvApplication.class); app.run(args); } } ``` ## 如何使用 ### 1. 單表分頁查詢 ``` @RequestMapping(value = "page") public PaginationResult page(BaseVo base, PaginationVo page) { // 對象 QSLog qsLog = QSLog.sLog; // 條件 Predicate predicate = qsLog.id.isNotNull(); if (ObjectUtils.isNotEmpty(base.getKeyword())) { Predicate p1 = qsLog.id.like("%" + base.getKeyword() + "%"); Predicate p2 = qsLog.method.likeIgnoreCase("%" + base.getKeyword() + "%"); Predicate p3 = qsLog.type.likeIgnoreCase("%" + base.getKeyword() + "%"); predicate = ExpressionUtils.and(predicate, ExpressionUtils.anyOf(p1, p2, p3)); } // 排序 Sort sort = Sort.by(Direction.ASC, SLog.FIELDS.createDate); // 分頁 Pageable pageable = PageRequest.of(page.getPage(), page.getLimit(), sort); // 查詢 Page<SLog> data = mSLogRepository.findAll(predicate, pageable); // 構造 return PaginationHelper.create(data); } ``` ### 2. 多表分頁查詢 ``` @RequestMapping(value = "page") public PaginationResult page(BaseVo base, PaginationVo page) { // 對象 QUser qUser = QUser.user; QSRole qRole = QSRole.sRole; QUserRole qUserRole = QUserRole.userRole; // 條件 Predicate predicate = qUser.id.isNotNull(); if (ObjectUtils.isNotEmpty(base.getKeyword())) { Predicate p1 = qUser.id.like("%" + base.getKeyword() + "%"); Predicate p2 = qUser.username.likeIgnoreCase("%" + base.getKeyword() + "%"); Predicate p3 = qUser.nickname.likeIgnoreCase("%" + base.getKeyword() + "%"); predicate = ExpressionUtils.and(predicate, ExpressionUtils.anyOf(p1, p2, p3)); } // 分頁 Pageable pageable = PageRequest.of(page.getPage(), page.getLimit(), Sort.by(Direction.DESC, User.FIELDS.createDate)); // 查詢字段 QBean<User> selectBean = Projections.fields(User.class , qUse // 主表字段 , qRole.id.longValue().as(User.FIELDS.roleId), //聯查字段 , qRole.name.as(User.FIELDS.roleName)); // 構造查詢 JPAQuery<User> jpaQuery = mJPAQueryFactory.select(selectBean) .from(qUser) .leftJoin(qUserRole) .on(qUser.id.eq(qUserRole.pk.users)) .leftJoin(qRole) .on(qRole.id.eq(qUserRole.pk.roles)) .where(predicate); // 分頁查詢 Page<User> data = mUserRepository.findAll(jpaQuery, pageable); // 構造 return PaginationHelper.create(data); } ``` ### 3. 添加 ``` @RequestMapping(value = "save") @Transactional public Result save(BaseVo base) { User user = new User(); int row = mUserRepository.insertOrUpdate(user); return (row >= 1) ? R.succ() : R.fail(); } ``` ### 4. 修改 ``` @RequestMapping(value = "update") @Transactional public Result update(BaseVo base) { QUser qUser = QUser.user; int row = (int) mJPAQueryFactory.update(qUser).set(qUser.isEnable, 1).where(qUser.id.in(base.getIds())); return (row >= 1) ? R.succ() : R.fail(); } ``` ### 5. 刪除 ``` @RequestMapping(value = "delete") @Transactional public Result delete(BaseVo base) { int row = mUserRepository.delete(base.getIds()); return (row >= 1) ? R.succ() : R.fail(); } ``` 上述只是部分示例,拓展后常規方法共48個 ### 屬性表達式 | 關鍵字 | 示例 | JPQL 片段 | | --- | --- | --- | | And | findByNameAndAge | where x.name = ?1 and x.age = ?2 | | Or | findByNameOrAge | where x.name = ?1 or x.age = ?2 | | Is | findByNameIs | where x.name = ?1 | | Equals | findByNameEquals | where x.name = ?1 | | Between | findByStartDateBetween | where x.startDate between ?1 and ?2 | | LessThan | findByAgeLessThan | where x.age < ?1 | | LessThanEqual | findByAgeLessThanEqual | where x.age ? ?1 | | GreaterThan | findByAgeGreaterThan | where x.age > ?1 | | GreaterThanEqual | findByAgeGreaterThanEqual | where x.age >= ?1 | | After | findByStartDateAfter | where x.startDate > ?1 | | Before | findByStartDateBefore | where x.startDate < ?1 | | IsNull | findByAgeIsNull | where x.age is null | | IsNotNull | findByAgeIsNotNull | where x.age not null | | NotNull | findByAgeNotNull | where x.age not null | | Like | findByNameLike | where x.name like ?1 | | NotLike | findByNameNotLike | where x.name not like ?1 | | StartingWith | findByNameStartingWith | where x.name like ?1 (parameter bound with appended %) | | EndingWith | findByNameEndingWith | where x.name like ?1 (parameter bound with prepended %) | | Containing | findByNameContaining | where x.name like ?1 (parameter bound wrapped in %) | | OrderBy | findByAgeOrderByNameDesc | where x.age = ?1 order by x.name desc | | Not | findByNameNot | where x.name <> ?1 | | In | findByAgeIn(Collectionages) | where x.age in ?1 | | NotIn | findByAgeNotIn(Collectionage) | where x.age not in ?1 | | TRUE | findByActiveTrue() | where x.active = true | | FALSE | findByActiveFalse() | where x.active = false | | IgnoreCase | findByNameIgnoreCase | where UPPER(x.name) = UPPER(?1) |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看