RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-324406

Blacit's questions

Martin Hope
Blacit
Asked: 2020-10-07 18:18:59 +0000 UTC

如何更改junit的版本

  • 0

整个问题是如何更改 Junit 版本?当我开始编写测试时,IDEA 询问我想使用哪一个。我当时注意到JUnit4,但我想尝试版本5。我是否正确理解为此我只需要更改版本 5 中使用的注释就可以了?不需要采取进一步行动。在 Pom.xml 我有这些依赖项:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-06 01:36:18 +0000 UTC

如何使用模拟测试日期

  • 0

我正在编写代码来测试一个方法,它需要参数:Long、LocalDate、LocalDate。如何查看日期?我想接受任何日期。

Mockito.verify(contractService, Mockito.times(1))
     .findAllByDate(
   ArgumentMatchers.anyLong(),
   ArgumentMatchers.anyLocalDate(),
   ArgumentMatchers.anyLocalDate()
);
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-06 01:12:59 +0000 UTC

表public.city中的id;找到串行 (Types#INTEGER),但期待 int8 (Types#BIGINT)

  • 0

为什么这条线id serial primary key,会导致这个错误?[id] in table [public.city]; found [serial (Types#INTEGER)], but expecting [int8 (Types#BIGINT)我不得不将 id 类型从 Long (bigint) 更改为 Integer。

我如何在 Liquibase 中使用创建表的示例:

create table users
(
    id serial primary key,
    email      varchar(255) not null
        constraint uk_6dotkott2kjsp8vw4d0m25fb7
            unique,
    first_name varchar(255) not null,
    last_name  varchar(255) not null,
    password   varchar(255) not null,
    role       varchar(255),
    status     varchar(255)
);

alter table users
    owner to root;
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-05 05:08:00 +0000 UTC

您不能将整数转换为日期

  • 1

我正在查询 postgresql 数据库。那么应该如何写日期以使其不计为整数呢?为什么它给我这个错误:

ERROR: ОШИБКА:  привести тип integer к date нельзя
LINE 3:   and start_date > cast(2020-03-12 AS date)

编码

select * from contract 
WHERE id = 6
  and start_date > CAST(2020-03-12 AS date)
  and start_date < cast(2020-03-19 as date) + interval '1' day
sql
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-04 19:28:46 +0000 UTC

',' 或 ')' 预期

  • 1

也许我什么都没看到,但据我所知,我没有错过任何地方的“;”。和 ”)”。在第一个和第二个 LocalDate 之后突出显示。

public List<Contract> findAllByDate(LocalDate startDate, LocalDate endDate) {
        return contractRepository.findAllByDate(LocalDate startDate, LocalDate endDate);
    }

这是我们调用的方法,它没有突出显示:

@Query(value = "select * from contract WHERE visit_date > :startDate and visit_date < cast(:endDay as date) + interval '1' day", nativeQuery = true)
    List<Contract> findAllByDate(@Param("startDay") LocalDate startDate, @Param("endDay") LocalDate endDay);}
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-04 04:44:20 +0000 UTC

读取迁移文件时出错:类路径资源 [db/changelogs/db.changelog-master.xml] 无法解析为 URL,因为它不存在

  • 0

我不明白他为什么不喜欢这条路,一切都拼写正确。

在此处输入图像描述

应用程序属性:

spring.jpa.hibernate.ddl-auto=validate
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml

liquibase.properties

classpath=
changeLogFile= db/changelog/db.changelog-master.xml
url= jdbc:postgresql://localhost:5432/new
username= root
password= 123
driver= org.postgresql.Driver

pom.xml org.liquibase liquibase-maven-plugin 3.6.3

db.changelog-master.xml

<changeSet id="0" author="blacit">
        <tagDatabase tag="db_init"/>
    </changeSet>

    <include file="v-1.0/db.changelog-v.1.0.xml" relativeToChangelogFile="true"/>

    <changeSet id="7" author="blacit">
        <tagDatabase tag="v.1.0"/>
    </changeSet>
                    <propertyFile>${project.basedir}/src/main/resources/liquibase.properties</propertyFile>
                </configuration>
            </plugin>


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: liquibase.exception.SetupException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at task.homerent.Application.main(Application.java:34) ~[classes/:na]
Caused by: liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: liquibase.exception.SetupException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:217) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:190) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:179) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314) ~[liquibase-core-3.8.0.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    ... 18 common frames omitted
Caused by: liquibase.exception.SetupException: liquibase.exception.SetupException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:359) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:308) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:23) ~[liquibase-core-3.8.0.jar:na]
    ... 25 common frames omitted
