Spring Data - Spring Data JPA 提供的各种Repository接口

2023-10-30

最近博主越来越懒了,深知这样不行。还是决定努力奋斗,如此一来,就有了一下一波复习

演示代码都基于Spring Boot + Spring Data JPA 

传送门: 博主的测试代码 

------------------------------------------------------------------------------------------------------------------------------

什么是Spring Data JPA?

Spring Data 是Spring提供的操作数据的框架在Spring data JPA是Spring data的一个模块,通过Spring data 基于jpa标准操作数据的模块。

Spring Data的核心能力,就是基于JPA操作数据,并且可以简化操作持久层的代码。

Spring Data JPA提供的核心接口

前提数据:

-- MySQL dump 10.13  Distrib 5.6.16, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: amber
-- ------------------------------------------------------
-- Server version    5.6.16-1~exp1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `table_user`
--

DROP TABLE IF EXISTS `table_user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `table_user` (
  `id` int(11) NOT NULL DEFAULT '0',
  `name` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `table_user`
--

LOCK TABLES `table_user` WRITE;
/*!40000 ALTER TABLE `table_user` DISABLE KEYS */;
INSERT INTO `table_user` VALUES (4,'tony',NULL,'shanghai',18),(5,'amber',NULL,'shanghai',18),(2,'amber1',NULL,'shanghai',18),(3,'tony',NULL,'shanghai',18),(0,'amber1',NULL,'shanghai',18),(6,'amber',NULL,'shanghai',18);
/*!40000 ALTER TABLE `table_user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-01-13 13:43:57
SQL
package com.amber.pojo;
import lombok.Data;
import javax.persistence.*;
@Entity
@Table(name = "table_user")
@Data
public class User {
    @Id
    @GeneratedValue
    private Integer id;
    private String name;
    private Integer age;
    private String address;
}
User
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>groupId</groupId>
    <artifactId>SpringBoot-JPA</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <lombok.version>1.16.20</lombok.version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>
pom.xml

Repository:

@org.springframework.stereotype.Repository
public interface UserRepository  extends Repository<User, Integer> {
}

 

  • 提供了方法名成查询方式: 

    方法的名称要遵循 findBy + 属性名(首字母大写) + 查询条件(首字母大写 Is Equals)

     findByNameLike(String name)

    findByName(String name)

    findByNameAndAge(String name, Integer age)

    findByNameOrAddress(String name) 等...

  • 基于@Query注解的查询和更新
 /**
     * SQL nativeQuery的值是true 执行的时候不用再转化
     * @param name
     * @return
     */
    @Query(value = "SELECT * FROM table_user WHERE name = ?1", nativeQuery = true)
    List<User> findByUsernameSQL(String name);

  //基于HQL

    /**
     * 基于HQL
     * @param name
     * @param id
     * @return
     */
    @Query("Update User set name = ?1 WHERE id = ?2")
    @Modifying
    int updateNameAndId(String name, Integer id);

CrudReposiroty : 继承了Repository

/*
 * Copyright 2008-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.repository;
import java.util.Optional;
/**
 * Interface for generic CRUD operations on a repository for a specific type.
 * 
 * @author Oliver Gierke
 * @author Eberhard Wolff
 */
