2021-09-10

该博客介绍了如何使用SpringBoot、Mybatis和MySQL数据库实现一个微信小程序的登录、注册和选课功能。前端页面包括登录、选课和个人课表界面,支持缓存登录信息。后端通过UserMapper接口操作数据库,进行用户验证和数据存储。
摘要由CSDN通过智能技术生成

SpringBoot+Mybatis+微信小程序实现前后端分离的登录 注册 选课小程序

前端页面:
注册界面
登录界面:后端判断账号密码是否匹配
登录页面

选课界面:
选课界面

我的课表界面:实现退课功能和显示课表功能
我的课表

个人页面显示:实现setStorageSync缓存 登录人的信息,并且获取登陆人信息显示到个人信息页面
个人信息界面

Springboot+Mybatis+Mysql

UserMapper

package com.example.demowx.mapper;


import com.example.demowx.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RestController;

@Mapper
@Repository
@RestController
public interface UserMapper {

    @Insert("INSERT into user(userId,username,password,usersex,school) VALUES(#{userId},#{username},#{password},#{usersex},#{school}) ")
    int saveUser(@Param("userId") String userId, @Param("username") String username, @Param("password") String password, @Param("usersex") String usersex, @Param("school") String school);

    @Select("select userId,username,password,usersex,school from user where userId=#{userId}")
    User selectUser(String userId);
}

User实体类

package com.example.demowx.entity;
import lombok.Data;

@Data
public class User {
    private String userId; 
    private String username;
    private String password;
    private String usersex;
    private String school;
}

UserController控制层

package com.example.demowx.controller;

import com.example.demowx.entity.User;
import org.apache.ibatis.jdbc.Null;
import org.springframework.util.StringUtils;

import com.example.demowx.mapper.UserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.Writer;
import java.util.List;


@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @ResponseBody
    @GetMapping("login")
    public Object login(String userId,String password, HttpServletResponse response){

        User user=userMapper.selectUser(userId);

        if (user==null){ //判断对象为不为空, 判断对象的属性为不为空会报空指针错误

            return 2;
        }
        if(password.equals(user.getPassword())){

            return user;
          }
        return 0;
    }

    @ResponseBody
    @RequestMapping("register")
    public int register(String userId,String username,String password,String usersex,String school){

        User user=userMapper.selectUser(userId);
        if(user!=null){
            return 1;//用户已经存在
        }

        int resultCount=userMapper.saveUser(userId,username,password,usersex,school);
        if(resultCount==0){
            return 0;//注册失败
        }
        return 2;//注册成功
    }


    @ResponseBody
    @GetMapping("getOne")
    public User login(String userId, HttpServletResponse response) {
        User user=userMapper.selectUser(userId);
        return user;
    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山山峏川-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值