• springmvc乱码及restful


    1 乱码的解决--通过过滤器来解决:springmvc中提供characterEncodingFilter

     post乱码

    <filter>
          <filter-name>CharacterEncodingFilter</filter-name>
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
          <init-param>
              <param-name>encoding</param-name>
              <param-value>utf-8</param-value>
          </init-param>
      </filter>
      <filter-mapping>
          <filter-name>CharacterEncodingFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>

    如果是get方式乱码

    a 修改tomcat的配置

    b 自己定义乱码解决的过滤器

    2 restful风格的url

    有点:轻量级,安全,效率高

    @RequestMapping("/{id}/{uid}/delete")
        public String hello(@PathVariable int uid,@PathVariable int id){
            System.out.println("id:"+id);
            System.out.println("uid:"+uid);
            return "/index.jsp";
            //
        }

    3 同一个controller通过参数来到达不同的处理方法--不重要

    提交url:http://localhost:8080/SpringMVC_Restful07/?method=add

    处理代码:

    //http://localhost:8080/SpringMVC_Restful07/?method=add   old way
        @RequestMapping(params="method=add",method=RequestMethod.GET)
        public String add(){
            System.out.println("add");
            return "redirect:/index.jsp";
        }
    public String update(){
            System.out.println("update");
            return "redirect:/index.jsp";
        }
        public String delete(){
            System.out.println("delete");
            return "redirect:/index.jsp";
        }
  • 相关阅读:
    svg 画地图
    小议 localStorage
    .NET Core 的缓存篇之MemoryCache
    .NET Core Session的简单使用
    .NET Core 使用NLog日志记录
    .NET Core 技巧汇总篇
    .NET Core 获取自定义配置文件信息
    微信支付教程系列之公众号支付
    微信支付教程系列之扫码支付
    微信支付教程系列之现金红包
  • 原文地址:https://www.cnblogs.com/alloevil/p/6070490.html
Copyright © 2020-2023  润新知