JPA访问数据库的几种方式

本文为原创,转载请注明出处:https://www.cnblogs.com/supiaopiao/p/10901793.html

1. Repository

1.1. 通过方法名称直接生成查询

Keyword

Sample

JPQL snippet

And

findByLastnameAndFirstname

… where x.lastname = ?1 and x.firstname = ?2

Or

findByLastnameOrFirstname

… where x.lastname = ?1 or x.firstname = ?2

Is,Equals

findByFirstname,findByFirstnameIs,findByFirstnameEquals

… where x.firstname = ?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,NotNull

findByAge(Is)NotNull

… where x.age not null

Like

findByFirstnameLike

… where x.firstname like ?1

NotLike

findByFirstnameNotLike

… where x.firstname not like ?1

StartingWith

findByFirstnameStartingWith

… where x.firstname like ?1(parameter bound with appended %)

EndingWith

findByFirstnameEndingWith

… where x.firstname like ?1(parameter bound with prepended %)

Containing

findByFirstnameContaining

… where x.firstname like ?1(parameter bound wrapped in %)

OrderBy

findByAgeOrderByLastnameDesc

… where x.age = ?1 order by x.lastname desc

Not

findByLastnameNot

… where x.lastname <> ?1

In

findByAgeIn(Collection<Age> ages)

… where x.age in ?1

NotIn

findByAgeNotIn(Collection<Age> ages)

… where x.age not in ?1

True

findByActiveTrue()

… where x.active = true

False

findByActiveFalse()

… where x.active = false

IgnoreCase

findByFirstnameIgnoreCase

… where UPPER(x.firstame) = UPPER(?1)

In和NotIn可以使用任何Collection的子类作为参数。

案例:

public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {
    Page<User> findByName(String name);

List<User> findByNameAndPhone(String name, String phone);

User findUserById(Integer id);

void deleteByIdIn(List<Integer> idList);
}

1.2. @Query注解

可以使用Spring Data JPA 的@Query注解将查询绑定到repository的函数上。

备注:注解到查询方法上的@Query执行顺序优先于下文中的@NamedQuery。

1.2.1. HQL

注意:使用“:属性名”的时候,最好在接口上加上@Param注解,否则会报类似如下异常:

public interface UserRepository extends JpaRepository<User, Integer>{
@Query(value = "SELECT u FROM User u WHERE u.name like %?1%")//不加nativeQuery应使用HQL
List<User> findTable2(String name);

@Query(value = "SELECT u FROM User u WHERE u.name like %:name% and u.sex = :sex")
    List<User> findTable3(@Param("name") String name, @Param("sex")String sex);
}

1.2.2. 原生SQL

(1)@Query注解通过设置nativeQuery标识支持执行原生SQL查询语句

public interface UserRepository extends JpaRepository<User, Integer>{
@Query(value = "SELECT * FROM user WHERE name like %?1%", nativeQuery = true)
List<User> findTable1(String name);

}

(2)Spring Data JPA通过原生SQL进行查询时,不能满足Page条件进行分页,所以可以通过countQuery标识执行count查询实现Page分页:

public interface UserRepository extends JpaRepository<User, Integer>{
   @Query(value = "SELECT * FROM user WHERE name like %?1%",
            countQuery = "SELECT count(*) FROM user WHERE name like %?1%",
            nativeQuery = true)
    Page<User> findTable3(String name, Pageable pageable);
}

1.3. @Modifying注解

  1. 在@Query注解中编写JPQL实现DELETE和UPDATE操作的时候必须加上@Modifying注解,以通知Spring Data这是一个DELETE或UPDATE操作。
  2. UPDATE或者DELETE操作需要使用事务,此时需要定义Service层,在Service层的方法上添加事务操作@Transactional。
  3. Modifying查询语句中能用于void/int/Integer 返回类型,不能用于其他类型
  4. 注意JPQL不支持INSERT操作。

代码示例:

