微信小程序学习1

小程序 就是把javaWeb项目的jsp/(thymeleaf)html的代码放在小程序写。

两者的区别

  • action=”wxtest”|| url: ‘http://localhost:8035/wxtest',
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    //jsp
    <form action="wxtest" method="post">

    name: <input name="username"/> <br/>
    name: <input name="password"/> <br/>
    <button type="submit">提交</button>

    </form>

    //wx
    //Page({

    // bindtest按钮监听事件
    bindtest:function(){
    wx.request({
    url: 'http://localhost:8035/wxtest',
    data:{
    username:"001",
    password:"abc",
    },
    method:"GET",
    header:{
    'content-type': 'application/json' //默认值
    },
    success: function (res) {
    console.log(res.data);
    },
    fail: function (res) {
    console.log("失败");
    }
    })
    }
    })

((idea)springboot框架)后端+前端(微信小程序)的demo:简单数据交互 完整教程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//后端
public class wxController extends HttpServlet {
@RequestMapping("/wxtest")
public void wxtest(User u, HttpServletResponse response) throws IOException {
System.out.println("username:" + u.getUsername() + "passsword:" + u.getPassword());
System.out.println("username:" + u.getUsername() + "passsword:" + u.getPassword());
System.out.println("username:" + u.getUsername() + "passsword:" + u.getPassword());
System.out.println("username:" + u.getUsername() + "passsword:" + u.getPassword());
System.out.println("username:" + u.getUsername() + "passsword:" + u.getPassword());

Writer out=response.getWriter();
out.write("enter wxBack");
out.flush();
}

}

//前端
Page({

// bindtest按钮监听事件
bindtest:function(){
wx.request({
url: 'http://localhost:8035/wxtest',
data:{
username:"001",
password:"abc",
},
method:"GET",
header:{
'content-type': 'application/json' //默认值
},
success: function (res) {
console.log(res.data);
},
fail: function (res) {
console.log("失败");
}
})
}
})


把数据库的数据显示在微信小程序页面

  • 结合工具postman理解
  • 后端从数据库取出数据封装成集合对象 发送给微信小程序 小程序在显示
  • 如何发送到小程序 小程序如何调用集合对象并显示?