@NoRepositoryBean
public interface CrudRepository<T, ID> extends Repository<T, ID> {
    /**
     * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
     * entity instance completely.
     * 
     * @param entity must not be {@literal null}.
     * @return the saved entity will never be {@literal null}.
     */
    <S extends T> S save(S entity);
    /**
     * Saves all given entities.
     * 
     * @param entities must not be {@literal null}.
     * @return the saved entities will never be {@literal null}.
     * @throws IllegalArgumentException in case the given entity is {@literal null}.
     */
    <S extends T> Iterable<S> saveAll(Iterable<S> entities);
    /**
     * Retrieves an entity by its id.
     * 
     * @param id must not be {@literal null}.
     * @return the entity with the given id or {@literal Optional#empty()} if none found
     * @throws IllegalArgumentException if {@code id} is {@literal null}.
     */
    Optional<T> findById(ID id);
    /**
     * Returns whether an entity with the given id exists.
     * 
     * @param id must not be {@literal null}.
     * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
     * @throws IllegalArgumentException if {@code id} is {@literal null}.
     */
    boolean existsById(ID id);
    /**
     * Returns all instances of the type.
     * 
     * @return all entities
     */
    Iterable<T> findAll();
    /**
     * Returns all instances of the type with the given IDs.
     * 
     * @param ids
     * @return
     */
    Iterable<T> findAllById(Iterable<ID> ids);
    /**
     * Returns the number of entities available.
     * 
     * @return the number of entities
     */
    long count();
    /**
     * Deletes the entity with the given id.
     * 
     * @param id must not be {@literal null}.
     * @throws IllegalArgumentException in case the given {@code id} is {@literal null}
     */
    void deleteById(ID id);
    /**
     * Deletes a given entity.
     * 
     * @param entity
     * @throws IllegalArgumentException in case the given entity is {@literal null}.
     */
    void delete(T entity);
    /**
     * Deletes the given entities.
     * 
     * @param entities
     * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
     */
    void deleteAll(Iterable<? extends T> entities);
    /**
     * Deletes all entities managed by the repository.
     */
    void deleteAll();
}
CrudRepository

Crud主要是添加了对数据的增删改查的方法

PagingAndSortingRepository: 继承了CrudRepository

/*
 * Copyright 2008-2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
 * Extension of {@link CrudRepository} to provide additional methods to retrieve entities using the pagination and
 * sorting abstraction.
 * 
 * @author Oliver Gierke
 * @see Sort
 * @see Pageable
 * @see Page
 */
@NoRepositoryBean
public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
    /**
     * Returns all entities sorted by the given options.
     * 
     * @param sort
     * @return all entities sorted by the given options
     */
    Iterable<T> findAll(Sort sort);
    /**
     * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
     * 
     * @param pageable
     * @return a page of entities
     */
    Page<T> findAll(Pageable pageable);
}
PagingAndSortingRepository
/**
 * 继承了Repository,缺点只能对所有的数据进行排序或者分页
 */
@Repository
public interface UserPagingAndSortingReposiroty extends PagingAndSortingRepository<User, Integer> {
}

 

package com.amber;
import com.amber.pojo.User;
import com.amber.repository.UserPagingAndSortingReposiroty;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = JPAApplication.class)
public class UserPagingAndSortingReposirotyTest {
    @Autowired
    UserPagingAndSortingReposiroty userPagingAndSortingReposiroty;
    /**
     * 排序
     */
    @Test
    public void TestSort(){
        //定义排序规则
        Sort.Order order = new Sort.Order(Sort.Direction.DESC, "name");
        Sort.Order order1 = new Sort.Order(Sort.Direction.DESC, "id");
        //Sort
        Sort sort = new Sort(order, order1);
        List<User> users = (List<User>)userPagingAndSortingReposiroty.findAll(sort);
        System.out.println(users);
    }
    /**
     * 分页Pageable封装了分页的参数,当前页,每一页显示的条数,注意当前页是从0开始的
     */
    @Test
    public void TestPaging(){
        //Pageable是个接口
        Pageable pageable = new PageRequest(0, 10);
        //返回Page对象
        Page<User> uses = userPagingAndSortingReposiroty.findAll(pageable);
        System.out.println(uses.getTotalElements());
        System.out.println(uses.getTotalPages());
        System.out.println(uses.getNumberOfElements());
    }
    /**
     * 分页 + 排序
     */
    @Test
    public void TestPagingAndSort(){
        //定义排序规则
        Sort.Order order = new Sort.Order(Sort.Direction.DESC, "name");
        Sort.Order order1 = new Sort.Order(Sort.Direction.DESC, "id");
        //Sort
        Sort sort = new Sort(order, order1);
        //Pageable是个接口
        Pageable pageable = new PageRequest(0, 10, sort);
        //返回Page对象
        Page<User> uses = userPagingAndSortingReposiroty.findAll(pageable);
        System.out.println(uses.getTotalElements());
        System.out.println(uses.getTotalPages());
        System.out.println(uses.getNumberOfElements());
    }
}
UserPagingAndSortingReposirotyTest

 

JPARepository: 继承了PagingAndSortingRepository接口

