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()
  • 相关阅读:
    含字母数字的字符串排序算法,仿Windows文件名排序算法
    WCF、WPF、Silverlight和区别(转)
    线程组的介绍
    python基础字符串的修改
    c语言
    python 字典
    单元测试相关
    python列表
    如何才能设计出好的测试用例
    字符串查找
  • 原文地址:https://www.cnblogs.com/wt7018/p/13341981.html
Copyright © 2011-2022 走看看