注意:本商城系統(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