Caused by: liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:568) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:351) ~[liquibase-core-3.8.0.jar:na]
    ... 27 common frames omitted
Caused by: liquibase.exception.SetupException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:359) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:308) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:23) ~[liquibase-core-3.8.0.jar:na]
    ... 29 common frames omitted
Caused by: liquibase.exception.ChangeLogParseException: Error Reading Migration File: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:118) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:568) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:351) ~[liquibase-core-3.8.0.jar:na]
    ... 31 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [db/changelog/v-1.0/01-changeset-users.xml] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.getResourcesAsStream(SpringLiquibase.java:613) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:186) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:71) ~[liquibase-core-3.8.0.jar:na]
    ... 34 common frames omitted
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-03 21:48:15 +0000 UTC

更改集类路径:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil 失败。错误:错误:“用户”关系已存在

  • 0

错误:Change Set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil failed. Error: ERROR: the “users” relationship already exists 。问题是我已经知道有一个USERS表,但是我有application.properties,spring.jpa.hibernate.ddl-auto=validate那为什么还会出现这个错误呢?也许我的 sql 查询是错误的?我正在使用 posgresql。

CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root;

链接到代码,如果没有用,那就删掉。

2020-10-03 18:10:31.010 ERROR 11936 --- [           main] liquibase.changelog.ChangeSet            : Change Set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil failed.  Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root]
2020-10-03 18:10:31.012  INFO 11936 --- [           main] l.lockservice.StandardLockService        : Successfully released change log lock
2020-10-03 18:10:31.014  WARN 11936 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil:
     Reason: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root]
2020-10-03 18:10:31.014  INFO 11936 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-10-03 18:10:31.026  INFO 11936 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-10-03 18:10:31.029  INFO 11936 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-10-03 18:10:31.038  INFO 11936 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-03 18:10:31.044 ERROR 11936 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil:
     Reason: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at task.homerent.Application.main(Application.java:34) ~[classes/:na]
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil:
     Reason: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:646) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:202) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:179) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314) ~[liquibase-core-3.8.0.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    ... 18 common frames omitted
Caused by: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
(
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
    email character varying(255) COLLATE pg_catalog."default" NOT NULL,
    first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    password character varying(255) COLLATE pg_catalog."default" NOT NULL,
    role character varying(255) COLLATE pg_catalog."default",
    status character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
)

    TABLESPACE pg_default;

ALTER TABLE public.users
    OWNER to root]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:402) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:59) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:131) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1273) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1255) ~[liquibase-core-3.8.0.jar:na]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:609) ~[liquibase-core-3.8.0.jar:na]
    ... 26 common frames omitted
Caused by: org.postgresql.util.PSQLException: ОШИБКА: отношение "users" уже существует
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284) ~[postgresql-42.2.16.jar:42.2.16]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:279) ~[postgresql-42.2.16.jar:42.2.16]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.1.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.1.jar:na]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:398) ~[liquibase-core-3.8.0.jar:na]
    ... 31 common frames omitted
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-03 01:35:41 +0000 UTC

显示互斥值

  • 1

有 2 个表:House 和 Contract。我想查询:需要将Contract表中的house_id与House表中的id进行比较。我需要查看不在合同表中的公寓。我的版本输出匹配值,如果合同中有这样的 id,那么它会在内部查找相同的值。并且除了id之外还显示相关信息。怎样才能纠正这一刻?

编码:

