其他分享
首页 > 其他分享> > SpringBoot商城系统

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<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);
}
}

}

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

标签:RequestMapping,return,SpringBoot,系统,user,import,public,商城,httpSession
来源: https://www.cnblogs.com/xiao123456789/p/16342110.html