作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
基于SpringBoot手机商城 有前台和后台
用户可以登录注册 收藏商品 购物车 结算商品 收货地址管理等
管理员则可以对用户,商品,订单进行管理操作
使用人群:
正在做毕设的学生,或者需要项目实战练习的Java学习者
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;
技术栈
后端:SpringBot(Spring+SpringMVC+Mybatis)
前端: HTML+Layui+thymeleaf
使用说明
项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,运行成功后在浏览器中输入地址:
前台地址:http://localhost:8080
用户名密码:321/123
后台地址: http://localhost:8080/adminLogin
管理员账号密码:12580/123
运行截图
前台界面
后管界面
相关代码
GoodController
package com.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.common.utils.DateUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pojo.Comment;
import com.pojo.Good;
import com.pojo.User;
import com.pojo.result.Result;
import com.pojo.result.ResultPage;
import com.service.CommentService;
import com.service.GoodService;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* <p>
* 积分物品表 前端控制器
* </p>
*
* @author chen
* @since 2022-01-30
*/
@RestController
@RequestMapping("/good")
public class GoodController {
@Autowired
private GoodService goodService;
@Autowired
private UserService userService;
@Autowired
private CommentService commentService;
//添加商品
@PostMapping("/add")
public Result add(Good good) {
//验证表单信息
if (goodService.getOne(new LambdaQueryWrapper<Good>().eq(Good::getName, good.getName())) != null) {
return Result.failure("已有相同名称的商品,请重新命名");
} else {
return Result.decide(goodService.save(good));
}
}
//删除商品
@PostMapping("/delete")
public Result delete(@RequestParam(value = "id") String id) {
return Result.decide(goodService.removeById(id));
}
//修改商品
@PostMapping("/update")
public Result update(Good good) {
Good currentGood = goodService.getById(good.getId());
//验证表单信息
if (goodService.getOne(new LambdaQueryWrapper<Good>().eq(Good::getName, good.getName())) != null
&& !good.getName().equals(currentGood.getName())) {
return Result.failure("已有相同名称的商品,请重新命名");
} else {
return Result.decide(goodService.updateById(good));
}
}
//根据id获取商品
@PostMapping("/getOne")
public Result getOne(@RequestParam(value = "id") String id) {
return Result.success(goodService.getById(id));
}
//条件分页获取分类
@RequestMapping("/getAll")
public ResultPage getAll(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "page") Integer page,
@RequestParam(value = "limit") Integer limit) {
//分页条件
PageHelper.startPage(page, limit);
List<Good> bookList = goodService.getAll(name, categoryId);
PageInfo<Good> goodPageInfo = new PageInfo<>(bookList, limit);
return new ResultPage(0, (int) goodPageInfo.getTotal(), goodPageInfo.getList());
}
//前台获取全部商品
@RequestMapping("/getAllGood")
public ModelAndView getAllGood(String goodName, String categoryId) {
ModelAndView mv = new ModelAndView();
LambdaQueryWrapper<Good> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Good::getStatus, 1);
if (!StringUtils.isEmpty(goodName)) {
queryWrapper.like(Good::getName, goodName);
}
if (!StringUtils.isEmpty(categoryId)) {
queryWrapper.like(Good::getCategoryId, categoryId);
}
mv.addObject("goodList", goodService.list(queryWrapper));
mv.setViewName("index/goodList.html");
return mv;
}
//前台获取商品详情信息
@RequestMapping("/getGoodDetail")
public ModelAndView getGoodDetail(String goodId) {
ModelAndView mv = new ModelAndView();
//商品信息
mv.addObject("good", goodService.getById(goodId));
//评论信息
LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Comment::getGoodId, goodId);
List<Comment> ls = commentService.list(queryWrapper);
for (Comment comment : ls) {
User user = userService.getById(comment.getUserId());
comment.setUserAvatar(user.getAvatar());
comment.setUserName(user.getName());
comment.setFmtDateTime(DateUtils.dateFmt(comment.getCreateTime()));
}
mv.addObject("commentList", ls);
mv.setViewName("index/goodDetail.html");
return mv;
}
}
GoodCategoryController
package com.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pojo.GoodCategory;
import com.pojo.User;
import com.pojo.result.Result;
import com.pojo.result.ResultPage;
import com.service.GoodCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import java.util.List;
import java.util.Locale;
/**
* <p>
* 帖子分类表 前端控制器
* </p>
*
* @author chen
* @since 2022-01-30
*/
@RestController
@RequestMapping("/category")
public class GoodCategoryController {
@Autowired
private GoodCategoryService categoryService;
//添加分类
@PostMapping("/add")
public Result add(GoodCategory category) {
//验证表单信息
if (categoryService.getOne(new LambdaQueryWrapper<GoodCategory>().eq(GoodCategory::getName,category.getName())) != null) {
return Result.failure("已有相同名称的类别,请重新命名");
} else {
return Result.decide(categoryService.save(category));
}
}
//通过id获取分类
@RequestMapping("/getOne")
public GoodCategory getOne(@RequestParam(value = "id") String id) {
return categoryService.getById(id);
}
//删除分类
@PostMapping("/delete")
public Result delete(@RequestParam(value = "id") String id) {
return Result.decide(categoryService.removeById(id));
}
//修改分类
@PostMapping("update")
public Result update(GoodCategory category) {
GoodCategory categoryEdit = categoryService.getById(category.getId());
//验证表单信息
if (categoryService.getOne(new LambdaQueryWrapper<GoodCategory>().eq(GoodCategory::getName,category.getName())) != null
&& !categoryEdit.getName().equals(category.getName())) {
return Result.failure("已有相同名称的类别,请重新命名");
} else {
return Result.decide(categoryService.updateById(category));
}
}
//分页条件查询分类信息
@RequestMapping("/getAll")
public ResultPage getAll(GoodCategory category,
@RequestParam(value = "page") Integer page,
@RequestParam(value = "limit") Integer limit) {
//查询条件
LambdaQueryWrapper<GoodCategory> userWrapper = new LambdaQueryWrapper<>();
if (StringUtils.hasText(category.getName())) {
userWrapper.like(GoodCategory::getName, category.getName());
}
//分页条件
Page<GoodCategory> categoryPage = new Page<>(page, limit);
IPage<GoodCategory> pageData = categoryService.page(categoryPage, userWrapper);
return new ResultPage(0, (int) pageData.getTotal(), pageData.getRecords());
}
//获取全部分类,用于下拉框选择
@GetMapping("/getAllCategory")
public Result getAllCategory() {
return Result.success(categoryService.query().list());
}
}
ViewController
package com.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pojo.Banner;
import com.pojo.Good;
import com.service.BannerService;
import com.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* <p>
* 前端控制器
* </p>
*
* @author chen
* @since 2022-01-30
*/
@Controller
public class ViewController {
@Autowired
private BannerService bannerService;
@Autowired
private GoodService goodService;
/*
* ==================================================后台管理页面========================================================================
* */
//后台登录界面
@GetMapping("/adminLogin")
public ModelAndView loginPage() {
ModelAndView mv = new ModelAndView();
mv.setViewName("/login.html");
return mv;
}
//管理员界面
@GetMapping("/adminIndex")
public ModelAndView adminIndex() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/admin.html");
return mv;
}
//用户列表界面
@GetMapping("/userList")
public ModelAndView userList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/user/userList.html");
return mv;
}
//添加用户界面
@GetMapping("/userAdd")
public ModelAndView userAdd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/user/userAdd.html");
return mv;
}
//修改用户界面
@GetMapping("/userEdit")
public ModelAndView userEdit() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/user/userEdit.html");
return mv;
}
//商品分类列表页面
@GetMapping("/categoryList")
public ModelAndView categoryList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/category/categoryList.html");
return mv;
}
//添加商品分类列表页面
@GetMapping("/categoryAdd")
public ModelAndView categoryAdd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/category/categoryAdd.html");
return mv;
}
//修改商品分类列表页面
@GetMapping("/categoryEdit")
public ModelAndView categoryEdit() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/category/categoryEdit.html");
return mv;
}
//商品列表页面
@GetMapping("/goodList")
public ModelAndView goodList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/good/goodList.html");
return mv;
}
//添加商品列表页面
@GetMapping("/goodAdd")
public ModelAndView goodAdd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/good/goodAdd.html");
return mv;
}
//修改商品列表页面
@GetMapping("/goodEdit")
public ModelAndView goodEdit() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/good/goodEdit.html");
return mv;
}
//管理员订单页面
@GetMapping("/adminOrderList")
public ModelAndView adminOrderList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/order/orderList.html");
return mv;
}
//轮播图列表页面
@GetMapping("/bannerList")
public ModelAndView bannerList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/banner/bannerList.html");
return mv;
}
//添加商品列表页面
@GetMapping("/bannerAdd")
public ModelAndView bannerAdd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/banner/bannerAdd.html");
return mv;
}
//修改商品列表页面
@GetMapping("/bannerEdit")
public ModelAndView bannerEdit() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/banner/bannerEdit.html");
return mv;
}
//评论页面
@GetMapping("/commentList")
public ModelAndView commentList() {
ModelAndView mv = new ModelAndView();
mv.setViewName("admin/comment/commentList.html");
return mv;
}
/*
* ==================================================前台页面========================================================================
* */
//商城主页面
@GetMapping("/")
public ModelAndView index() {
ModelAndView mv = new ModelAndView();
//获取轮播图
LambdaQueryWrapper<Banner> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Banner::getSelected, 1);
//热门商品
LambdaQueryWrapper<Good> goodWrapper = new LambdaQueryWrapper<>();
goodWrapper
.eq(Good::getStatus, 1)
.orderByDesc(Good::getSales)
.last("limit 4");
mv.addObject("goodList", goodService.list(goodWrapper));
mv.addObject("bannerList", bannerService.list(queryWrapper));
mv.setViewName("index/index.html");
return mv;
}
//前台登录界面
@GetMapping("/userLogin")
public ModelAndView UserloginPage() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/login.html");
return mv;
}
//用户注册界面
@GetMapping("/register")
public ModelAndView register() {
ModelAndView mv = new ModelAndView();
mv.setViewName("register.html");
return mv;
}
//用户修改密码界面
@GetMapping("/updatePwd")
public ModelAndView updatePwd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/user_pwd.html");
return mv;
}
//用户收货地址管理界面
@GetMapping("/userAddress")
public ModelAndView userAddress() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/user_address.html");
return mv;
}
//用户修收货地址界面
@GetMapping("/addressEdit")
public ModelAndView addressEdit() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/user_addressEdit.html");
return mv;
}
//商品评价页面
@GetMapping("/order/userComment")
public ModelAndView comment() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/comment.html");
return mv;
}
}
如果也想学习本系统,下面领取。关注并回复:165springboot