栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot商城系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot商城系统

注意:本商城系统无后台管理功能和页面
技术架构:
springboot+mysql+mybatis+html+css+js
部分代码展示:
登录功能:

package com.moon.tmail.controller;

import com.moon.tmail.pojo.Common;
import com.moon.tmail.pojo.Prefer;
import com.moon.tmail.pojo.TabUser;
import com.moon.tmail.service.TabUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("user")
public class TabLoginController {
    @Autowired
    private TabUserService tabUserService;
    private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(6);

    @RequestMapping("login")
    public boolean login(@RequestBody TabUser user, HttpSession httpsession) {
        TabUser res = tabUserService.findbyphone(user.getPhone());
        if (res == null) {
            return false;
        }
        if (passwordEncoder.matches(user.getPassword(), res.getPassword())) {
            httpsession.setAttribute("userId", res.getId());
            httpsession.setAttribute("nickname", res.getNickname());
            httpsession.setAttribute("phone", res.getPhone());
            httpsession.setAttribute("address",res.getAddress());
            return true;
        }
        return false;
    }

    @RequestMapping("checkPrefer")
    public boolean prefer(HttpSession httpSession) {
        int userId = Integer.parseInt(httpSession.getAttribute("userId").toString());
        List prefers = tabUserService.findbyuserId(userId);
        if (prefers == null || prefers.size() == 0) {
            return true;
        }
        return false;
    }

    @RequestMapping("logout")
    public boolean logout(HttpSession httpSession) {
        httpSession.invalidate();
        return true;
    }

    @RequestMapping("checkLogin")
    public boolean isLogin(HttpSession httpSession) {
        if (httpSession.getAttribute("phone") == null || "".equals(httpSession.getAttribute("phone"))) {
            return false;
        }
        return true;
    }
    @RequestMapping("check/{phone}")
    public boolean isExist(@PathVariable String phone){
        Long p = Long.parseLong(phone);
        if(tabUserService.findbyphone(p)==null){
            return true;
        };
        return false;
    }
    @RequestMapping("register")
    public boolean register(@RequestBody TabUser user){
        user.setPassword(passwordEncoder.encode(user.getPassword()));
        user.setIsEmp(false);
        int i = tabUserService.add(user);
        if(i!=1) {
            return false;
        }
        return true;
    }
    @RequestMapping("addPrefer")
    public void addPrefer(@RequestBody List categories,HttpSession httpSession){
        Integer i = (Integer) httpSession.getAttribute("userId");
        for(Common c:categories){
            Prefer prefer = new Prefer();
            prefer.setUserId(i);
            prefer.setCategoryId(c.getCategoryId());
            tabUserService.addPrefer(prefer);
        }
    }

}

系统演示地址:
链接:https://pan.baidu.com/s/1rpqBqlh08b2wahi1DnCk-Q
提取码:7q7q

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/950688.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号