小编Cep*_*pr0的帖子

允许docker容器连接到本地/主机postgres数据库

我最近一直在使用Docker和QGIS,并按照本教程中的说明安装了容器.

一切都很好,虽然我无法连接到包含我所有GIS数据的localhost postgres数据库.我认为这是因为我的postgres数据库没有配置为接受远程连接,并且已经使用本文中的说明编辑了postgres conf文件以允许远程连接.

当我尝试连接到我在Docker中运行QGIS的数据库时,我仍然收到一条错误消息:无法连接到服务器:Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections to port 5433? postgres服务器正在运行,我编辑了我的pg_hba.conf文件以允许来自一系列的连接IP地址(172.17.0.0/32).我以前查询过使用的docker容器docker ps的IP地址,虽然IP地址发生了变化,但到目前为止一直在172.17.0.x范围内.

有什么想法我无法连接到这个数据库?我想象的可能很简单!

我正在运行Ubuntu 14.04; Postgres 9.3

ubuntu qgis docker postgresql-9.3

105
推荐指数
10
解决办法
9万
查看次数

Spring Data REST - 自v.2.5.7起,PUT请求无法正常工作

从版本2.5.7开始, Spring Data REST无法正确执行PUT请求以更新具有关联资源的资源.与按预期工作的PATCH请求不同!

例如,Person与多对一关联Addres.如果我们使用SDR v.2.5.6(Spring Boot v.1.4.3)执行PUT请求,那么一切正常.但是,如果我们切换到2.5.7版(即Spring Boot v.1.4.4),那么我们会收到一个错误:

无法构造Address的实例:没有String-argument构造函数/工厂方法从String值反序列化

其他类型的关联也会发生同样的情况,例如一对多(单向和双向) - 请参阅我的示例应用程序代码和测试.

从1.4.4开始,Spring Boot的所有版本都存在此问题,包括最新的稳定1.5.6版本,以及最新的2.0.0-SNAPSHOT版本!

要解决这种情况,我们可以切换到SDR v.2.5.6(Spring Boot v.1.4.3).

我准备了一个邮递员的请求集合,以帮助您解决问题:SDR PUT问题

更新2017-08-14

我找到了如何避免错误Can not construct instance of Address: no String-argument constructor/factory method to deserialize from String value.

由于我在这个项目中使用Lombok,因此有必要告诉Lombok禁止@ConstructorProperties生成的构造函数中使用注释 .所以我lombok.anyConstructor.suppressConstructorProperties=true在'lombok.config'文件中设置,错误消失了.

不幸的是,发现了一个新问题 - PUT请求根本不更新关联的对象!

以下示例说明了这一点.当我们尝试通过将他的地址从addresses/1(初始值)更改为addresses/2- 来更新Person时,它仍然是相同的:addresses/1!与之前的问题一样,自1.4.4以来,这一问题出现在Spring Boot的 …

java rest put spring-data-rest spring-boot

13
推荐指数
1
解决办法
3121
查看次数

如何在Spring Data REST项目中使用DTO?

Spring Data REST自动仅公开域对象.但大多数情况下,我们必须处理数据传输对象.那么如何以SDR方式做到这一点?

spring projection dto spring-data-rest

11
推荐指数
1
解决办法
1万
查看次数

Spring DATA JPA 如何编写使用字段的常量值来获取数据的方法

嗨,我正在使用 Spring Data JPA 并希望使用功能从方法名称生成查询。我在 DB 中有一个活动字段,它只有值 0 和 1。我想获取所有活动值为 1 的数据。这是一个常量值,所以我不想将此值作为方法参数传递。

请建议相同的方法是什么。

例子:

我有一个实体 EmailRef

public class EmailRef {

    /* other vareialbe */

    @Column(name="is_active") /* this is the field which value is 0 and 1 in DB*/
    private Integer active;

    /* setter getter method */       
}
Run Code Online (Sandbox Code Playgroud)

这是我要编写方法的存储库,该方法将获取 active 为 1 的所有数据;

public interface EmailRefRepositry extends JpaRepository<EmailRef, Long> {          

