简体   繁体   English

BeanResult的BindingResult或普通目标对象都不能用作请求属性,我也不知道为什么

[英]Neither BindingResult nor plain target object for bean name available as request attribute, and I don't know why

I'm getting an error: Neither BindingResult nor plain target object for bean name 'foo' available as request attribute and I can't figure out why. 我收到一个错误: Neither BindingResult nor plain target object for bean name 'foo' available as request attribute都不能Neither BindingResult nor plain target object for bean name 'foo' available as request attribute ,我不知道为什么。 I know there are some questions regarding this already, and I have tried their solutions to no avail. 我知道已经对此有一些疑问,我已经尝试了他们的解决方案,但无济于事。

As far as the headers for the code I have (all actual variables have been replaced with metasyntactic variables): 就我的代码头而言(所有实际变量都已替换为元语法变量):

In the JSP that doesn't work: 在不起作用的JSP中:

<form:form name="myForm"
class="form-horizontal form-row-seperated" action="#"
onsubmit="return isformSubmit();" method="post" 
modelAttribute="foo">

In the Java controller for said JSP: 在表示JSP的Java控制器中:

@RequestMapping(value="bar", method = RequestMethod.POST)
public @ResponseBody Boolean baz(
    @ModelAttribute("foo") FOOBEAN fooBean,
// Ten @RequestParam strings have been omitted for brevity
 , HttpServletRequest qux) throws QUUXEXCEPTION {

foo does not show up anywhere else in the configurator page. foo不会显示在配置器页面的其他任何地方。

I know I'm doing something wrong, but I don't know what exactly. 我知道我做错了,但我不知道到底是什么。 If I'm not giving enough context, please let me know. 如果我没有提供足够的背景信息,请告诉我。

UPDATE: Here's the FOOBEAN class. 更新:这是FOOBEAN类。 I'm reusing metasyntactic variables here; 我在这里重用元语法变量; they are not the same variables that were in the controller class. 他们是不是可以在控制器类相同的变量。 Also, FOOBEAN and Foo are not related other than that Foo is a variable within FOOBEAN . 此外, FOOBEANFoo不相关,只是FooFOOBEAN的变量。

public class FOOBEAN {

     private String Foo;

     private String Bar;

     private String Baz;

     private String Qux;

     private String Quux;

     private String Corge;

     private String Grault;

     private String Garply;


     public String getFoo() {
        return Foo;
    }

    public void setFoo(String foo) {
        Foo = foo;
    }

    public String getBar() {
        return Bar;
    }

    public void setBar(String bar) {
        Bar = bar;
    }

    public String getBaz() {
        return Baz;
    }

    public void setBaz(String baz) {
        Baz = baz;
    }

    public String getQux() {
        return Qux;
    }

    public void setQux(String qux) {
        Qux = qux;
    }

    public String getQuux() {
        return Quux;
    }

    public void setQuux(String quux) {
        Quux = quux;
    }

    public String getCorge() {
        return Corge;
    }

    public void setCorge(String corge) {
        Corge = corge;
    }

    public String getGrault() {
        return Grault;
    }

    public void setGrault(String grault) {
        Grault = grault;
    }

    public String getGarply() {
        return Garply;
    }

    public void setGarply(String garply) {
        Garply = garply;
    }

}

You need to add the BindingResult object as a parameter and initialise the model as follows: 您需要添加BindingResult对象作为参数,并按如下所示初始化模型:

@ModelAttribute("foo") 
public FOOBEAN getFoo(){ 
    return new FOOBEAN();
}

public @ResponseBody Boolean baz(@ModelAttribute("foo") FOOBEAN fooBean, BindingResult result, HttpServletRequest qui) {
    // method body does here 
}

Note that the getFoo method must be called in the GET handler, ie the method you use to return the view name. 请注意,必须在GET处理程序中调用getFoo方法,即用于返回视图名称的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会在 Spring 中收到此消息? “ BindingResult 和 bean 名称 &#39;removedTeam&#39; 的普通目标对象都不能用作请求属性” - Why am I getting this message in Spring? “Neither BindingResult nor plain target object for bean name 'removedTeam' available as request attribute” BindingResult和bean的普通目标对象都不能作为请求属性使用 - Neither BindingResult nor plain target object for bean available as request attribute 在这种情况下,为什么会出现错误“ Bean名称&#39;user&#39;的BindingResult和普通目标对象均不可用”? - Why do I get an error “Neither BindingResult nor plain target object for bean name 'user' available as request attribute” in this case? 循环时获取“既没有 BindingResult 也没有可用作请求属性的 bean 名称‘bean 名称’的普通目标对象” - Getting "Neither BindingResult nor plain target object for bean name 'bean name' available as request attribute" when looping BeanResult的BindingResult和普通目标对象都不能用作请求属性 - Neither BindingResult nor plain target object for bean name available as request attribute Bean名称“所有者”的BindingResult和普通目标对象都不能用作请求属性 - Neither BindingResult nor plain target object for bean name 'owner' available as request attribute IllegalStateException:BeanResult&#39;getAppointment&#39;的BindingResult和普通目标对象都不能用作请求属性 - IllegalStateException: Neither BindingResult nor plain target object for bean name 'getAppointment' available as request attribute Bean名称“ categorie”的BindingResult或普通目标对象都不能用作请求属性 - Neither BindingResult nor plain target object for bean name 'categorie' available as request attribute BindingResult和bean名称&#39;team&#39;的普通目标对象都不能作为请求属性使用 - Neither BindingResult nor plain target object for bean name 'team' available as request attribute BeanResult&#39;user&#39;的BindingResult和普通目标对象都不能用作请求属性 - Neither BindingResult nor plain target object for bean name 'user' available as request attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM