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";
      }
    }
  • 相关阅读:
    NSDate
    Info.plist字段列表详解
    面向对象编程思想以及强、弱引用总结
    分类(类别/Category)与 类扩展(Extension)
    UIAlertView
    SQLite3的运用
    快速创建单例
    C++ 常用设计模式
    I2S 总线学习:2-I2S驱动WM8978
    设计模式的七大原则
  • 原文地址:https://www.cnblogs.com/NBG-SDL/p/14157598.html
Copyright © 2011-2022 走看看