美文网首页
Java - Spring Boot + MyBatis-Plu

Java - Spring Boot + MyBatis-Plu

作者: 西半球_ | 来源:发表于2020-05-12 20:37 被阅读0次

写一个接口

学习路线

暂时不涉及service层,只在Controller中实现,
接口代码写在 Controller 中,接口路径通过RequestMapping的路径拼上GetMapping或PostMapping的路径组成的

@RestController
@RequestMapping("v1/api/")

public class Controller {
 //实现各个接口
}

get请求 无参数

    /**
     * get请求 无参数 localhost:8080/v1/api/get
     */
    @GetMapping("get")
    public String get(){
        return "get请求 - 无参数";
    }
get请求 - 无参数

get请求 带参数


    /**
     * get请求 带参数 localhost:8080/v1/api/getWithParm?type=3
     */
    @GetMapping("getWithParm")
    public String getWithParm(String type){
        System.out.println("传的参数"+type);
        return "get请求 - 带参数";
    }
get请求 带参数

get请求 带参数2

    /**
     * get请求 带参数2 localhost:8080/v1/api/getWithParm2/要传的ID
     */
    @GetMapping(value = "getWithParm2/{id:\\w+}")
    public String getWithParm2(@PathVariable(required = false) String id) {
        System.out.println("getWithParm2 id- "+id);
        return "get请求 2 - 带参数 2";
    }
get请求 带参数2

post请求 无参数

    /**
     * post请求 无参数 localhost:8080/v1/api/post
     */
    @PostMapping("post")
    public String post(){
        return "post请求 - 无参数";
    }
post请求 无参数

post请求 带参数

    /**
     * post请求 带参数 localhost:8080/v1/api/postWithParm
     */
    @PostMapping("postWithParm")
//    public String postWithParm(String type){
//        System.out.println("传的参数"+type);
//        return "post请求 - 带参数";
//    }
    public String postWithParm(@RequestParam(required = false) String type,
                               @RequestParam(required = false) String id){
        System.out.println("post传的参数"+type);
        System.out.println("post传的参数"+id);
        return "post请求 - 带参数";
    }
post请求 带参数

delete请求 带参数

     /**
     * delete请求 带参数 localhost:8080/v1/api/deleteWithID
     */
    @DeleteMapping("deleteWithID")
    public String deleteWithID(@RequestParam(required = false) String id){
        System.out.println("delete传的参数"+id);
        return "delete请求 - 带参数";
    }

delete请求 带参数

相关文章

网友评论

      本文标题:Java - Spring Boot + MyBatis-Plu

      本文链接:https://www.haomeiwen.com/subject/mjaunhtx.html