public interface UserRepository extends JpaRepository<User, Integer>{

@Modifying
    @Query("UPDATE User u SET u.name = :name WHERE u.id = :id")
    void updateTable(@Param("name") String name, @Param("id")Integer id);

@Modifying
@Query("delete from User u WHERE u.id in :idList")
void deleteByIds(@Param("idList")List<Integer> idList);

}

2. 实体类中定义,在Repository中使用

2.1. 命名查询@NamedQuery

使用@NamedQuery为实体创建查询适用于定义少量查询。@NamedQuery需要声明在实体类上,@NamedQuery可以实现命名HQL查询(或JPQL)。

备注:注解到查询方法上的@Query(上文中)执行顺序优先于@NamedQuery。

@Entity
@NamedQuery(name = "Two.selectBySex",query = "select t from Two t where t.sex = ?1 group by id")
public class Two {
    @Id

@GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id",nullable=false)
    private Integer id;

@Column(name="name",nullable=false)
    private String name;

@Column(name="sex",nullable=false)
    private String sex;

Set、get方法省略
}

Repository层代码展示:

public interface TwoRepository extends JpaRepository<Two, Integer>{
    //实体类上通过@NamedQuery注解实现查询
    List<Two> selectBySex(String sex);
}

Spring Data处理这些方法对命名查询的调用,以实体类名称开始,后接方法名,以点作连接符。所以NameQuery定义在实体上,而不是定义在方法上。

2.2. 个实体类中有多个命名查询@NamedQueries

上面我们演示了命名查询@NamedQuery的写法,当然JPA也支持多个@NamedQuery,那就是@NamedQueries

@Entity
@NamedQueries(value = {
        @NamedQuery(
                name = "Two.selectBySex",
                query = "select t from Two t where t.sex = ?1 group by id"),
        @NamedQuery(
                name = "Two.findUserByPrimaryKey",
                query = "select t from Two t where t.id = :id")
})

public class Two {
    @Id

@GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id",nullable=false)
    private Integer id;

@Column(name="name",nullable=false)
    private String name;

@Column(name="sex",nullable=false)
    private String sex;

Set、get方法省略
}

Repository层代码展示:

public interface TwoRepository extends JpaRepository<Two, Integer>{
    //实体类上通过@NamedQuery注解实现查询
    List<Two> selectBySex(String sex);
    Two findUserByPrimaryKey(@Param("id") Integer id);
}

Spring Data处理这些方法对命名查询的调用,以实体类名称开始,后接方法名,以点作连接符。所以NameQuery定义在实体上,而不是定义在方法上。

2.3. 命名原生sql查询@NamedNativeQuery

@NamedNativeQuery可以实现命名原生sql查询

@Entity
@NamedNativeQuery(name = "Three.selectBySex", query = "select * from three where sex = ?1 group by id", resultClass = Three.class)
@Table(name="three")
public class Three {
    @Id

@GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id",nullable=false)
    private Integer id;

@Column(name="name",nullable=false)
    private String name;

@Column(name="sex",nullable=false)
    private String sex;

Set、get方法省略
}

Repository层代码展示:

public interface ThreeRepository extends JpaRepository<Three, Integer>{
    //实体类上通过@NamedNativeQuery注解实现查询
    List<Three> selectBySex(String sex);
}

2.4. 个实体类中有多个命名查询@NamedNativeQueries

上面我们演示了命名查询@NamedNativeQuery的写法,当然JPA也支持多个@NamedNativeQuery,那就是@NamedNativeQueries

@Entity
@NamedNativeQueries(value = {
        @NamedNativeQuery(
                name = "Three.selectBySex",
                query = "select * from three where sex = ?1 group by id",
                resultClass = Three.class),
        @NamedNativeQuery(
                name = "Three.findUserByPrimaryKey",
                query = "select * from three where id = :id",
                resultClass = Three.class)//resutlClass用来指定实体类,resutlSetMapping用来指定映射的名称
})
@Table(name="three")
public class Three {
    @Id

@GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id",nullable=false)
    private Integer id;

@Column(name="name",nullable=false)
    private String name;

@Column(name="sex",nullable=false)
    private String sex;

Set、get方法省略
}

Repository层代码展示:

