美文网首页
2018-11-22java学习实例操作&商城商城流程

2018-11-22java学习实例操作&商城商城流程

作者: YW祥 | 来源:发表于2018-11-22 19:33 被阅读0次

    java接口自动化,json请求转换为javabean

    1.什么是GsonFormat
    将json数据格式转换为javabean对象的as插件
    2.快捷键 Ctrl+ALT+S,或settings -->Plugins -->输入GsonFormat install plugins


    image.png

    安装完成,重启IntelliJ IDEA即可,
    首先需要new Class文件,然后按键 ALT+Insert 选中GsonFormat,或快捷键ALT+S即可,弹出框输入json格式的字符串数据即可。

    网络下载不了使用本地导入

    本地jar文件已添加附件


    image.png

    使用效果

    新建请求javabean类
    https://www.tapd.cn/tfl/pictures/201811/tapd_63882484_1542879778_83.gif

    自动化有带[ ]商城增加商品

    image.png

    javabean请求

        private String brand;
        //声明一个list列表存储颜色
      private List<String> colors=new ArrayList<>();
      private int price;
      private String productCode;
      private String productName;
      private List<String> sizes =new ArrayList<>();
      private String type;
    
    
      public String getBrand() {
        return brand;
      }
    
      public List<String> getColors() {
        return colors;
      }
    
      public int getPrice() {
        return price;
      }
    
      public String getProductCode() {
        return productCode;
      }
    
      public String getProductName() {
        return productName;
      }
    
      public List<String> getSizes() {
        return sizes;
      }
    
      public String getType() {
        return type;
      }
    
      public void setBrand(String brand) {
        this.brand = brand;
      }
    
      public void setColors(List<String> colors) {
        this.colors = colors;
      }
    
      public void setPrice(int price) {
        this.price = price;
      }
    
      public void setProductCode(String productCode) {
        this.productCode = productCode;
      }
    
      public void setProductName(String productName) {
        this.productName = productName;
      }
    
      public void setSizes(List<String> sizes) {
        this.sizes = sizes;
      }
    
      public void setType(String type) {
        this.type = type;
      }
    
      @Override
      public String toString() {
        return "AddProdRequest{" +
            "brand='" + brand + '\'' +
            ", colors=" + colors +
            ", price=" + price +
            ", productCode='" + productCode + '\'' +
            ", productName='" + productName + '\'' +
            ", sizes=" + sizes +
            ", type='" + type + '\'' +
            '}';
      }
    }
    

    javabean响应

    
      private String respCode ;
      private String respDesc;
    
      public String getRespCode() {
        return respCode;
      }
    
      public String getRespDesc() {
        return respDesc;
      }
    
      public void setRespCode(String respCode) {
        this.respCode = respCode;
      }
    
      public void setRespDesc(String respDesc) {
        this.respDesc = respDesc;
      }
    
      @Override
      public String toString() {
        return "AddProdResponse{" +
            "respCode='" + respCode + '\'' +
            ", respDesc='" + respDesc + '\'' +
            '}';
      }
    }
    

    testNG运行结果

      @Test
      public void addProd(){
        AddProdRequest proreq=new AddProdRequest();
        proreq.setBrand("");
        ArrayList<String>colors=new ArrayList<>();
        colors.add("红");
        colors.add("蓝");
        proreq.setPrice(2000);
        proreq.setProductCode("12345");
        proreq.setProductName("手机");
        ArrayList<String>sizs=new ArrayList<>();
        sizs.add("大");
        sizs.add("小");
        proreq.setType("");
    
        String yewx = JSON.toJSONString(proreq, true);
        System.out.println(yewx);
        String yewx1 = HttpTools.doPostByJson("http://qa.guoyasoft.com:8080/product/addProd", yewx, "UTF-8");
        AddProdResponse yewx2 = JSON.parseObject(yewx1,AddProdResponse .class);
    
    
      }
    
    }
    

    文件在Wiki

    思维导图:![ 商城流程.png java学习.png 商城接连流程.png

    相关文章

      网友评论

          本文标题:2018-11-22java学习实例操作&商城商城流程

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