SpringBoot實現(xiàn)商城系統(tǒng)

注意:本商城系統(tǒng)無后臺管理功能和頁面

技術(shù)架構(gòu):

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<Prefer> 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<Common> 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);

? ? ? ? }

? ? }

}

系統(tǒng)演示地址:

鏈接:https://pan.baidu.com/s/1rpqBqlh08b2wahi1DnCk-Q

提取碼:7q7q

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容