在开发中常用JPARepository

优点: 对继承父接口中方法的返回值进行了适配,因为在父类接口中通常都返回迭代器,需要我们自己进行强制类型转化。而在JpaRepository中,直接返回了List

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.data.jpa.repository;
import java.util.List;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;
@NoRepositoryBean
public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
    List<T> findAll();
    List<T> findAll(Sort var1);
    List<T> findAllById(Iterable<ID> var1);
    <S extends T> List<S> saveAll(Iterable<S> var1);
    void flush();
    <S extends T> S saveAndFlush(S var1);
    void deleteInBatch(Iterable<T> var1);
    void deleteAllInBatch();
    T getOne(ID var1);
    <S extends T> List<S> findAll(Example<S> var1);
    <S extends T> List<S> findAll(Example<S> var1, Sort var2);
}
JpaRepository

JpaSpecificationExecutor: 这个接口单独存在,没有继承以上说的接口

主要提供了多条件查询的支持,并且可以在查询中添加分页和排序。

因为这个接口单独存在,因此需要配合以上说的接口使用,如:

/**
 * JpaSpecificationExecutor是单独存在的,需要配合这JpaRepository一起使用
 */
@Repository
public interface UserJpaSpecificationExecutor extends JpaSpecificationExecutor<User>, JpaRepository<User, Integer> {
}

package com.amber;
import com.amber.pojo.User;
import com.amber.repository.UserJpaSpecificationExecutor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = JPAApplication.class)
public class UserJpaSecificationExecutorTest {
    @Autowired
    UserJpaSpecificationExecutor userJpaSpecificationExecutor;
    /**
     * 多条件查询的另外一种写法
     */
    @Test
    public void testUser2(){
        //Specification是个接口,封装了查询信息
        Specification<User> specification = new Specification<User>() {
            /**
             * Predicate封装了单个查询条件
             * @param root 对查询对象属性的封装,比如我们这里是查询User,因此root可以看成是User
             * @param query CriteriaQuery封装了查询中的各部分信息, Select from order
             * @param cb CB查询条件的构造器
             * @return
             */
            @Override
            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Predicate p1 = cb.equal(root.get("name"), "amber");
                Predicate p2 = cb.equal(root.get("age"), "18");
                return cb.and(p1,p2);
            }
        };
        List<User> users = userJpaSpecificationExecutor.findAll(specification);
        System.out.println(users);
    }
    /**
     * 多条件查询
     */
    @Test
    public void testUser1(){
        //Specification是个接口,封装了查询信息
        Specification<User> specification = new Specification<User>() {
            /**
             * Predicate封装了单个查询条件
             * @param root 对查询对象属性的封装,比如我们这里是查询User,因此root可以看成是User
             * @param query CriteriaQuery封装了查询中的各部分信息, Select from order
             * @param cb CB查询条件的构造器
             * @return
             */
            @Override
            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<>();
                Predicate p1 = cb.equal(root.get("name"), "amber");
                Predicate p2 = cb.equal(root.get("age"), "18");
                predicates.add(p1);
                predicates.add(p2);
                Predicate[] predicateArr = new Predicate[predicates.size()];
                return cb.and(predicates.toArray(predicateArr));
            }
        };
        List<User> users = userJpaSpecificationExecutor.findAll(specification);
        System.out.println(users);
    }
    /**
     * 单条件查询
     */
    @Test
    public void testUser(){
        //Specification是个接口,封装了查询信息
        Specification<User> specification = new Specification<User>() {
            /**
             * Predicate封装了单个查询条件
             * @param root 对查询对象属性的封装,比如我们这里是查询User,因此root可以看成是User
             * @param query CriteriaQuery封装了查询中的各部分信息, Select from order
             * @param cb CB查询条件的构造器
             * @return
             */
            @Override
            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Predicate p1 = cb.equal(root.get("name"), "amber");
                return p1;
            }
        };
        List<User> users = userJpaSpecificationExecutor.findAll(specification);
        System.out.println(users);
    }
}
View Code

