概述
wxml
<!--miniprogram/pages/testDemo/testDemo.wxml-->
<swiper autoplay="{{autoplay}}" interval="{{interval}}" circular="{{circular}}" duration="{{duration}}" vertical="{{vertical}}">
<block wx:for="{{newsarr}}" wx:key="">
<swiper-item>
<view class="swiperList">
<text class="iconfont icon-news"></text>
<text> {{item.message}}</text>
</view>
</swiper-item>
</block>
</swiper>
<form bindsubmit="formSubmit">
<view class="page-section">
<view class="weui-cells__title">学生姓名</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<input class="weui-input" name="name" placeholder-style="color:#F76260" placeholder="必填" />
</view>
</view>
</view>
<view class="section section_gap">
<view class="weui-cells__title">性别</view>
<radio-group name="sex">
<label><radio value="1"/>男</label>
<label><radio value="0"/>女</label>
</radio-group>
</view>
<view class="section">
<view class="weui-cells__title">出生日期选择</view>
<picker mode="date" value="{{date}}" name="birthday" start="1990-09-01" end="2017-09-01" bindchange="bindDateChange">
<view class="picker">
当前选择: {{date}}
</view>
</picker>
</view>
<button formType="submit">提交</button>
<button formType="reset">重新填写</button>
</form>
js
// miniprogram/pages/testDemo/testDemo.js
Page({
/**
* 页面的初始数据
*/
data: {
date: '1995-09-01',
region: ['广东省', '广州市', '海珠区'],
customItem: '全部',
newsarr: [
{ id: 0, message: "姓名必填" },
{ id: 4, message: "其他随意" }
],
autoplay: true,
interval: 1000,
duration: 500,
vertical: true,
circular: true,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
formSubmit: function (e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value)
var data=e.detail.value
if (e.detail.value.name.length == 0) {
wx.showToast({
title: '姓名不能为空!',
icon: 'loading',
duration: 1500
})
}else{
wx.showLoading({
title: '数据正在提交中......',
mask:"true"
})
var vo={
name:e.detail.value.name,
sex:e.detail.value.sex,
birthday:e.detail.value.birthday
}
wx.request({
url: 'http://localhost:8081/weDemo/insertStu',
data:{
vo:JSON.stringify(vo),
},
method:'GET',
success: res => {
if (res.data=="sucess") {
wx.showToast({
title: '新增成功',
})
}else{
wx.showToast({
title: '新增失败,请联系JAVA',
icon: 'error',
})
}
console.log(res.data),
wx.hideLoading()
}, fail: err => {
wx.showToast({
icon: 'none',
title: '新增记录失败'
})
console.error('[数据库] [新增记录] 失败:', err)
}
})
}
},
bindDateChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
date: e.detail.value
})
},
bindRegionChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
region: e.detail.value
})
}
})
Controller
package com.excel.demo.controller;
import com.alibaba.fastjson.JSONObject;
import com.excel.demo.entity.Student;
import com.excel.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author :Hj
* @date 2021/03/16 10:50
*/
@RestController
@RequestMapping("/weDemo")
public class WeDemoControl {
@Autowired
private StudentService studentService;
@ResponseBody
@RequestMapping(value = "/insertStu")
public String insertStu(String vo){
Student student= JSONObject.parseObject(vo,Student.class);
studentService.insertStu(student);
return "sucess";
}
}
最后
以上就是冷静红酒为你收集整理的小程序开发之提交数据给后台Springboot保存数据wxmljsController的全部内容,希望文章能够帮你解决小程序开发之提交数据给后台Springboot保存数据wxmljsController所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复