    @Query("select * from email_reference where is_active=1") /* this is the query I want to convert into method*/
    List<EmailRef> findByActive(); /*I want …
Run Code Online (Sandbox Code Playgroud)

spring spring-data-jpa

6
推荐指数
1
解决办法
2928
查看次数

Spring Data Rest - 无法更新(PATCH)引用另一个实体的子实体列表

我有三个实体:父级、其子级和一些参考:

家长

@Entity
@Table(name = "parents")
public class Parent extends LongId {

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

    @NonNull
    @OneToMany(cascade = MERGE)
    private List<Child> children = new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)

孩子

@Entity
@Table(name = "children")
public class Child extends LongId {

    @NonNull
    @Column(nullable = false)
    private String name;

    @NonNull
    @ManyToOne(optional = false)
    private Reference reference;
}
Run Code Online (Sandbox Code Playgroud)

参考

@Entity
@Table(name = "references")
public class Reference extends LongId {

    @NotEmpty
    @Column(nullable = false)
    @Length(min = 3)
    @NonNull
    private String description; …
Run Code Online (Sandbox Code Playgroud)

java spring-data-rest

5
推荐指数
1
解决办法
2399
查看次数

如何在 Spring Boot 项目中使用 Log4jdbc 记录 SQL 查询及其参数和结果?

要查看发送到数据库的 SQL 查询,我们通常使用showSql参数:

spring.jpa.showSql=true
Run Code Online (Sandbox Code Playgroud)

它允许我们看到语句体而不是它的参数:

insert into master (id, version, name) values (null, ?, ?)
Run Code Online (Sandbox Code Playgroud)

尤其是我们没有看到查询的结果。

有没有办法在应用程序日志中查看 SQL 语句、其参数和结果?

java sql logging spring-data-jpa spring-boot

4
推荐指数
1
解决办法
3851
查看次数

加速 jsonb 对象数组中嵌套的键值的范围测试

假设我有下parents表:

create table parents (
  id       integer not null constraint parents_pkey primary key,
  name     text    not null,
  children jsonb   not null
);
Run Code Online (Sandbox Code Playgroud)

其中children有一个如下结构的json数组:

[
    {
        "name": "child1",
        "age": 10
    }, 
    {
        "name": "child2",
        "age": 12
    } 
]
Run Code Online (Sandbox Code Playgroud)

例如,我需要找到所有有 10 岁到 12 岁孩子的父母。

我创建以下查询:

select distinct
  p.*
from
  parents p, jsonb_array_elements(p.children) c
where
  (c->>'age')::int between 10 and 12;
Run Code Online (Sandbox Code Playgroud)

当表parents很大时(例如 1M 条记录),它工作得很好,但速度很慢。我尝试在children字段上使用“杜松子酒”索引,但这没有帮助。

那么有没有办法加快此类查询的速度呢?或者也许还有另一种解决方案可以对嵌套 json 数组中的字段进行查询/索引?

查询计划

Unique  (cost=1793091.18..1803091.18 …
Run Code Online (Sandbox Code Playgroud)

sql arrays postgresql json jsonb

4
推荐指数
1
解决办法
2124
查看次数

如何使用 Querydsl 和 Spring Data 轻松实现“REST API 查询语言”来过滤实体?

如何使用Spring Data轻松实现一种“REST API 查询语言”来过滤实体?

例如,对于以下Person实体:

@Data
@Entity
public class Person {

  @Id
  @GeneratedValue
  private Long id;

  private LocalDate dob; // date of birth

  private String name;

  @Formula("timestampdiff('year', dob, now())")
  private Integer age;

  public Person(String name, LocalDate dob) {
    this.name = name;
    this.dob = dob;
  }
}
Run Code Online (Sandbox Code Playgroud)

我想通过这样的请求获取其数据:

GET /people?name=jo&age=18&page=1&sort=name,desc
Run Code Online (Sandbox Code Playgroud)

即:'获取所有name包含“jo”(不区分大小写)且age等于 18 的人的第一页,按name降序排序'。

rest spring querydsl spring-data spring-boot

4
推荐指数
1
解决办法
6870
查看次数

如何基于HTTP方法进行Zuul动态路由,并通过'serviceId'解析目标主机?

如何基于HTTP方法(GET/POST/PUT ...)进行Zuul动态路由?例如,当您需要将POST请求路由到不同的主机而不是' zuul.routes.* '中描述的默认主机时 ...

zuul:
  routes:
    first-service:
      path: /first/**
      serviceId: first-service
      stripPrefix: false

    second-service:
      path: /second/**
      serviceId: second-service
      stripPrefix: false
Run Code Online (Sandbox Code Playgroud)

即当我们请求' GET/first '时,Zuul将请求路由到' first-service ',但如果我们请求' POST/first ',则Zuul将请求路由到' second-service '.

spring spring-cloud netflix-zuul spring-cloud-netflix

3
推荐指数
1
解决办法
4315
查看次数

findAll 与 findAll 与投影中的 CrudRepository 发生冲突

登录

@ApiModel
@Entity
public class Login {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private LocalDateTime loginDateTime;

    /** Other fields ***/
} 
Run Code Online (Sandbox Code Playgroud)

仅登录日期

interface LoginDateOnly {

    @Value("#{target.loginDateTime.toLocalDate()}")
    LocalDate getDateFromLoginDateTime();

}
Run Code Online (Sandbox Code Playgroud)

登录库

@RepositoryRestResource(collectionResourceRel = "login", path = "login")
public interface LoginRepository extends PagingAndSortingRepository<Login, Long> {

    Collection<LoginDateOnly> findAll();

    /** Other query methods **/
}
Run Code Online (Sandbox Code Playgroud)

我只是想获得所有我的登录记录,与LOCALDATE的部分我的loginDateTime选择使用/投射http://host/api/login。但目前我遇到了与 CrudRepository 的 findAll() 的冲突。如何使用投影尽可能地解决这个问题。我正在将 @Query 和 @NamedQuery 作为最后的手段。

jpa spring-data-jpa spring-data-rest

2
推荐指数
1
解决办法
1647
查看次数