后端用的是ssm,具体就不讲怎么配置了。
前端用小程序,第一次做这个。
在user.js中
const USER_URL = 'http://localhost:81/showAllUser';
let appDatas = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
user: ""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.request({
url: USER_URL,
success: (response) => {
this.setData({
user:response.data
})
console.log(response);
//appDatas.data=response.data;
// 更新app数据
}
});
},
})
在user.wxml中
<navigator url="http://localhost:81/demo/showAllUser">
<text>id:{{user.id}}\n</text>
<text>name:{{user.name}}</text>
</navigator>
就可以获取到数据库中的数据了。
如果有多个用户则遍历输出
其他都不变,user.wxml中改为
<navigator wx:for="{{user}}" wx:key="{{index}}">
<text>id:{{user[index].id}}\n</text>
<text>name:{{user[index].name}}</text>
</navigator>