开发者社区> 问答> 正文

springmvc怎么基于ajax自动封装复杂表单bean?报错

我的bean是一对一的bean,ajax我输入属性名.属性名会提示报错,我应该怎么写参数名能够让springmvc自动封装bean呢

展开
收起
爱吃鱼的程序员 2020-06-06 21:23:10 516 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>找个js插件他会自动封装form数据为json</p>
    
                    
    
                        <p>springmvc4.0以后会自动封装到bean里,4.0之前可以配置解决。</p>
    

        jar包jack-json系列


        <!-- 输出对象转JSON支持   -->  
        <bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter">    
           <property name="supportedMediaTypes">    
               <list>    
                   <value>application/json;charset=utf-8</value>    
               </list>    
           </property>    
       </bean>  
       <bean id="jsonConverter"    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>   
        
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="webBindingInitializer">
                <bean class="com.jeecms.common.web.springmvc.BindingInitializer"/>
            </property>
             <property name="messageConverters">    
               <list>    
                   <ref bean="stringConverter"/>    
                   <ref bean="jsonConverter" />    
               </list>    
           </property> 
        </bean>

                        <p>ajax 使用 post 提交数据,controller 中使用 @RequestBody 描述对象类型的参数,会自动封装</p>
    
    2020-06-06 21:23:29
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载