总结:

  Spring Data Jpa中一共提供了

  • Repository:
    •   提供了findBy + 属性方法 
    •   @Query 
      •   HQL: nativeQuery 默认false
      •   SQL: nativeQuery 默认true
        • 更新的时候,需要配合@Modifying使用
  • CurdRepository:
    • 继承了Repository 主要提供了对数据的增删改查
  • PagingAndSortRepository:
    • 继承了CrudRepository 提供了对数据的分页和排序,缺点是只能对所有的数据进行分页或者排序,不能做条件判断
    JpaRepository: 继承了PagingAndSortRepository
    • 开发中经常使用的接口,主要继承了PagingAndSortRepository,对返回值类型做了适配
  • JpaSpecificationExecutor
    • 提供多条件查询
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Data - Spring Data JPA 提供的各种Repository接口 的相关文章

  • Github API 返回发布数组的空资产

    我正在尝试通过 gitHub api 跟踪 gitHub 版本的 download count 我不需要太多 我只是想看看它是什么 我正在尝试获取以下信息 http developer github com v3 repos release
  • git-shell - 新存储库

    我有一台专门的服务器git用户和存储库我正在尝试使用git shell method http git scm com book en Git on the Server Setting Up the Server让我的开发人员能够从事多个
  • 创建私有远程ivy存储库

    我已经做了很多搜索 但无法将所有部分放在一起 我想在我们的一台服务器上创建一个 ivy 存储库 我想将其锁定 使其成为私有的 然后能够从 Gradle 发布到此存储库 我知道如何使用 Gradle 进行发布 并且我可以使用 Gradle 创
  • 聚合根引用其他聚合根

    我目前正在大量使用 DDD 并且在从其他聚合根加载 操作聚合根时遇到问题 对于模型中的每个聚合根 我还有一个存储库 存储库负责处理根的持久性操作 假设我有两个聚合根 以及一些成员 实体和值对象 聚合根 1 和聚合根 2 AggregateR
  • Git:添加、推送、提交

    git 和 git 有什么区别add push and commit 只是来自 SVN 的有点困惑 其中 更新 将 添加 内容 而提交则执行 推送 并且也会 添加 git 中有各种不同的功能 希望根据您的经验给出一些解释 git add将修
  • Github API v3 不显示所有用户存储库

    如果我输入这个命令 curl https api github com users KiCad repos grep full name 我预计它将返回所有 KiCad 存储库 但它返回 full name KiCad Air Coils
  • 镜像两个可写 SVN 存储库之间的子文件夹

    我正在尝试处理涉及我公司的 SVN 服务器的情况 我们将所有重要代码保存在锁定服务器中 我们将其称为 开发 服务器 有些文件需要由公司网络外部的用户编辑 因此我们有另一个 SVN 服务器 全局 服务器 它可以在防火墙外部访问 并且包含那些包
  • 在 GitHub 上创建一个存储库的子目录,并将其作为我自己的存储库的一部分

    抱歉 我对 Git 和 GitHub 很陌生 我已经阅读了一些内容 但我不确定我想要做的是否是entirely可能的 基本上我想分叉 XBMC 上使用的 Confluence Skin 并修改此处的各种元素 https github com
  • 使用 Moq 模拟存储库

    为了模拟存储库 我使用下面的代码 我不明白为什么变量empl总是null 你知道我错过了什么吗 Thanks TestMethod public void Test var employee new Employee EmployeeID
  • Symfony2:在实体或控制器中使用业务(存储库)逻辑的最佳方法

    我的项目中遇到一个设计问题 与放置一些业务逻辑的位置有关 我有三个实体 Event TicketOrder 和 Ticket 一项活动有很多 TicketOrder 一项 TicketOrder 也有很多 Ticket 在我的模板中 我必须
  • 在气隙环境中使用 docker 的最佳实践

    我是 Docker 新手 想在气隙环境中使用它 我知道我可以在隔离系统中设置自己的存储库 但我不知道如何从 docker hub 获取所需的许多 docker 镜像到环境中 如果我可以将它们下载到 zip 或 tgz 存档中 那就太好了 但
  • 将库发布到 Maven 存储库

    我有一个稳定的开源库 http github com fernandezpablo85 scribe并想知道如何 以及是否 我可以将我的库发布到 Maven 官方存储库 以便人们可以将其包含在他们的pom xml文件并自动下载依赖项 将您的
  • 如何在两台电脑之间共享svn仓库

    我的工作站上有 SVN 存储库 我在工作站和笔记本电脑上都使用它 在工作站上 我可以在本地访问存储库 但在笔记本电脑上 我必须连接互联网才能访问存储库 这不方便 因为我无法在飞机 火车和其他无互联网的地方工作 我想比较修订等 在笔记本电脑上
  • Bitbucket:从提示绑定文件以供下载

    我在一个私人存储库中工作 并与我的朋友合作 他对 SCM 之类的东西不太友好 他所需要的只是监控我开发的最新版本 这是 1 个可执行文件 我想知道 而不是每次他想要获取最新更改时克隆整个存储库 有时我的更改集可能由几个仅在开发时使用而不是测
  • 将 Mercurial 存储库转换为 svn 存储库

    我知道你可以将 svn 存储库转换为 Mercurial 存储库 或使用 Mercurial 作为 svn 存储库的客户端 但我想要的是将 Mercurial 存储库转换为 svn 存储库 我们有一些使用 SVNKit 的工具 我们想继续使
  • 使用 ViewModel 设计 MVC 存储库

    我想创建一个存储库类来将我的数据逻辑与控制器分开 我使用 ViewModel 来表示一些数据 这些数据将填充来自不同表的数据 我有一些问题 对于像这样的方法GetAll 我要返回一个IQueryable
  • 如何将svn文件夹上一级

    我需要将 svn 文件夹移至上一级并保留所有历史记录 所有文件和目录来自https myserver com svn Project trunk into https myserver svn Project 我使用一个命令 svn mov
  • 将新文件推送到新存储库 Git

    我是 git 新手 还没有完全了解工作流程 因此 我在 github com 上创建了一个存储库 并且能够从我的计算机推送所有文件 现在我已经在 github 上创建了一个新的存储库 并在我的计算机上创建了一个新文件夹 所有内容都从新文件夹
  • 无法在 Junit 测试中自动装配 JpaRepository - Spring boot 应用程序

    Hi All 我正在尝试在 Spring boot 应用程序中执行 Junit 测试 Junit 应该测试一些 CRUD 操作 我正在使用 Spring Repositories 特别是 JpaRepository 存储库类 package
  • 存储库和服务层之间的区别

    我查看了一些相关的问题 但仍然没有看到存储库和服务层之间有太大区别 所以给出的例子我想它应该看起来像这样 如果不是请告诉我为什么 public interface ProductRepository extends CrudReposito

