基于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管理等等。
/**
* <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);
}
/**
* 获取树形的权限树
*/
@GetMapping
public Result getListByTree() {
resultItem.put("name",i.getName());
List<Category> categories1 = categoryService.list(wrapper);
String ids = categories1.stream().map(j->j.getId().toString()).collect(Collectors.joining(","));
log.info("ids: {}",ids);
List<Map<String, Object>> goods = goodsService.getIndexGood(ids);
if (goods!=null&&goods.size()==6){
resultItem.put("goods",goods);
result.add(resultItem);
}
}
return Result.getSuccessResult(result);
}
/**
* 向表中添加一条记录
*/
@PostMapping("/user/register")
public Result save(@RequestBody User user) {
user.setRoleId(4);
if (StringUtils.isEmpty(user.getPassword())){
user.setPassword(ShaUtil.getSHA256("123456"));
} else {
user.setPassword(ShaUtil.getSHA256(user.getPassword()));
}
if (userService.save(user)){
return Result.getSuccessResult("","注册成功");
}
return Result.getFailResult("","注册失败");
}
/**
* 商品搜索
* @param param
* @return
*/
@GetMapping("/goods/search")
public Result getList(@RequestParam Map<String, Object> param) {
int num = 1;
if (!StringUtils.isEmpty(param.get("page"))){
num = Integer.parseInt(param.get("page").toString());
}
QueryWrapper<Goods> wrapper = new QueryWrapper<>();
wrapper.eq("active",1);
Object name = param.get("name");
if (!StringUtils.isEmpty(name)) {
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/goods")
public class GoodsController {
@Value("${server.port}")
private String port;
@Resource
private IGoodsService iGoodsService;
/**
* 进行分页查询
*/
@GetMapping
public Result getList(@RequestParam Map<String, Object> param) {
InitUtil.initPage(param);
int num = Integer.parseInt(param.get("page").toString());
int limit = Integer.parseInt(param.get("limit").toString());
QueryWrapper<Goods> wrapper = new QueryWrapper<>();
InitUtil.initEq(param, wrapper, "active","user_id");
IPage<Goods> page = new Page<>(num, limit);
return Result.getSuccessResult(iGoodsService.page(page, wrapper));
}
}
/**
* 根据用户的角色类型获取菜单
*/
@GetMapping("/userPermissionList")
public Result userPermissionList(HttpServletRequest request){
int userId = JwtUtil.getUserId(request);
User user = userService.getById(userId);
if (user==null) {
throw new UserNoLoginException();
}
return Result.getSuccessResult(iPermissionService.userPermissionList(user.getRoleId()));
}
/**
* name : 需要检查那个字段的value是否在数据库存在
* 比如/check/RegistworkName?value=阿司匹林 :检查数据库是否存在RegistworkName='阿司匹林'
*/
@GetMapping("/check/{name}")
public Result checkName(@PathVariable String name,@RequestParam String value){
QueryWrapper<Permission> wrapper = new QueryWrapper<>();
wrapper.eq(name, value);
if (iPermissionService.getOne(wrapper) != null){
return Result.getFailResult();
}
return Result.getSuccessResult();
}
/**
* 向表中添加一条记录
*/
@PostMapping()
public Result save(@RequestBody Permission iPermission) {
if (iPermissionService.save(iPermission)){
return Result.getSuccessResult("","添加成功");
}
return Result.getFailResult("","添加失败");
}
/**
wrapper.eq(name, value);
if (iGoodsService.getOne(wrapper) != null){
return Result.getFailResult();
}
return Result.getSuccessResult();
}
/**
* 向表中添加一条记录
*/
@PostMapping()
public Result save(@RequestBody Goods iGoods){
if (iGoodsService.save(iGoods)){
return Result.getSuccessResult("","添加成功");
}
return Result.getFailResult("","添加失败");
}
/**
* 根据表中的主键修改 根据表中字段相应的修改,如果存在则修改
*/
@PutMapping("/{id}")
public Result update(@RequestBody Goods iGoods, @PathVariable int id) {
iGoods.setId(id);
if (iGoodsService.updateById(iGoods)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=1 有效
*/
@PutMapping("/back/{id}")
public Result back(@PathVariable int id) {
Goods iGoods = new Goods();
iGoods.setId(id);
iGoods.setActive(1);
if (iGoodsService.updateById(iGoods)){
return Result.getSuccessResult("","激活成功");
}
return Result.getFailResult("","激活失败");
}
/**
* active 字段 相当于激活一样 设置字段的有效性 active=0 无效 逻辑删除
*/
@PutMapping("/del/{id}")
public Result loginDel(@PathVariable int id) {
}
/**
* 进行分页查询
*/
@GetMapping
public Result getList(HttpServletRequest request) {
QueryWrapper<Address> wrapper = new QueryWrapper<>();
String token = request.getHeader("Authorization");
int userId = JWT.decode(token).getClaim("id").asInt();
wrapper.eq("active",1).eq("user_id",userId);
return Result.getSuccessResult(iAddressService.list());
}
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Address iAddress = iAddressService.getById(id);
if (iAddress == null) {
return Result.getFailResult("","无记录");
}
return Result.getSuccessResult(iAddress);
}
/**
* 向表中添加一条记录
*/
@PostMapping()
public Result save(@RequestBody Address iAddress,HttpServletRequest request) {
QueryWrapper<Address> wrapper = new QueryWrapper<>();
String token = request.getHeader("Authorization");
int userId = JWT.decode(token).getClaim("id").asInt();
iAddress.setUserId(userId);
if (iAddressService.save(iAddress)){
return Result.getSuccessResult("","添加成功");
}
return Result.getFailResult("","添加失败");
}
/**
* 根据表中的主键修改 根据表中字段相应的修改,如果存在则修改
*/
@PutMapping("/{id}")
public Result update(@RequestBody Address iAddress, @PathVariable int id,HttpServletRequest request) {
judge(request,id);
iAddress.setId(id);
if (iAddressService.updateById(iAddress)){
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("/admin/send/{id}")
public Result send(@PathVariable int id){
if (orderDetailService.send(id)>0){
return Result.getSuccessResult("发货成功");
}
return Result.getFailResult("","发货失败");
}
/**
* 收货
*/
@PutMapping("/receive/{id}")
public Result receive(@PathVariable int id){
if (orderDetailService.receive(id)>0){
return Result.getSuccessResult("收货成功");
}
return Result.getFailResult("","收货失败");
}
/**
* 获取支付信息
*/
@GetMapping("/pay/{id}")
@Transactional(readOnly = true)
public Result getPay(@PathVariable String id){
QueryWrapper<Pay> wrapper = new QueryWrapper<>();
wrapper.eq("platform_number",id);
return Result.getSuccessResult(payService.getOne(wrapper));
}
/**
* 获取所有的订单信息
*/
@GetMapping("/admin")
public Result getOrderItems(@RequestParam Map<String,Object> param,HttpServletRequest request){
return Result.getSuccessResult(orderDetailService.getOrderItem(param,JwtUtil.getUserId(request)));
}
/**
* 获取用户购买的所有商品
*/
@GetMapping("/goods")
public Result getAllOrder(HttpServletRequest request){
QueryWrapper<Orderdetail> wrapper = new QueryWrapper<>();
wrapper.eq("user_id",JwtUtil.getUserId(request));
/**
* <p>
* 角色 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/roles")
public class RoleController {
@Resource
private IRoleService iRoleService;
/**
* 进行分页查询
*/
@GetMapping
public Result getList(@RequestParam Map<String, Object> param) {
InitUtil.initPage(param);
int num = Integer.parseInt(param.get("page").toString());
int limit = Integer.parseInt(param.get("limit").toString());
QueryWrapper<Role> wrapper = new QueryWrapper<>();
InitUtil.initLike(param, wrapper, "name");
InitUtil.initEq(param, wrapper, "active");
IPage<Role> page = new Page<>(num, limit);
return Result.getSuccessResult(iRoleService.page(page, wrapper));
}
/**
* 获取所有角色
* @return
*/
@GetMapping("/all")
public Result getAll() {
QueryWrapper<Role> wrapper = new QueryWrapper<>();
wrapper.eq("active", 1);
JSONObject jsonObject = new JSONObject();
List<Role> list = iRoleService.list(wrapper);
for (Role i : list) {
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 (iCategoryService.removeById(id)){
return Result.getSuccessResult("","删除成功");
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@Slf4j
@RequestMapping("/users")
public class UserController {
@Resource
private IUserService iUserService;
/**
* 进行分页查询
*/
@GetMapping
public Result getList(@RequestParam Map<String, Object> param) {
InitUtil.initPage(param);
InitUtil.initEq(param, wrapper, "active");
IPage<Role> page = new Page<>(num, limit);
return Result.getSuccessResult(iRoleService.page(page, wrapper));
}
/**
* 获取所有角色
* @return
*/
@GetMapping("/all")
public Result getAll() {
QueryWrapper<Role> wrapper = new QueryWrapper<>();
wrapper.eq("active", 1);
JSONObject jsonObject = new JSONObject();
List<Role> list = iRoleService.list(wrapper);
for (Role i : list) {
jsonObject.put(i.getId().toString(), new HashMap<String, String>(){{
put("name",i.getName());
}}
);
}
return Result.getSuccessResult(jsonObject);
}
/**
* 通过主键id在表中查找信息
*/
@GetMapping("/{id}")
public Result getById(@PathVariable int id) {
Role iRole = iRoleService.getById(id);
if (iRole == null) {
return Result.getFailResult("","无记录");
}
return Result.getSuccessResult(iRole);
}
/**
* name : 需要检查那个字段的value是否在数据库存在
* 比如/check/RegistworkName?value=阿司匹林 :检查数据库是否存在RegistworkName='阿司匹林'
*/
@GetMapping("/check/{name}")
public Result checkName(@PathVariable String name,@RequestParam String value){
QueryWrapper<Role> wrapper = new QueryWrapper<>();
wrapper.eq(name, value);
if (iRoleService.getOne(wrapper) != null){
return Result.getFailResult();
}
return Result.getSuccessResult();
}
.withHeader(header)
.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());
}
}
* 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("","批量失效成功");
}
/**
* 在数据表中真正的删除一条记录
*/
@DeleteMapping("/{id}")
public Result delById(@PathVariable int id) {
if (iPayService.removeById(id)){
return Result.getSuccessResult("","删除成功");
}
return Result.getFailResult("","删除失败");
}
}
return JWT.create()
.withHeader(header)
.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);
public Result getById(@PathVariable int id) {
Goods iGoods = iGoodsService.getById(id);
if (iGoods == null) {
return Result.getFailResult("","无记录");
}
return Result.getSuccessResult(iGoods);
}
/**
* name : 需要检查那个字段的value是否在数据库存在
* 比如/check/RegistworkName?value=阿司匹林 :检查数据库是否存在RegistworkName='阿司匹林'
*/
@GetMapping("/check/{name}")
public Result checkName(@PathVariable String name,@RequestParam String value){
QueryWrapper<Goods> wrapper = new QueryWrapper<>();
wrapper.eq(name, value);
if (iGoodsService.getOne(wrapper) != null){
return Result.getFailResult();
}
return Result.getSuccessResult();
}
/**
* 向表中添加一条记录
*/
@PostMapping()
public Result save(@RequestBody Goods iGoods){
if (iGoodsService.save(iGoods)){
return Result.getSuccessResult("","添加成功");
}
return Result.getFailResult("","添加失败");
}
/**
* 根据表中的主键修改 根据表中字段相应的修改,如果存在则修改
*/
@PutMapping("/{id}")
public Result update(@RequestBody Goods iGoods, @PathVariable int id) {
iGoods.setId(id);
if (iGoodsService.updateById(iGoods)){
return Result.getSuccessResult("","修改成功");
}
return Result.getFailResult("","修改失败");
}
*/
@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("/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);