基于javaweb+mysql的springboot在线商城系统(前后端分离+java+vue+springboot+ssm+mysql+maven)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线商城系统(前后端分离+java+vue+springboot+ssm+mysql+maven)
一、项目简述
本系统功能包括: 前台展示+后台管理,包括最基本的用户登录注册,下单, 购物车,购买,结算,订单查询,收货地址,后台商品管 理,订单管理,用户管理等等功能,小伙伴一起来看看 吧。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
项目技术: Springboot + Maven + Mybatis + Vue + HTML 等 等组成,B/S模式+ Maven管理等等。
iShoppingcartService.updateById(iShoppingcart);
}
return Result.getSuccessResult("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
*/
@DeleteMapping("/{id}")
public Result delById(@PathVariable int id) {
if (iShoppingcartService.removeById(id)){
return Result.getSuccessResult("","删除成功");
}
return Result.getFailResult("","删除失败");
}
}
package com.ysu.shop.controller;
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
* 权限 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/permissions")
public class PermissionController {
@Resource
private IPermissionService iPermissionService;
@Resource
private IUserService userService;
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Permission iPermission = iPermissionService.getById(id);
if (iPermission == null) {
return Result.getFailResult("", "无记录");
}
return Result.getSuccessResult(iPermission);
}
/**
* 获取树形的权限树
*/
@GetMapping
public Result getListByTree() {
return Result.getSuccessResult(iPermissionService.listByTree());
}
/**
* 获取所有的一级权限
* @return
*/
*/
@PutMapping("/update")
public Result update(@RequestBody User user,HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
if (!StringUtils.isEmpty(user.getPassword())){
user.setPassword(null);
}
if (!StringUtils.isEmpty(user.getUsername())){
user.setUsername(null);
}
if (!StringUtils.isEmpty(user.getAnswer())){
user.setAnswer(null);
}
if (!StringUtils.isEmpty(user.getQuestion())){
user.setQuestion(null);
}
if (userService.updateById(user)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
/**
* 修改密码
* @param request
* @return
*/
@PutMapping("/updatePwd")
public Result updatePwd(@RequestBody Map<String,Object> param, HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
String oldPwd = ShaUtil.getSHA256(param.get("oldPwd").toString());
String newPwd = ShaUtil.getSHA256(param.get("newPwd").toString());
if (userService.updatePwd(userId,oldPwd,newPwd)>0){
return Result.getSuccessResult("","修改密码成功");
}
return Result.getFailResult("","原密码不正确,修改密码失败");
}
/**
* 修改密码
* @param request
* @return
*/
@PutMapping("/updatePwdByAnswer")
Category iCategory = new Category();
iCategory.setId(id);
iCategory.setActive(1);
if (iCategoryService.updateById(iCategory)){
return Result.getSuccessResult("","激活成功");
}
return Result.getFailResult("","激活失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=0 无效 逻辑删除
*/
@PutMapping("/del/{id}")
public Result loginDel(@PathVariable int id) {
Category iCategory = new Category();
iCategory.setId(id);
iCategory.setActive(0);
if (iCategoryService.updateById(iCategory)){
return Result.getSuccessResult("","设置失效成功");
}
return Result.getFailResult("","设置失效失败");
}
/**
* 批量设置 active=0
*/
@PutMapping("/batchDel")
public Result LoginBatchDel(@RequestParam String ids) {
Category iCategory = new Category();
iCategory.setActive(0);
String[] idList = ids.split(",");
for (String id : idList) {
iCategory.setId(Integer.parseInt(id));
iCategoryService.updateById(iCategory);
}
return Result.getSuccessResult("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
*/
@DeleteMapping("/{id}")
public Result delById(@PathVariable int id) {
if (id<20) {
return Result.getFailResult("","不能删除系统预留项");
}
if (userService.updateById(user)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
/**
* 修改密码
* @param request
* @return
*/
@PutMapping("/updatePwd")
public Result updatePwd(@RequestBody Map<String,Object> param, HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
String oldPwd = ShaUtil.getSHA256(param.get("oldPwd").toString());
String newPwd = ShaUtil.getSHA256(param.get("newPwd").toString());
if (userService.updatePwd(userId,oldPwd,newPwd)>0){
return Result.getSuccessResult("","修改密码成功");
}
return Result.getFailResult("","原密码不正确,修改密码失败");
}
/**
* 修改密码
* @param request
* @return
*/
@PutMapping("/updatePwdByAnswer")
public Result updatePwdByAnswer(@RequestBody Map<String,Object> param, HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
String answer = ShaUtil.getSHA256(param.get("answer").toString());
String newPwd = ShaUtil.getSHA256(param.get("newPwd").toString());
if (userService.updatePwdByAnswer(userId,answer,newPwd)>0){
return Result.getSuccessResult("","修改密码成功");
}
return Result.getFailResult("","修改密码失败");
}
}
package com.ysu.shop.controller;
*/
@RestController
@Slf4j
@RequestMapping("/shopping-cart")
public class ShoppingcartController {
@Resource
private IShoppingcartService iShoppingcartService;
/**
* 进行分页查询
*/
@GetMapping
public Result getList(HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
QueryWrapper<Shoppingcart> wrapper = new QueryWrapper<>();
wrapper.eq("user_id",userId);
return Result.getSuccessResult(iShoppingcartService.list(wrapper));
}
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Shoppingcart iShoppingcart = iShoppingcartService.getById(id);
if (iShoppingcart == null) {
return Result.getFailResult("","无记录");
}
return Result.getSuccessResult(iShoppingcart);
}
/**
* name : 需要检查那个字段的value是否在数据库存在
* 比如/check/RegistworkName?value=阿司匹林 :检查数据库是否存在RegistworkName='阿司匹林'
*/
@GetMapping("/check/{name}")
public Result checkName(@PathVariable String name,@RequestParam String value){
QueryWrapper<Shoppingcart> wrapper = new QueryWrapper<>();
wrapper.eq(name, value);
if (iShoppingcartService.getOne(wrapper) != null){
return Result.getFailResult();
}
return Result.getSuccessResult();
}
/**
* 向表中添加一条记录
return user;
}
public static int getUserId(HttpServletRequest request){
String token = request.getHeader("Authorization");
return JWT.decode(token).getClaim("id").asInt();
}
public static User getUser(String token){
try {
User user = new User();
user.setId(JWT.decode(token).getClaim("id").asInt());
user.setUsername(JWT.decode(token).getClaim("username").asString());
return user;
}catch (Exception e) {
e.printStackTrace();
throw new MyException(e.getMessage());
}
}
public static void main(String[] args){
User user = new User();
user.setId(1);
user.setUsername("admin");
System.out.println(user);
String token = create(user);
System.out.println("-------------------token----------------");
System.out.println(getUser(token));
}
}
package com.ysu.shop.client;
* active 字段 相当于激活一样 设置字段的有效性 active=1 有效
*/
@PutMapping("/back/{id}")
public Result back(@PathVariable int id) {
Role iRole = new Role();
iRole.setId(id);
iRole.setActive(1);
if (iRoleService.updateById(iRole)){
return Result.getSuccessResult("","激活成功");
}
return Result.getFailResult("","激活失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=0 无效 逻辑删除
*/
@PutMapping("/del/{id}")
public Result loginDel(@PathVariable int id) {
Role iRole = new Role();
iRole.setId(id);
iRole.setActive(0);
if (iRoleService.updateById(iRole)){
return Result.getSuccessResult("","设置失效成功");
}
return Result.getFailResult("","设置失效失败");
}
/**
* 批量设置 active=0
*/
@PutMapping("/batchDel")
public Result LoginBatchDel(@RequestParam String ids) {
Role iRole = new Role();
iRole.setActive(0);
String[] idList = ids.split(",");
for (String id : idList) {
iRole.setId(Integer.parseInt(id));
iRoleService.updateById(iRole);
}
return Result.getSuccessResult("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
*/
@DeleteMapping("/{id}")
public Result LoginBatchDel(@RequestParam String ids) {
Shoppingcart iShoppingcart = new Shoppingcart();
iShoppingcart.setActive(0);
String[] idList = ids.split(",");
for (String id : idList) {
iShoppingcart.setId(Integer.parseInt(id));
iShoppingcartService.updateById(iShoppingcart);
}
return Result.getSuccessResult("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
*/
@DeleteMapping("/{id}")
public Result delById(@PathVariable int id) {
if (iShoppingcartService.removeById(id)){
return Result.getSuccessResult("","删除成功");
}
return Result.getFailResult("","删除失败");
}
}
package com.ysu.shop.controller;
/**
* <p>
@Resource
private IUserService userService;
@GetMapping("/info")
public Result getUserById(HttpServletRequest request){
User user = userService.getUserById(JwtUtil.getUserId(request));
return Result.getSuccessResult(user);
}
/**
* 修改用户信息
*/
@PutMapping("/update")
public Result update(@RequestBody User user,HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
if (!StringUtils.isEmpty(user.getPassword())){
user.setPassword(null);
}
if (!StringUtils.isEmpty(user.getUsername())){
user.setUsername(null);
}
if (!StringUtils.isEmpty(user.getAnswer())){
user.setAnswer(null);
}
if (!StringUtils.isEmpty(user.getQuestion())){
user.setQuestion(null);
}
if (userService.updateById(user)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
/**
* 修改密码
* @param request
* @return
*/
@PutMapping("/updatePwd")
public Result updatePwd(@RequestBody Map<String,Object> param, HttpServletRequest request) {
int userId = JwtUtil.getUserId(request);
String oldPwd = ShaUtil.getSHA256(param.get("oldPwd").toString());
String newPwd = ShaUtil.getSHA256(param.get("newPwd").toString());
/**
* <p>
* 用户权限表 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/role-permissions")
public class RolePermissionController {
@Resource
private IRolePermissionService iRolePermissionService;
@GetMapping("/{id}")
public Result getRightsById(@PathVariable int id) {
QueryWrapper<RolePermission> wrapper = new QueryWrapper<>();
wrapper.eq("role_id", id);
RolePermission role = iRolePermissionService.getOne(wrapper);
if (role == null) {
return Result.getFailResult("该角色尚未分配权限");
}
return Result.getSuccessResult(role);
}
@PostMapping()
public Result add(@RequestBody RolePermission entity) {
if (iRolePermissionService.save(entity))
return Result.getSuccessResult("", "分配权限成功!");
return Result.getFailResult("", "分配权限失败");
}
@PutMapping("/{id}")
public Result add(@RequestBody RolePermission entity,@PathVariable int id) {
entity.setId(id);
if (iRolePermissionService.updateById(entity))
return Result.getSuccessResult("", "修改分配权限成功!");
return Result.getFailResult("", "修改分配权限失败");
/**
* <p>
* 权限 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/permissions")
public class PermissionController {
@Resource
private IPermissionService iPermissionService;
@Resource
private IUserService userService;
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Permission iPermission = iPermissionService.getById(id);
if (iPermission == null) {
return Result.getFailResult("", "无记录");
}
return Result.getSuccessResult(iPermission);
}
.withClaim("id", user.getId())
.withClaim("username",user.getUsername())
.withExpiresAt(new Date(System.currentTimeMillis() + EXPIRE_TIME))
.sign(Algorithm.HMAC256(KEY));
}
public static void isExpire(String token){
if(System.currentTimeMillis() - JWT.decode(token).getExpiresAt().getTime() > 0 ){
throw new MyException("登录已过期,请重新登录");
}
}
/**
* 通过token串 获取id信息,然后从数据库中获取信息
* @param token
* @return
*/
public static User getUserById(String token){
Integer userId = JWT.decode(token).getClaim("id").asInt();
System.out.println(userService+":"+userId);
User user = userService.getUserById(userId);
if (user == null){
throw new UserNoLoginException();
}
return user;
}
public static int getUserId(HttpServletRequest request){
String token = request.getHeader("Authorization");
return JWT.decode(token).getClaim("id").asInt();
}
public static User getUser(String token){
try {
User user = new User();
user.setId(JWT.decode(token).getClaim("id").asInt());
user.setUsername(JWT.decode(token).getClaim("username").asString());
return user;
}catch (Exception e) {
e.printStackTrace();
throw new MyException(e.getMessage());
}
}
public static void main(String[] args){
User user = new User();
user.setId(1);
user.setUsername("admin");
System.out.println(user);
String token = create(user);
System.out.println("-------------------token----------------");
System.out.println(getUser(token));
}
}
@PutMapping("/{id}")
public Result update(@RequestBody Pay iPay, @PathVariable int id) {
iPay.setId(id);
if (iPayService.updateById(iPay)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=1 有效
*/
@PutMapping("/back/{id}")
public Result back(@PathVariable int id) {
Pay iPay = new Pay();
iPay.setId(id);
iPay.setActive(1);
if (iPayService.updateById(iPay)){
return Result.getSuccessResult("","激活成功");
}
return Result.getFailResult("","激活失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=0 无效 逻辑删除
*/
@PutMapping("/del/{id}")
public Result loginDel(@PathVariable int id) {
Pay iPay = new Pay();
iPay.setId(id);
iPay.setActive(0);
if (iPayService.updateById(iPay)){
return Result.getSuccessResult("","设置失效成功");
}
return Result.getFailResult("","设置失效失败");
}
/**
* 批量设置 active=0
*/
@PutMapping("/batchDel")
public Result LoginBatchDel(@RequestParam String ids) {
Pay iPay = new Pay();
iPay.setActive(0);
String[] idList = ids.split(",");
for (String id : idList) {
iPay.setId(Integer.parseInt(id));
iPayService.updateById(iPay);
}
return Result.getSuccessResult("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/category")
public class CategoryController {
@Resource
private ICategoryService iCategoryService;
@GetMapping
public Result getListByTree() {
return Result.getSuccessResult(iCategoryService.listByTree());
}
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Category iCategory = iCategoryService.getById(id);
if (iCategory == null) {
return Result.getFailResult("","无记录");
}
return Result.getSuccessResult(iCategory);
}
/**
* 获取所有角色
* @return
*/
@GetMapping("/all")
public Result getAll() {
QueryWrapper<Category> wrapper = new QueryWrapper<>();
wrapper.eq("active", 1);
}
package com.ysu.shop.utils;
@Component
public class JwtUtil {
private static IUserService userService;
@Resource
public void setUserService(IUserService userService) {
JwtUtil.userService = userService;
}
/**
* 过期时间为1天
*/
private static final long EXPIRE_TIME = 24*60*60*1000;
/**
* token私钥
*/
public static final String KEY = "ysu_user_shop";
public static String create(User user) {
HashMap<String, Object> header = new HashMap<>(2);
header.put("typ", "JWT");
System.out.println(userService+":"+userId);
User user = userService.getUserById(userId);
if (user == null){
throw new UserNoLoginException();
}
return user;
}
public static int getUserId(HttpServletRequest request){
String token = request.getHeader("Authorization");
return JWT.decode(token).getClaim("id").asInt();
}
public static User getUser(String token){
try {
User user = new User();
user.setId(JWT.decode(token).getClaim("id").asInt());
user.setUsername(JWT.decode(token).getClaim("username").asString());
return user;
}catch (Exception e) {
e.printStackTrace();
throw new MyException(e.getMessage());
}
}
public static void main(String[] args){
User user = new User();
user.setId(1);
user.setUsername("admin");
System.out.println(user);
String token = create(user);
System.out.println("-------------------token----------------");
System.out.println(getUser(token));
}
}
package com.ysu.shop.client;