public interface ThreeRepository extends JpaRepository<Three, Integer>{
    //实体类上通过@NamedNativeQuery注解实现查询
    List<Three> selectBySex(String sex);
    Three findUserByPrimaryKey(@Param("id") Integer id);
}

3. 外部ORM文件中定义,在Repository中使用

3.1. 命名查询named-query

使用XML配置,向位于resources/META-INF文件夹下的orm.xml配置文件添加必要的<name-query/>元素。

resources/META-INF下orm.xml配置:

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
                                     http://xmlns.jcp.org/xml/ns/persistence/orm_2_0.xsd" version="2.1">

<!-- JPA Named Queries -->
    <named-query name="One.selectByName">
        <query>SELECT o FROM One o WHERE o.sex = ?1 group by id</query>
    </named-query>

<named-query name="One.findUserByPrimaryKey">
        <query>SELECT o FROM One o WHERE o.id = :id</query>
    </named-query>
</entity-mappings>

Repository层代码展示:

public interface OneRepository extends JpaRepository<One, Integer>{
    //1.1 XML定义 命名查询
    List<One> selectByName(String name);
    One findUserByPrimaryKey(@Param("id") Integer id);
}

3.2. 原生SQL查询named-native-query

使用XML配置,向位于resources/META-INF文件夹下的orm.xml配置文件添加必要的<named-native-query/>元素。

resources/META-INF下orm.xml配置:

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
                                     http://xmlns.jcp.org/xml/ns/persistence/orm_2_0.xsd" version="2.1">

<!-- JPA Named Native Queries -->
    <named-native-query name="One.selectByName1">
        <query>SELECT * FROM one WHERE sex = ?1 group by id</query>
    </named-native-query>

<!--result-class用来指定实体类,result-set-mapping用来指定映射的名称-->
    <named-native-query name="One.findUserByPrimaryKey1" result-class="cn.com.bmsoft.stormplan.basic.entity.One">
        <query>SELECT * FROM one WHERE id = :id</query>
    </named-native-query>
</entity-mappings>

Repository层代码展示:

package cn.com.bmsoft.stormplan.basic.dao;

import cn.com.bmsoft.stormplan.basic.entity.One;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface OneRepository extends JpaRepository<One, Integer>{
    //1.2 XML定义 原生sql查询 named-native-query
    List<One> selectByName1(String sex);
    One findUserByPrimaryKey1(@Param("id")Integer id);
}

4. SpEL表达式

从Spring Data JPA 1.4版本开始,支持在@Query定义的查询中使用SpEL模板表达式。在执行查询的时候,这些表达式通过一个事先定义好的变量集合求值。Spring Data JPA支持一个名为entityName的变量。它的用法是select x from #{#entityName} x。它会将域类型的entityName与给定repository关联起来。entityName按照如下方式处理:如果域类型在@Entity注解上设置了name属性,则使用该属性。否则直接使用域类型的类名。

下例演示了在定义带有查询方法和手工定义查询的repository接口时使用#{#entityName}表达式。

public interface UserRepository extends JpaRepository<User, Integer>{
    @Query(value = "SELECT u FROM #{#entityName} u WHERE u.name like %:name% and u.sex = :sex")
    List<User> findTable4(@Param("name") String name, @Param("sex")String sex);
}

SpEL表达式的好处:

参考网址:https://www.cnblogs.com/tilv37/p/6944182.html

5. Specifications动态构建查询

5.1. 参数介绍

  1. Predicate:单独每一条查询条件的详细描述

Predicate[]:多个查询条件的详细描述

  1. Root:查询哪个表
  2. CriteriaQuery:查询哪些字段,排序是什么
  3. CriteriaBuilder:字段之间是什么关系,如何生成一个查询条件,每个查询条件都是什么方式

(1)CriteriaQuery<T>:主要是构建查询条件

distinct、select、where、groupby、having、orderby等

(2)CriteriaBuilder:主要是用来进行一些函数操作

① and

② or

③ between

④ lt(小于)、le(小于等于)、gt(大于)、ge(大于等于)

⑤ not(非)等...

