Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 跳过URI变量';id';因为请求包含同名的绑定值_Java_Postgresql_Hibernate_Spring Mvc - Fatal编程技术网

Java 跳过URI变量';id';因为请求包含同名的绑定值

Java 跳过URI变量';id';因为请求包含同名的绑定值,java,postgresql,hibernate,spring-mvc,Java,Postgresql,Hibernate,Spring Mvc,有一种PUT-方法,其任务是更改客户的卡。Customer类本身与User类(字段name、lastname等)具有@OneToOne关系。一切都很好,方法执行它的任务,这没有问题。但出于某种原因,它发出了警告: 2020-04-26 14:15:14.160 WARN 5340 --- [nio-8080-exec-2] o.springframework.validation.DataBinder : Skipping URI variable 'id' because request

有一种
PUT
-方法,其任务是更改
客户的卡。
Customer
类本身与
User
类(字段
name
、last
name
等)具有@OneToOne关系。一切都很好,方法执行它的任务,这没有问题。但出于某种原因,它发出了警告:

2020-04-26 14:15:14.160  WARN 5340 --- [nio-8080-exec-2] o.springframework.validation.DataBinder  : Skipping URI variable 'id' because request contains bind value with same name.
如何修复它

我使用
springmvc
+
Hibernate
+
Jpa
+
PostgreSQL

类用户:

package com.tinychiefdelights.model;
导入io.swagger.annotations.ApiModel;
导入龙目数据;
导入javax.persistence.*;
@ApiModel
@资料
@实体
@表(name=“pg_user”,schema=“public”)
公共类用户{
公共用户()休眠
}
公共用户(字符串名称、字符串姓氏、字符串角色、,
字符串登录,字符串密码){//
this.name=名称;
this.lastName=lastName;
this.role=角色;
this.login=登录;
this.password=密码;
}
// Поля
私人@Id
@生成值
长id;
@列(name=“login”)
私有字符串登录;
@列(name=“password”)
私有字符串密码;
@列(name=“role”)
私有字符串角色;
@列(name=“name”)
私有字符串名称;
@列(name=“last_name”)
私有字符串lastName;
}
客户:

package com.tinychiefdelights.model;
导入com.fasterxml.jackson.annotation.*;
导入龙目数据;
导入org.hibernate.annotations.NotFound;
导入org.hibernate.annotations.NotFoundAction;
导入javax.persistence.*;
导入java.util.List;
@资料
@实体
@表(name=“customer”,schema=“public”)
公共类客户{
公共客户()休眠
}
// Поля
//姓名、姓氏、登录名、密码、用户姓名;
私人@Id
@生成值
长id;
@列(name=“wallet”)
私人双钱包;
//关系
//
@OneToOne(级联=级联类型.ALL)
@JoinColumn(name=“user\u id”,referencedColumnName=“id”)//在用户类中不带客户加入
@NotFound(action=NotFoundAction.IGNORE)
私人用户;
//Лист заказов
@OneToMany(mappedBy=“customer”,cascade=CascadeType.ALL)
@JsonIgnore//
私有列表订单列表;
}
客户服务:

公共客户editCustomer(长id、用户用户、双钱包){
Customer=customerRepository.getByIdAndUserRole(id,“客户”);
customer.setUser(用户);
customer.setWallet(钱包);
返回customerRepository.save(客户);
}
客户控制员:

@PutMapping(“/customer/{id}”)
Customer editCustomer(@PathVariable Long id,用户用户,@RequestParam double wallet){
返回customerService.editCustomer(id、用户、钱包);
}

因为您正在向
@PutMapping
传递一个id为的用户,并且还有一个路径变量id。从Spring MVC模型属性中检查此代码:

private void bind(ServletRequest request, ServletRequestDataBinder dataBinder) {
    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
    if (multipartRequest != null) {
        bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
    }

    String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
    Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
    if (uriVars != null) {
        for (Map.Entry<String, String> entry : uriVars.entrySet()) {
            if (mpvs.contains(entry.getKey())) {
                logger.warn("Skipping URI variable '" + entry.getKey()
                        + "' since the request contains a bind value with the same name.");
            } else {
                mpvs.addPropertyValue(entry.getKey(), entry.getValue());
            }
        }
    }

    this.extendDataBinder.doExtendBind(mpvs, dataBinder);

    dataBinder.bind(mpvs);
}
private void bind(ServletRequest-request,ServletRequestDataBinder-dataBinder){
MutablePropertyValues mpvs=新的ServletRequestParameterPropertyValues(请求);
MultipartRequest MultipartRequest=WebUtils.getNativeRequest(请求,MultipartRequest.class);
if(multipartRequest!=null){
bindMultipart(multipartRequest.getMultiFileMap(),mpvs);
}
字符串attr=HandlerMapping.URI\u模板\u变量\u属性;
Map uriVars=(Map)request.getAttribute(attr);
if(uriVars!=null){
对于(Map.Entry:uriVars.entrySet()){
if(mpvs.contains(entry.getKey())){
logger.warn(“跳过URI变量””+entry.getKey()
+“'因为请求包含同名的绑定值。”);
}否则{
mpvs.addPropertyValue(entry.getKey(),entry.getValue());
}
}
}
this.extendDataBinder.doExtendBind(mpvs,dataBinder);
dataBinder.bind(mpvs);
}

因为您正在向
@PutMapping
传递一个id为的用户,并且还有一个路径变量id。从Spring MVC模型属性中检查此代码:

private void bind(ServletRequest request, ServletRequestDataBinder dataBinder) {
    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
    if (multipartRequest != null) {
        bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
    }

    String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
    Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
    if (uriVars != null) {
        for (Map.Entry<String, String> entry : uriVars.entrySet()) {
            if (mpvs.contains(entry.getKey())) {
                logger.warn("Skipping URI variable '" + entry.getKey()
                        + "' since the request contains a bind value with the same name.");
            } else {
                mpvs.addPropertyValue(entry.getKey(), entry.getValue());
            }
        }
    }

    this.extendDataBinder.doExtendBind(mpvs, dataBinder);

    dataBinder.bind(mpvs);
}
private void bind(ServletRequest-request,ServletRequestDataBinder-dataBinder){
MutablePropertyValues mpvs=新的ServletRequestParameterPropertyValues(请求);
MultipartRequest MultipartRequest=WebUtils.getNativeRequest(请求,MultipartRequest.class);
if(multipartRequest!=null){
bindMultipart(multipartRequest.getMultiFileMap(),mpvs);
}
字符串attr=HandlerMapping.URI\u模板\u变量\u属性;
Map uriVars=(Map)request.getAttribute(attr);
if(uriVars!=null){
对于(Map.Entry:uriVars.entrySet()){
if(mpvs.contains(entry.getKey())){
logger.warn(“跳过URI变量””+entry.getKey()
+“'因为请求包含同名的绑定值。”);
}否则{
mpvs.addPropertyValue(entry.getKey(),entry.getValue());
}
}
}
this.extendDataBinder.doExtendBind(mpvs,dataBinder);
dataBinder.bind(mpvs);
}

但是如何修复?您已经在发送用户,设置其id并从那里读取,而不是路径变量。但是如何修复?您已经在发送用户,设置其id并从那里读取,而不是路径变量。