zoukankan      html  css  js  c++  java
  • SpringMVC之映射到方法

    springMVC实例一

    请求中要包含name,但是不能包含age的写法params={"name","!age"}

    当传age的时候

    实例二:

    先看删除和更新

    HiddenHttpMethodFilter在Spring3.0中将post请求转换为put和delete请求,

    查看HiddenHttpMethodFilter源码

    @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
    
            String paramValue = request.getParameter(this.methodParam);
            if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) {
                String method = paramValue.toUpperCase(Locale.ENGLISH);
                HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
                filterChain.doFilter(wrapper, response);
            }
            else {
                filterChain.doFilter(request, response);
            }
        }
    public static final String DEFAULT_METHOD_PARAM = "_method";
    
        private String methodParam = DEFAULT_METHOD_PARAM;

    所以把name为_method的属性设置为DELETE和PUT就可以了

    在web.xml中配置HiddenHttpMethodFilter,要写在DispatcherServlet前面

    查询和保存:

    运行页面:

  • 相关阅读:
    shell脚本
    恋练有词
    sublime text3 的汉化
    c#中如何将int i=1;转化成string s="0001"
    SQL语句中DateAdd 函数说明
    ASP.NET弹出对话框
    C/C++避免头文件包含造成的重定义方法
    Android:保存图片到Sqlite数据库
    Ubuntu 12.04 配置
    C# 实现天气预报
  • 原文地址:https://www.cnblogs.com/lonely-buffoon/p/5582556.html
Copyright © 2011-2022 走看看