5.2. 代码案例

//where empname like ?  group by wages

@Override
public Page<EmployeeEntity> search1(EmployeeVO employeeVO) throws Exception {
   Pageable pageable = PageRequest.of(employeeVO.getPage() - 1, employeeVO.getSize(), Sort.Direction.ASC,"empid");
   Specification<EmployeeEntity> specification = new Specification<EmployeeEntity>() {
      @Override
      public Predicate toPredicate(Root<EmployeeEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
         List<Predicate> list = new ArrayList<>(10);
         if(StringUtils.isNotBlank(employeeVO.getEmpname())){
            list.add(cb.and(
                  cb.like(root.get("empname").as(String.class),"%"+ employeeVO.getEmpname()+"%")
            ));
         }
         Expression<BigDecimal> wages = root.get("wages").as(BigDecimal.class);
         return criteriaQuery.where(list.toArray(new Predicate[list.size()])).groupBy(wages).getRestriction();
         //where empname like ?  group by wages
      }
   };
   Page<EmployeeEntity> stuPage = employeeRepository.findAll(specification, pageable);
   return stuPage;
}

//where empname like ? or deptid=?

@Override
public Page<EmployeeEntity> search2(EmployeeVO employeeVO) throws Exception {
   Pageable pageable = PageRequest.of(employeeVO.getPage() - 1, employeeVO.getSize(), Sort.Direction.ASC,"empid");
   Specification<EmployeeEntity> specification = new Specification<EmployeeEntity>() {
      @Override
      public Predicate toPredicate(Root<EmployeeEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
         List<Predicate> list = new ArrayList<>(10);
         if(StringUtils.isNotBlank(employeeVO.getEmpname()) && null != employeeVO.getDeptid()){
            list.add(cb.or(
                  cb.like(root.get("empname").as(String.class),"%"+ employeeVO.getEmpname()+"%"),
                  cb.equal(root.get("deptid").as(Integer.class), employeeVO.getDeptid())
            ));
         }//where empname like ? or deptid=?
         return criteriaQuery.where(list.toArray(new Predicate[list.size()])).getRestriction();
      }
   };
   Page<EmployeeEntity> stuPage = employeeRepository.findAll(specification, pageable);
   return stuPage;
}

//where wages < ?

@Override
public Page<EmployeeEntity> search3(EmployeeVO employeeVO) throws Exception {
   Pageable pageable = PageRequest.of(employeeVO.getPage() - 1, employeeVO.getSize(), Sort.Direction.ASC,"empid");
   Specification<EmployeeEntity> specification = new Specification<EmployeeEntity>() {
      @Override
      public Predicate toPredicate(Root<EmployeeEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
         Predicate wages = cb.lt(root.get("wages").as(BigDecimal.class), employeeVO.getWages());
         return criteriaQuery.where(wages).getRestriction();
      }
   };//where wages < ?
   Page<EmployeeEntity> stuPage = employeeRepository.findAll(specification, pageable);
   return stuPage;
}

//where wages between ? and ?

@Override
public Page<EmployeeEntity> search4(EmployeeVO employeeVO){
   Pageable pageable = PageRequest.of(employeeVO.getPage() - 1, employeeVO.getSize(), Sort.Direction.ASC,"empid");
   Specification<EmployeeEntity> specification = new Specification<EmployeeEntity>() {
      @Override
      public Predicate toPredicate(Root<EmployeeEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
         Predicate wages = cb.between(root.get("wages").as(BigDecimal.class), employeeVO.getMinWages(), employeeVO.getMaxWages());
         return criteriaQuery.where(wages).getRestriction();
      }
   };//where wages between ? and ?
   Page<EmployeeEntity> stuPage = employeeRepository.findAll(specification, pageable);
   return stuPage;
}

6. JPA Join联表查询

构建表关系如下:

实体类代码展示:

@Entity
@Table(name="a")
public class AEntity {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="aid",nullable=false)
    private Integer aid;

@Column(name="aname",nullable=false)
    private String aname;

省略set、get方法
}

@Entity
@Table(name="b")
public class BEntity {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="bid",nullable=false)
    private Integer bid;