select contract.house_id, house.id FROM Contract
INNER JOIN house ON contract.house_id = house.id
sql
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-02 23:36:49 +0000 UTC

有条件的不正确工作

  • 0

该程序应该找出公寓是否在某个日期被预订,如果没有,那么我们预订它,如果是,则显示一条消息它已被预订。我的程序是如何工作的:

第一次运行:使用我们想要预订的信息发出 Post2020-03-12请求2020-03-19。程序保存。如果我们再提出一个完全相同的请求,程序会再次保存信息。

第二遍:我们发出一个 Post 请求,其中包含我们想要预订的2020-03-12信息2020-03-19。该程序写道,公寓已经被占用。我们提出了一个新的 Post-request,我们想预订2020-04-12by 2020-04-19,程序保存信息。如果我们再提出一个完全相同的请求,程序将再次保存。

查询是如何在数据库中实现的:我们在数据库Contract中搜索新的. 因此,可以找到一个有效的或丢失的,如果它丢失了,那么您可以创建一个新的。id Houseend_datestart_dateContractContract

因为我想在控制器中进行检查:如果请求没有返回任何内容,那么我们可以将新合同保存到数据库中,否则我们进入条件并保存它。

问题是什么:如何正确建立数据正确保存的条件?因为重复保存不应该在同一日期。

控制器:

@PostMapping("/rent")
@PreAuthorize("hasAuthority('user:write')")
public String homeRent(@RequestBody ContractDto contractDto) {
    List<Contract> con = contractService.findContractByHouseIdAndEndDateAfter(contractDto.getHouseId(), contractDto.getEndDate());
    if(con.isEmpty()) {
        Contract contract = new Contract();
        contract.setHouse(houseService.findById(contractDto.getHouseId()));
        contract.setUser(userService.findById(contractDto.getTenantId()));
        contract.setStartDate(contractDto.getStartDate());
        contract.setEndDate(contractDto.getEndDate());
        contractService.save(contract);
        return "Квартира забронирована";
    }
    return "Квартира занята";
}

回购

@Repository
public interface ContractRepository extends JpaRepository<Contract, Long> {
    List<Contract> findContractByHouseIdAndEndDateAfter(Long houseId, LocalDate from);
}
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-01 06:03:46 +0000 UTC

如何登录到postgresql数据库

  • 0

如何在数据库中实现事务,如日志记录?例如,用户登录并立即将其写入表中。

java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-10-01 02:22:29 +0000 UTC

值不存储在数据库中

  • 0

如果我发送值,为什么我的 id_house 和 id_tenant 为空?日期已正确保存。我如何询问谁租了哪间公寓。很可能我以某种方式处理不正确,因为在实体中我将它们列为类。一般来说,我不明白到底与什么有关。

我接受价值观:

@PostMapping("/rent")
    @PreAuthorize("hasAuthority('user:write')")
    public void homeRent(@RequestBody Contract contract) {
        contractRepository.save(contract);
    }

合同:

@Data
@Entity
@Table(name = "contract", schema = "public")
public class Contract {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

@ManyToOne
@JoinColumn(name = "id_house")
@ToString.Exclude
@EqualsAndHashCode.Exclude
@JsonIgnore
private House house;

@ManyToOne
@JoinColumn(name = "id_tenant")
@EqualsAndHashCode.Exclude
@ToString.Exclude
@JsonIgnore
private User user;

@Column(name = "end_date")
private LocalDate end_date;
@Column(name = "start_date")
private LocalDate start_date;
}

通过邮递员请求:

{
    "start_date" : "2020-03-12",
    "end_date" : "2020-03-19",
    "id_house" : 2,
    "id_tenant" : 3
}
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-30 04:40:11 +0000 UTC

为什么没有为用户设置角色

  • 0

我想为用户设置一个角色,现在他有TENANT,我想将其更改为LANDLORD。对于与 ENUM 值相关的其他人,它也不适用于我。我提出请求发布、获取、删除 - 一切都很好。