随机推荐

  • UE4联网2——视角同步

    在做完子弹的同步后发现和客户端和服务器的玩家的仰角是不同步的 所以在角色代码中加入tick函数更新玩家的仰角pitch 这里我们需要用到一个变量RemoteViewPitch 这是在pawn中定义的已经复制的公有变量 rpc 值得注意的是它
  • 忽略大小写的字符串比较

    问题描述 一般我们用strcmp可比较两个字符串的大小 比较方法为对两个字符串从前往后逐个字符相比较 按 ASCII 码值大小比较 直到出现不同的字符或遇到 0 为止 如果全部字符都相同 则认为相同 如果出现不相同的字符 则以第一个不相同的
  • vue3引用ElementPlus出错|如何在vue中引用TypeScript

    具体错误 直接套用elementplus官方文档里的模版 报错 Module parse failed Unexpected token You may need an additional loader to handle the res
  • 运放噪声如何计算?

    一 噪声 运放的噪声分为 1 电压噪声en v 2 电流噪声在电阻Rs和R1 R2上产生的等效噪声en i 3 电阻的热噪声enr 总输入噪声计算公式 en in sqrt env 2 eni 2 enr 2 总输出噪声计算公式 en ou
  • [第七届蓝帽杯全国大学生网络安全技能大赛 蓝帽杯 2023]——Web方向部分题 详细Writeup

    Web LovePHP 你真的熟悉PHP吗 源码如下
  • 【C++】C++入门

    目录 一 C 关键字 二 命名空间 2 1命名空间的定义 2 2命名空间的使用 2 2 1加命名空间名称和作用域限定符 2 2 2使用using 将命名空间中某个成员引入 2 2 3使用using namespace将命名空间引入 三 C
  • 【KnowledgeBase】CLIP多模态代码试玩

    文章目录 前言 一 CLIP整体流程简述 二 代码试玩 参考 前言 多模态CLIP的推理部分代码简单试玩一下 致敬大佬的CLIP 论文链接 Learning Transferable Visual Models From Natural L
  • JS中的“&&”与“&”和“

    在JavaScript中 和 是逻辑运算符 和 是位运算符 四个运算符主要区别是运算方法不一样 1 JavaScript中的位运算符 运算方法 两个数值的个位分别相与 同时为1才得1 只要一个为0就为0 举个例子 31 2 结果为2 理由
  • python-报错

    报错 异常名称 描述 BaseException 所有异常的基类 SystemExit 解释器请求退出 KeyboardInterrupt 用户中断执行 通常是输入 C Exception 常规错误的基类 StopIteration 迭代器
  • JS 统计字符

    var str id content value replace r n g n var length t str length
  • 使用Koa2进行Web开发(一)

    这篇文章是我正在进行写作的 新时期的Node js入门 的一部分 Connect Express与Koa 为了更好地理解后面的内容 首先需要梳理一下Node中Web框架的发展历程 Connect 在connect官方网站提供的定义是 Con
  • Python实现贝叶斯优化器(Bayes_opt)优化卷积神经网络回归模型(CNN回归算法)项目实战

    说明 这是一个机器学习实战项目 附带数据 代码 文档 视频讲解 如需数据 代码 文档 视频讲解可以直接到文章最后获取 1 项目背景 贝叶斯优化器 BayesianOptimization 是一种黑盒子优化器 用来寻找最优参数 贝叶斯优化器是
  • 从枚举类型的ordinal()方法说起

    文章背景 本周有一个开发任务涉及到了枚举类型的修改 需要对枚举类型新增一项 在新增的时候我没有加在已有项的最后面 而是在中间随便找了个位置 其实也不是很随便 我是根据语义关联性觉得放在某一项后面比较合适 没想到的是 我的无心之举经造成了大
  • 安装centos 8

    安装centos 8 首先下载centos 8镜像 地址 http mirrors aliyun com centos 8 isos x86 64 这里选择了boot版本 boot版与完整版的区别是体积小 通过网络源安装 下载完成大概有70
  • Solidity与dapp开发学习记录4

    目录 函数修饰符进阶 Payable修饰符 运用 取款 Withdraws 运用 准备好设计僵尸对战 随机数 Random Numbers 通过keccak256生成随机数 此方法容易受到不诚实节点的攻击 如何在以太坊中安全地生成随机数 运
  • BASE64Encoder及BASE64Decoder的正确用法

    一直以来Base64的加密解密都是使用sun misc包下的BASE64Encoder及BASE64Decoder的sun misc BASE64Encoder BASE64Decoder类 这人个类是sun公司的内部方法 并没有在java
  • 腾讯云搭建邮局

    想在个人电脑上面搭个邮局临时用一下 没有想到宽带的端口全部被封了 25 110 143本来以为不能发就算了 收也不行了 完全没有办法用 还好腾讯云有按月开通的 先开通一个月试试 花了三十块 开了一个 轻量应用服务器 这里安全方面 没有什么要
  • 系统架构设计高级技能 · 层次式架构设计理论与实践

    现在的一切都是为将来的梦想编织翅膀 让梦想在现实中展翅高飞 Now everything is for the future of dream weaving wings let the dream fly in reality 点击进入系
  • dlopen和 dlsym的使用方式

    背景 为了把不同的逻辑解耦 一般会把各个业务封装成动态库 然后主逻辑去调用各个动态库 这里有个问题是 为什么以前我们都是通过include第三方的头文件 然后通过连接器链接动态库实现 现在却要利用dlopen呢 考虑以下情况 比如我们要用c
  • Spring Data - Spring Data JPA 提供的各种Repository接口

    最近博主越来越懒了 深知这样不行 还是决定努力奋斗 如此一来 就有了一下一波复习 演示代码都基于Spring Boot Spring Data JPA 传送门 博主的测试代码 什么是Spring Data JPA Spring Data 是