繁体   English   中英

BeanResult'parametre'的BindingResult和普通目标对象都不

[英]Neither BindingResult nor plain target object for bean name 'parametre'

我正在使用Spring MVC,因此基本上,我在创建一个论坛时将文件和radioButton作为输入:form_li.jsp:

<f:form  id="form1"
         name="form1"
         modelAttribute="parametre"
         action="${addTreat}"
         method="POST"
         enctype="multipart/form-data">

    <table>
        <tr>
            <td>xslx File : </td>
            <td>
                <f:input id="filepd" path="fileCom" name="filepd"  type="file" />
            </td>
        </tr>

        <tr>
            <td>Choice </td>
            <td>
                <div>
                    <f:input id="az" name="az" path="choice" type="radio" value="false" />
                    <label for="az">1</label>
                    <f:input id="aj" name="aj"  path="choice" type="radio" value="true"/>
                    <label for="aj">2</label>
                </div>
            </td>
        </tr>

        <tr>
            <div align="center">
                <f:input type="submit" value="Validate" path="" />
            </div>
        </tr>
    </table>
</f:form>

对于myController:

@RequestMapping(value="/addTreat", method= RequestMethod.POST)
public String addTr(HttpServletRequest req,
        BindingResult result,
        ModelMap model,
        @RequestParam("parametre") Parametre parametre) {

    model.addAttribute("parametre", new Parametre());
    return form_li;
}

对于Parametre.java类:

public class Parametre {

    private String choice;
    private MultipartFile fileCom;
    //getters and setters
    //default constructor
}

我的问题是运行应用程序并转到/ addTreat网址时。 我得到了著名的BeanResult'parametre'的BindingResult或普通目标对象都不能用作请求属性。 我尝试了多种解决方案,但我无法正常工作。 请任何人都可以帮助解决此问题。

这么多事情搞砸了,我建议您阅读一些modelAttribute示例,即使在官方的spring文档中也有几十个。 看起来您将模型对象与简单的请求参数混淆了,对于第二个对象,您甚至不需要BindingResult 此外,表单操作的语法不正确。

action="${addTreat}"更改为action="/addTreat"

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM