xuganggogo
2013-03-19 19:53
采纳率: 0%
浏览 1.1k
已采纳

SpringMVC 的 @RequestParam required 失效的问题,请教各位。

controller部分代码如下:

    @RequestMapping(value = "/u/info/infoMonitorFromFriend" )
    public String infoMonitorFromFriend(  
        @RequestParam(required=false,defaultValue="",value="attid") int[] attid,    //信息的属性额 1 原创         2 转发    7回复   
        @RequestParam(required=false,defaultValue="",value="keyid") int[] keyid,  //关键词id 过滤
        @RequestParam(required=false,defaultValue="",value="stat") int[] stat, // 状态
        @RequestParam(required=false,defaultValue="",value="contentkey") String  contentkey, //  内容包涵的词
        @RequestParam(required=false,defaultValue="",value="userkey") String userkey, // 用户名包涵的内容
        @RequestParam(value="page",defaultValue="1") Integer page,
        @RequestParam(value="pageSize",defaultValue="5") Integer pageSize,
        HttpServletRequest request, HttpServletResponse response, ModelMap model ) throws IOException 
    {

当在Spring配置文件中用

<mvc:annotation-driven />

 **/u/info/infoMonitorFromFriend?page=1&pageSize=5 这样的URL可以放到controller。

但是当我用,

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

来配置,如下

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="order" value="0" />            
    </bean>     
    
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">  
        <property name="messageConverters">    
            <list>    
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />  
                <bean class="org.springframework.http.converter.StringHttpMessageConverter" /> 
                <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" /> 
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /> 
                <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /> 
                <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />   
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" > 
                    <property name="supportedMediaTypes">  
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>  
                </bean>
            </list>    
        </property>    
    </bean>    

 **/u/info/infoMonitorFromFriend?page=1&pageSize=5 这样的URL就会返回404.

 

求解答~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • jinnianshilongnian 2013-03-23 11:08
    已采纳

    validator="validator"
    conversion-service="conversionService"
    content-negotiation-manager="contentNegotiationManager">

    [color=red]
    <!-- StringHttpMessageConverter编码为UTF-8,防止乱码 -->



    /mvc:message-converters[/color]

        <mvc:argument-resolvers>
            <bean class="com.sishuok.es.common.web.bind.method.annotation.PageableMethodArgumentResolver"/>
            <bean class="com.sishuok.es.common.web.bind.method.annotation.SearchableMethodArgumentResolver"/>
            <bean class="com.sishuok.es.common.web.bind.method.annotation.FormModelMethodArgumentResolver"/>
            <bean class="com.sishuok.es.sys.user.web.bind.method.CurrentUserMethodArgumentResolver"/>
        </mvc:argument-resolvers>
    
    </mvc:annotation-driven>
    
    点赞 打赏 评论

相关推荐 更多相似问题