zoukankan      html  css  js  c++  java
  • SpringMVC restful

    1、基本

    @Controller       控制层
    @Service         业务层
    @Component    组件
    @Repository     dao

    2、@RequestMapping url

    三、restful 风格

    与python的restful差不多

    1、不用restful风格

    访问链接

    http://localhost:8090/add?a=1&b=3

    控制层

    package com.wt.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    // 控制注解
    @Controller
    public class HelloControl {
        @RequestMapping("/add")
        public String showHi(int a, int b, Model model){
            String result = "结果是:" + (a + b);
            model.addAttribute("msg", result);
            return "hi";
        }
    }

    2、使用restful风格

    注意:注解 PathVariable

    // 控制注解
    @Controller
    public class HelloControl {
        @RequestMapping("/add/{a}/{b}")
        public String showHi(@PathVariable int a, @PathVariable int b, Model model){
            String result = "结果是:" + (a + b);
            model.addAttribute("msg", result);
            return "hi";
        }
    }

    3、请求方式

    GET POST PUT DELETE

    // 控制注解
    @Controller
    public class HelloControl {
    //    @RequestMapping(name="/add/{a}/{b}", method = RequestMethod.GET)
        @GetMapping("/add/{a}/{b}")
        public String showHi(@PathVariable int a, @PathVariable int b, Model model){
            String result = "结果是:" + (a + b);
            model.addAttribute("msg", result);
            return "hi";
        }
    }
    @PostMapping()
    @PutMapping()
    @DeleteMapping()
  • 相关阅读:
    CentOS 7 和centos6切换图形界面和多用户界面
    centos6.8下安装elasticsearch
    一个xib钟多个Cell
    iOS frame从导航栏下面开始
    Xcode 移除(卸载)插件
    iOS9 HTTP传输安全
    pch头文件
    真机调试---打包6plus出现问题
    Xcode 添加类前缀
    iOS 状态栏黑色背景白色字体
  • 原文地址:https://www.cnblogs.com/wt7018/p/13341981.html
Copyright © 2011-2022 走看看