postman 和 maven 教程

参考 https://www.yiibai.com/maven/

理解maven为是帮我们建立好了一个服务器,我们只要新建一个java类,写入中间功能,其他的api接口,maven都帮我们弄好了。

我理解maven是一个框架,帮我们把服务器建立连接的都搞好了,比如一个服务器ip传参数进去,怎么传到里面的过程和传到输出帮我们搞好了

这里写图片描述

  1. 新建project,选spring Initializr,再next,next,选web ☑️web,后面还有把SQL的MySQL和MyBatis、JDBC(还是SQL Server来着)选中☑️。
  2. 右键new java class 比如图中的Api2Controller

    package com.example.demo;
    import org.springframework.web.bind.annotation.RequestMapping;#导入这几个
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    import java.util.HashMap;
    import java.util.Map;
    @RestController
    public class Api2Controller {
        @RequestMapping("/test")#相当于一个自建的新建的路径入口(package也是路径,但这个是新建的,原本不存在的)
        public Map<String,Object> aa(@RequestParam("bb") String bb){
            Map<String,Object> rtn = new HashMap<>();
            rtn.put("Hello","world "+bb);
        #或者:
        public String aa(@RequestParam(value = "aa",required = false) String a,
                     @RequestParam(value = "bb",required = true) String b){
        String c = a + b;
        # @RequestParam是一个绑定,要输入绑定参数,是输入的意思,输入到变量aa/bb里,required=false就是可以不输入,那么该变量默认是null,required=ture是默认的,就是一定要输入,不输入该变量会报错。
        #return c;
        return rtn;
    }
        #也可以写成网页的版本
        @RequestMapping("/html")
        public String bb(@RequestParam("bb") String bb){
            String rtn = "<html><body><h1>Hello world "+bb+"</h1></body></html>";
            return rtn;
        }
        }
    
  3. 配合postman使用:
    这里写图片描述
    点中间上面的+号,建立新一个URl。
    选中GET/POST等,输入路径,本地是http://127.0.0.8088,然后再添加刚新建的路径,最后是http://127.0.0.8088/test,然后点“Params”,输入参数,比如key输入aa,value 随便写,再key输入bb,value随便写。就是等会要输入IDEA的.

  4. run IDEA的程序,运行起服务器和spring,然后到postman中,点“Send”,就在postman看见返回值了。

改端口

这里写图片描述

src - main -resource - application.properties可以改端口,比如改成server.port=9999

mysql配合maven(JDBC)

https://www.cnblogs.com/suixue/p/5687764.html
IDEA中Maven管理下添加mysql依赖,不需要加载进jar包,只需要在pom.xml添加几行代码,让服务器去下载jar包。

猜你喜欢

转载自blog.csdn.net/eqiang8848/article/details/82254935