@Column(name="bname",nullable=false)
    private String bname;

@OneToOne(cascade=CascadeType.ALL) //B是关系的维护端,当删除 b,会级联删除 a
    @JoinColumn(name = "aid", referencedColumnName = "aid") //name:关联id,referencedColumnName:A表id
    private AEntity aEntity;//A表

省略set、get方法
}

@Entity
@Table(name="c")
public class CEntity {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="cid",nullable=false)
    private Integer cid;

@Column(name="cname",nullable=false)
    private String cname;
    省略set、get方法

}

@Entity
@Table(name="d")
public class DEntity {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="did",nullable=false)
    private Integer did;

@Column(name="dname",nullable=false)
    private String dname;

//可选属性optional=false,表示B不能为空。删除d,不影响b   @ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH},optional=false)
    @JoinColumn(name = "bid", referencedColumnName = "bid")//name:关联id,referencedColumnName:B表id
    private BEntity bEntity;//B表

    //可选属性optional=false,表示C不能为空。删除d,不影响c
@ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH},optional=false)
    @JoinColumn(name = "cid", referencedColumnName = "cid")//name:关联id,referencedColumnName:C表id
    @JsonBackReference
    private CEntity cEntity;//C表
    省略set、get方法
}

Service层代码展示:

@Override
public Page<DEntity> search(DVO dVO) {
    Pageable pageable = PageRequest.of(dVO.getPage() - 1, dVO.getSize(), Sort.Direction.ASC,"did");
    Specification<DEntity> specification = new Specification<DEntity>() {
        @Override
        public Predicate toPredicate(Root<DEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
            List<Predicate> list = new ArrayList<>(10);

//A:B:D 1:1:n  根据D的实体类查询aname
            if (StringUtils.isNotBlank(dVO.getAname())) {
                Join<AEntity,DEntity> ajoin = root.join("bEntity",JoinType.LEFT);
                list.add(cb.like(ajoin.get("aEntity").get("aname").as(String.class),"%"+ dVO.getAname()+"%"));
            }//select * from d left join b on d.bid=b.bid left join a on b.aid=a.aid where a.aname like "%xxx%"

            //B:D 1:n  根据D的实体类查询bname
            if (StringUtils.isNotBlank(dVO.getBname())) {
                Join<BEntity,DEntity> ajoin = root.join("bEntity",JoinType.LEFT);
   list.add(cb.like(ajoin.get("bname").as(String.class),"%"+ dVO.getBname()+"%"));
}//select * from d left join b on d.bid=b.bid where b.bname like "%xxx%"

            //C:D 1:n  根据D的实体类查询cname
            if (StringUtils.isNotBlank(dVO.getCname())) {
                Join<BEntity,DEntity> ajoin = root.join("cEntity",JoinType.LEFT);
                list.add(cb.like(ajoin.get("cname").as(String.class),"%"+ dVO.getCname()+"%"));
            }//select * from d left join c on d.cid=c.cid where c.cname like "%xxx%"

            return criteriaQuery.where(list.toArray(new Predicate[list.size()])).getRestriction();
        }
    };
    Page<DEntity> stuPage = dRepository.findAll(specification, pageable);
    return stuPage;
}

