esolve
V2EX  ›  问与答

SpringMVC: spring form 里 inputform 必须要有一个 modelattribute 吗?

  •  
  •   esolve · Dec 11, 2017 · 2623 views
    This topic created in 3082 days ago, the information mentioned may be changed or developed.

    一般来说 spring form 如下用:

    <form:form id="inputForm" modelAttribute="product" action="${ctx}/product/add" method="POST"\>
    
    <form:input path="name" id="name"/>
    

    需要后端传一个 product bean,而提交的也是 product.name

    现在我想要的页面 randominput.jsp 诸如

    <form:form id="inputForm" action="${ctx}/randomthings/add" method="POST"\>
    <form:input path="type" type="hidden" id="type"/>
    <form:input path="applePrice" id="applePrice"/>
    
    <form:input path="location" id="location"/>
    

    location 和 applePrice 并不在同一个 bean 内

    后台大致是

     @RequestMapping(value = {"addVouchers"}, method = RequestMethod.GET)
     public String addVouchers(Model model) {
        String type = getType();
        model.addAttribute("type",type);
        return "modules/randominput";
    }
    

    这样做结果却是 java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

    如何解决啊?

    esolve
        1
    esolve  
    OP
       Dec 11, 2017
    顶顶顶
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2447 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:04 · PVG 00:04 · LAX 09:04 · JFK 12:04
    ♥ Do have faith in what you're doing.