广告
返回顶部
首页 > 资讯 > 后端开发 > Python >微信小程序后端Java接口开发的详细步骤
  • 832
分享到

微信小程序后端Java接口开发的详细步骤

2024-04-02 19:04:59 832人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

目录1、搭建一个SpringBoot项目并引入依赖 2、编写controller层3、创建微信小程序项目 微信小程序使用wx.request(OBJECT)来调用后端接口。 首先

微信小程序使用wx.request(OBJECT)来调用后端接口。

首先 我们来一个简单案例 —— helloworld实现

1、搭建一个springboot项目并引入依赖

在这里插入图片描述


<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-WEB</artifactId>
        </dependency>

2、编写controller层


@RestController
public class HelloWorldController {
    @GetMapping("/helloWorld")
    public String helloWorld(Integer id){
        return "helloworld"+id;
    }
}

server:
  port: 80
  servlet:
    context-path: /
  Tomcat:
    uri-encoding: utf-8

运行成功

在这里插入图片描述

3、创建微信小程序项目

在这里插入图片描述

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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作