zoukankan      html  css  js  c++  java
  • RESTful风格;

    RESTFUL是一种网络应用程序的设计风格和开发方式,基于HTTP,可以使用XML格式定义或JSON格式定义。RESTFUL适用于移动互联网厂商作为业务使能接口的场景,实现第三方OTT调用移动网络资源的功能,动作类型为新增、变更、删除所调用资源。

    一:

    二:

    三:

    package com.nbg.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    /**
     * @Controller注解配置的类表示被扫描,被spring托管
     */
    @Controller
    @RequestMapping("/hello")
    public class HelloController {
        @RequestMapping("/haha")
        public String one(Model model) {
            model.addAttribute("one", "第一个注解配置的springmvc");
            /**
             * 会被实体解析器处理
             */
            return "one";
        }
    
        /**
         * RESTful风格;http://localhost:8080/springmvc_03_Anno/hello/restFul/1/2  1→a,2→b
         * 需要使用@PathVariable注解;
         *
         * @param a
         * @param b
         * @param model
         * @return
         */
        @RequestMapping("/restFul/{a}/{b}")
        public String restFul(@PathVariable int a, @PathVariable int b, Model model) {
            model.addAttribute("one", "" + a + b);
            return "one";
        }
    
        /**
         * 使用了 @PostMapping 这个注解,那就只有使用post请求才能被访问到,其余一样@GetMapping
         *
         * @param a
         * @param b
         * @param model
         * @return
         */
        @PostMapping("/post/{a}/{b}")
        public String postM(@PathVariable int a, @PathVariable int b, Model model) {
            model.addAttribute("one", "" + a + b);
            return "one";
        }
      /**
       * 使用这种方法@RequestMapping(name = "/nameAndMethod/{a}/{b}",method = {RequestMethod.GET})
       * 也可以做到@GetMapping的效果
       * @param a
       * @param b
       * @param model
       * @return
       */
      @RequestMapping(value= "/valueAndMethod/{a}/{b}",method = {RequestMethod.GET})
      public String getM(@PathVariable int a, @PathVariable int b, Model model) {
       model.addAttribute("one", "" + a + b);
       return "one";
      }
    }
  • 相关阅读:
    HTML
    JavaScript事件对象
    JavaScript 事件入门
    如何向github上传文件
    crystal
    BUUCTF[强网杯 2019]随便注wp
    BUUCTF[CISCN2019 华东南赛区]Web4 wp
    BUUCTF[NPUCTF2020]ezinclude wp
    Windows下Ant的环境配置
    Java解惑(1)——表达式之谜
  • 原文地址:https://www.cnblogs.com/NBG-SDL/p/14157598.html
Copyright © 2011-2022 走看看