我通过邮递员提出请求,但没有任何变化,尽管请求在那里。不换角色的原因是什么?完整代码如果没有用,则删除。我还尝试只输出user.setRole();- 一切都解决了,它显示了当前的用户角色。

在properties集合update中,以前是validate

spring.jpa.hibernate.ddl-auto=update

这是方法:

@PutMapping("/{id}")
    @PreAuthorize("hasAuthority('user:write')")
    public void TenantAdd(@PathVariable(value = "id") Long id) {
        User user = userRepository.findById(id).orElseThrow();
        user.setRole(Role.LANDLORD);
    }
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-30 00:44:28 +0000 UTC

在特定日期预订公寓的逻辑

  • 1

任务:您需要检查一个人是否可以在给定日期预订公寓,如果可以,则将其保存在数据库中,如果不能,则不保存任何内容。我的代码版本结果是错误的,我完全不明白如何最好地实现这个过程,我什至没有任何想法。 代码。如果不需要答案,我会删除它。

@PostMapping("/rent")
@PreAuthorize("hasAuthority('user:write')")
public void homeRent(@RequestBody ContractDto contractDto) {
    Contract contract = new Contract();
    House house = houseRepository.findById(contractDto.getId_house()).orElseThrow();
    Set<Contract> temp = house.getContract();
    for(Contract s:temp) {
        System.out.println(s.getStart_date());
        if(s.getStart_date().equals("")) {
            System.out.println("null");
        }
    }
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 22:09:05 +0000 UTC

解析模板 [用户/注册] 时出错,模板可能不存在或可能无法被任何已配置的模板解析器访问

  • 0

邮递员回复有问题。注册用户时出现的错误。我知道重点是他正在寻找模板,但我怎么能告诉他不要这样做呢?我试着让方法什么都不返回,错误还是一样?

PS Front 注册不执行。

编码:

@PostMapping("/user/registration")
    public User registerNewUserAccount(@RequestBody UserDto accountDto) {
        User user = new User();
        user.setFirstName(accountDto.getFirst_name());
        user.setLastName(accountDto.getLast_name());
        user.setPassword(passwordEncoder.encode(accountDto.getPassword()));

        user.setEmail(accountDto.getEmail());
        Role role = Role.TENANT;
        user.setRole(role);
        Status status = Status.ACTIVE;
        user.setStatus(status);
        return userRepository.save(user);
    }

错误:

"status": 500,
    "error": "Internal Server Error",
    "message": "Error resolving template [user / registration], template might not exist or might not be accessible by any of the configured Template Resolvers",
    "path":"/user/registration"

完整代码

java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 21:17:52 +0000 UTC

如何不通过 ID 绑定多对多

  • 0

2 个实体 House 和 City 以及数据库的屏幕截图。现在我意识到我没有完全正确地连接它,因为当用户提出请求时,他需要输入城市的号码,而不是名称,这是不正确的。如何正确绑定,以便在发生请求时将城市名称添加到 House 并链接到 City?

城市

@Data
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Table(name = "city", schema = "public")
public class City {

@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@OneToMany(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST,
        CascadeType.REFRESH
}, mappedBy = "city")
@ToString.Exclude
@EqualsAndHashCode.Exclude
@JsonIgnore
private Set<House> house;

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

房子

@Data
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Table (name = "house", schema = "public")
public class House {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "city_id")
    private City city;

    @OneToMany(mappedBy = "house")
    private Set<Contract> contract;

    @Column(name = "id_landlord", nullable = false)
    private Long id_landlord;
    @Column(name = "outside", nullable = false)
    private String outside;
    @Column(name = "rooms", nullable = false)
    private Integer rooms;
    @Column(name = "price", nullable = false)
    private Double price;
    @Column(name = "description", nullable = false)
    private String description;
    @Enumerated(value = EnumType.STRING)
    @Column(name = "status")
    private Status status;
}

在此处输入图像描述

java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 20:04:37 +0000 UTC

如何搜索存储库?

  • 0

