微信小程序 post请求

后端

@Data
public class PostBean {

    private String str;
    private Boolean bool1;
    private Integer int1;
}

    @PostMapping("/postTest")
    public String postTest(@RequestBody PostBean postBean){
        System.out.println("====postTest()==begin=" +postBean);
        System.out.println("====postTest()==end=");
        return "post test success! "+postBean.getStr();
    }

小程序

postTest() {
  var that = this;
  wx.request({
    url: 'http://127.0.0.1:8080/test/postTest', //仅为示例,并非真实的接口地址
    method: "POST",
    data: {
      "str": "restfulToolkitX",
      "bool1": true,
      "int1": 1
    },
    header: {
      'content-type': 'application/json' // 默认值
    },
    success (res) {
      console.log(res.data)
    },
    fail(res) {
      console.log(res.erMsg)
    }
  })

你可能感兴趣的:(微信小程序,微信小程序,java,小程序)