Python 官方文档:入门教程 => 点击学习
目录1、搭建一个SpringBoot项目并引入依赖 2、编写controller层3、创建微信小程序项目 微信小程序使用wx.request(OBJECT)来调用后端接口。 首先
微信小程序使用wx.request(OBJECT)来调用后端接口。
首先 我们来一个简单案例 —— helloworld实现
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-WEB</artifactId>
</dependency>
@RestController
public class HelloWorldController {
@GetMapping("/helloWorld")
public String helloWorld(Integer id){
return "helloworld"+id;
}
}
运行成功
helloworld.js
data: {
result:'请求后台中.....'
},
onLoad: function (options) {
var that=this;
this.getData(that);
},
getData(that){
wx.request({
url: 'Http://localhost:8080/helloWorld',
method:'GET',
data:{
id:666
},
header:{
'content-type':'application/JSON' //默认值
},
success(res){
console.log(res.data);
console.log(that);
that.setData({
result:res.data
})
}
})
},
helloworld.wxml
<text>后端返回的数据:{{result}}</text>
注意:!!!!
这里记得设置 如下图
否则会报错:
VM9 asdebug.js:1 http://localhost 不在以下 request
合法域名列表中,请参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html(env:
windows,mp,1.05.2110110; lib: 2.19.4)
访问后端成功 如下图
到此这篇关于微信小程序后端Java接口开发的详细步骤的文章就介绍到这了,更多相关小程序后端Java接口开发内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: 微信小程序后端Java接口开发的详细步骤
本文链接: https://www.lsjlt.com/news/156697.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0