zoukankan      html  css  js  c++  java
  • springmvc:RestFul-Filter

    1.RestFul(简洁,安全,高效)

    原来的:http://localhost:8888/test1?a=1&b=3
    RestFull:http://localhost:8888/test1/2/2
    
    @Controller
    public class RestFullController {
       // @RequestMapping(value = "/test1/{a}/{b}",method = RequestMethod.GET)
        @RequestMapping("/test/{a}/{b}")
        public String test1(@PathVariable int a, @PathVariable int b, Model model){
            int res=a+b;
            model.addAttribute("msg","结果1为"+res);
            return "test";
        }
        @PostMapping("/test/{a}/{b}")
        public String test2(@PathVariable int a, @PathVariable int b, Model model){
            int res=a*b;
            model.addAttribute("msg","结果2为"+res);
            return "test";
        }
    }
    

    2.Filter(解决请求中的乱码)

    <!--1.配置过滤器-->
    <filter>
        <filter-name>encoding</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>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    //class配置
    public class Filt implements Filter {
        public void init(FilterConfig filterConfig) throws ServletException {
    
        }
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
            filterChain.doFilter(request,response);
        }
        public void destroy() {
    
        }
    }
    
  • 相关阅读:
    NET 事件与委托
    NET高级 REF OUT
    缓冲池
    NET高级 EQUAL相等
    装箱拆箱
    CTS、CLS、CLR
    结构体及引用类型
    NET高级-深拷贝浅拷贝
    密闭类 静态 类及扩展方法
    NET高级-索引器
  • 原文地址:https://www.cnblogs.com/zh93/p/12952182.html
Copyright © 2011-2022 走看看