微信小程序实现前后台交互(后台使用ssm框架)

微信小程序前端代码 :

index.js中page的onload函数。

onLoad: function () {
    wx.request({
      url: 'http://localhost:8080/BaseProjectSSM/admin/clazz_table/list2',
      method: 'post',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res => {
        console.log(res.data)
        this.setData({
          
        })
      },
      fail: res => {
        console.log("失败")
      }
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
        
      })
    }
  },

微信控制台结果:

微信小程序实现前后台交互(后台使用ssm框架)_第1张图片

后台代码:

控制层:

@RequestMapping(value="/list2",method=RequestMethod.POST)
	@ResponseBody
	public Map getList2(){
		Map ret = new HashMap();
		List clazz1 = clazzService.findList2();
		ret.put("clazzList2", clazz1);
		return ret;
	}

service.java文件

public List findList2();

serviceImpl.java文件

	@Override
	public List findList2() {
		// TODO Auto-generated method stub
		return clazzDao.findList2();
	}

 dao.java文件

	public List findList2();

clazz.java实体类

   package com.ischoolbar.programmer.entity.admin;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Component;



/**
 * 课程实体
 * @author whs
 *
 */
@Component
public class Clazz {
	private Long id;
	private String clazzname;//课程名字
	private Long categoryId;//分类id
	private ClazzCategory clazzCategory;//课程类别
	private Long addressId;//课程地址
	private String teacher;//教师
	private Date clazzTime;//上课时间
	private Integer duration; //时长
	private String weekday;//星期
	private String cost;//费用
	private String remark;//备注
	
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getClazzname() {
		return clazzname;
	}
	public void setClazzname(String clazzname) {
		this.clazzname = clazzname;
	}
	public Long getCategoryId() {
		return categoryId;
	}
	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}
	public ClazzCategory getClazzCategory() {
		return clazzCategory;
	}
	public void setClazzCategory(ClazzCategory clazzCategory) {
		this.clazzCategory = clazzCategory;
	}
	public Long getAddressId() {
		return addressId;
	}
	public void setAddressId(Long addressId) {
		this.addressId = addressId;
	}
	public String getTeacher() {
		return teacher;
	}
	public void setTeacher(String teacher) {
		this.teacher = teacher;
	}
	public Date getClazzTime() {
		return clazzTime;
	}
	public void setClazzTime(String clazzTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			this.clazzTime = sdf.parse(clazzTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public Integer getDuration() {
		return duration;
	}
	public void setDuration(Integer duration) {
		this.duration = duration;
	}
	public String getWeekday() {
		return weekday;
	}
	public void setWeekday(String weekday) {
		this.weekday = weekday;
	}
	public String getCost() {
		return cost;
	}
	public void setCost(String cost) {
		this.cost = cost;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
}

 mapper.xml文件


	

数据库:

微信小程序实现前后台交互(后台使用ssm框架)_第2张图片

你可能感兴趣的:(微信小程序实现前后台交互(后台使用ssm框架))