Роль默认情况下,用户有一个属性,TENANT在我们询问他的查询的帮助下LANDLORD,现在他将具有各种属性的公寓添加到表中HOUSE:描述、价格、city_id 等。该用户想删除他自己的状态LANDLORD,从我们的数据库中删除他的公寓,然后再次成为TENANT我的公寓,如果他有的话,将状态设为 INACTIVE?我只是明白如何为他分配一个角色,但我没有猜到如何找到属于他的公寓。出于某种原因,我的 id_landlord 搜索版本不起作用。附上一张房子和用户属性的照片。

代码片段如下所示:

@PutMapping("/{id}")
    @PreAuthorize("hasAuthority('landlord:write')")
    public void TenantPostAdd(@PathVariable(value = "id") Long id) {
        User user = userRepository.findById(id).orElseThrow();
        user.setRole(Role.TENANT);
        House house = houseRepository.findById_landlord(id); - не работает
        house.setStatus(Status.INACTIVELY);
    }

房子仓库:

@Repository
public interface HouseRepository extends JpaRepository<House, Long> {
    House findById_landlord(@Param("id_landlord") House house);
}

在此处输入图像描述

完整代码。

java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 18:36:24 +0000 UTC

如何显示一个实体的所有值

  • 0

如何显示所有 House 实体?我们有 House 和一个可以用来获取它们的存储库。我了解可以这样做:List<House> res = houseRepository.findAll();我怎样才能退回它们并撤回它们?我不明白你。

@GetMapping("/list")
    @PreAuthorize("hasAuthority('user:read')")
    public House userPostInfo() {
    List<House> res = houseRepository.findAll();
        return ??;
    }
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 07:15:45 +0000 UTC

无法从实体中检索数据

  • 0

无法将 House 实体中的公寓显示为整个列表并按 ID 单独显示。当我转到该页面时,它会给出一个错误,即无限循环

Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: task.homerent.model.House["city"]->task.homerent.model.City$HibernateProxy$ikPQOTJQ["house"])

链接到代码

这是控制器的样子:

HouseRestController


@GetMapping("/{id}")
    @PreAuthorize("hasAuthority('user:read')")
    public House userPostInfo(@PathVariable(value = "id") Long id) {
        Optional<House> house = houseRepository.findById(id);
        List<House> res = new ArrayList<>();
        house.ifPresent(res::add);

        return res.stream().filter(houses -> houses.getId().equals(id))
                .findFirst()
                .orElse(null);
    }
java
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 04:56:17 +0000 UTC

错误:错误:关系“城市”已经存在

  • 0

我通过 pgAdmin4 创建了一个请求,它给出了一个错误“关系“城市”已经存在”。没有表格,所以也没有链接。

CREATE TABLE city
(
  id SERIAL PRIMARY KEY,
  id_region integer NOT NULL,
  name varchar(250) NOT NULL

);

INSERT INTO city (id, id_region, name) VALUES
(1, 1, 'Адыгейск'),
(2, 1, 'Майкоп'),
(3, 2, 'Горно-Алтайск'),
(4, 3, 'Алейск'),
(5, 3, 'Барнаул'),
(6, 3, 'Белокуриха'),
(7, 3, 'Бийск'),
(8, 3, 'Горняк'),
(9, 3, 'Заринск'),
(10, 3, 'Змеиногорск'),
(11, 3, 'Камень-на-Оби'),
(12, 3, 'Новоалтайск'),
(13, 3, 'Рубцовск'),
(14, 3, 'Славгород'),
(15, 3, 'Яровое'),
...
postgresql
  • 1 个回答
  • 10 Views
Martin Hope
Blacit
Asked: 2020-09-28 04:18:52 +0000 UTC

为什么不设置默认值

  • 0

我正在尝试设置默认值,但由于某种原因没有设置它们,您可以在第 3 行注意到这一点,因为前两个是手动完成的,我自己编写了所有内容,第三个是通过邮递员发送的 Json 请求. 角色列和状态列均未设置任何值。我正在使用postgresql。

在此处输入图像描述

在此处输入图像描述

java
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5