JPA访问数据库的几种方式的更多相关文章

  1. Spring框架访问数据库的两种方式的小案例

    1.1 以Xml的方式访问数据库的案例 要以xml的方式访问数据库需要用到JdbcTemplate ,因为 JdbcTemplate(jdbc的模板对象)在Spring 中提供了一个可以操作数据库的对 ...

  2. .NET访问数据库的两种方式(C#语言)

    一.直接使用C#操作数据库的类库ADO.NETADO.NET使用Connection对象来连接数据库,使用Command或DataAdapter 对象来执行SQL语句,并将执行的结果返回给DataRe ...

  3. Asp.net 访问数据库的几种方式

    ASP.NET中连接数据库的各种方法 连接SQL数据库的方法:(一).在Web.Config中创建连接字符串:1.<add name="ConnectionString" c ...

  4. .Net 中读写Oracle数据库常用两种方式

    .net中连接Oracle 的两种方式:OracleClient,OleDb转载 2015年04月24日 00:00:24 10820.Net 中读写Oracle数据库常用两种方式:OracleCli ...

  5. plsql 连接oracle数据库的2种方式

      plsql 连接oracle数据库的2种方式 CreationTime--2018年8月10日09点50分 Author:Marydon 方式一:配置tnsnames.ora 该文件在instan ...

  6. Code First03---CodeFirst根据配置同步到数据库的三种方式

    上一节我们说到使用Fluent API对实体的配置,但是有一个问题了,在业务中我们可以用到的实体很多,那是不是每个都需要这样去配置,这样就造成我们重写的OnModelCreating方法很庞大了.所以 ...

  7. springboot学习-jdbc操作数据库--yml注意事项--controller接受参数以及参数校验--异常统一管理以及aop的使用---整合mybatis---swagger2构建api文档---jpa访问数据库及page进行分页---整合redis---定时任务

    springboot学习-jdbc操作数据库--yml注意事项--controller接受参数以及参数校验-- 异常统一管理以及aop的使用---整合mybatis---swagger2构建api文档 ...

  8. Android开发之使用sqlite3工具操作数据库的两种方式

    使用 sqlite3 工具操作数据库的两种方式 请尊重他人的劳动成果,转载请注明出处:Android开发之使用sqlite3工具操作数据库的两种方式 http://blog.csdn.net/feng ...

  9. Servlet访问路径的两种方式、Servlet生命周期特点、计算服务启动后的访问次数、Get请求、Post请求

    Servlet访问路径的两种方式: 1:注解 即在Servlet里写一个@WebServlet @WebServlet("/myServlet") 2:配置web.xml < ...

随机推荐

  1. 13 Zabbix4.4.1系统告警“More than 75% used in the configuration cache”

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 13 Zabbix4.4.1系统告警“More than 75% used in the conf ...

  2. DOS批处理中%~dp0等扩充变量语法详解

    有时候我们看到别人使用%~dp0 ~是扩展的意思,相当于把一个相对路径转换绝对路径%0代指批处理文件自身%1表示批处理文件命令行接收到的第一个参数,%2表示第二个,以此类推%~d0 是指批处理所在的盘 ...

  3. maven项目编译报错:Type Dynamic Web Module 3.0 requires Java 1.6 or newer.

    在maven的pom.xml文件中增加: <build>   <plugins>     <plugin>         <groupId>org.a ...

  4. HihoCoder1076 与链(数位DP)

    时间限制:24000ms 单点时限:3000ms 内存限制:256MB 描述 给定 n 和 k.计算有多少长度为 k 的数组 a1, a2, ..., ak,(0≤ai) 满足: a1 + a2 +  ...

  5. k8sReplicaSet控制器

    一.ReplicaSet概述 简称RS,是pod控制器类型的一种实现,用于确保由其管控的pod对象副本数在任一时刻都能精确满足期望的数量.ReplicaSet控制器资源启动后会查找集群中匹配其标签选择 ...

  6. python1-集合、函数(全局变量与局部变量)

    集合(set) # s=set('hello')# print(s)## s=set(['alex','alex','sb'])# print(s) # s={1,2,3,4,5,6} #添加# s. ...

  7. 【leetcode】1250. Check If It Is a Good Array

    题目如下: Given an array nums of positive integers. Your task is to select some subset of nums, multiply ...

  8. 使用oracle Sqlplus中上下键出现乱码的问题

    安装rlwrap,前提是安装readline和readline-devel yum list | grep readlineyum install -y readline.x86_64 readlin ...

  9. yum 源的搭建

    repos和epel的关系 https://blog.csdn.net/fantaxy025025/article/details/84918199 配置阿里云的yum源 https://www.cn ...

  10. CentOS查看和修改PATH环境变量的方法

    查看PATH:echo $PATH以添加mongodb server为列修改方法一:export PATH=/usr/local/mongodb/bin:$PATH//配置完后可以通过echo $PA ...