> 文章列表 > YC-A11(原创)基于springboot,vue网上商城

YC-A11(原创)基于springboot,vue网上商城

YC-A11(原创)基于springboot,vue网上商城

(原创)基于springboot,vue易淘网上商城定制版v4.0

本人原创作品,用户前台、系统管理员后台项目完整,无任何bug。

每行代码都是本人自己写,我在代码上面都写有详细注释

开发工具:IDEA

服务器:Tomcat9.0, jdk1.8

项目构建:maven

数据库:mysql5.7

系统分前后台,采用前后端分离

前端技术:vue (vue cli,vue-router,vuex全家桶),elementUI等框架实现

服务端技术:springboot,mybatis-plus

前台截图:

后台截图:

package lyp.itjiaochen.club.controller;import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiOperation;
import lyp.itjiaochen.club.pojo.User;
import lyp.itjiaochen.club.pojo.dto.RespBean;
import lyp.itjiaochen.club.pojo.dto.RespPageBean;
import lyp.itjiaochen.club.pojo.dto.query.UserQueryDto;
import lyp.itjiaochen.club.service.IUserService;
import lyp.itjiaochen.club.utils.Md5Util;
import lyp.itjiaochen.club.utils.SysConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** <p>*  前端控制器* </p>** @author IT教程资源* @since 2023-04-02*/
@RestController
@RequestMapping("/admin/user")
public class UserController {@Autowiredprivate IUserService iUserService;@ApiOperation("分页查询用户信息")@PostMapping("/getUserPage")public RespPageBean getUserPage(@RequestBody UserQueryDto queryDto){return iUserService.getUserPage(queryDto);}@ApiOperation("添加用户")@PostMapping("/addUser")public RespBean addUser(@RequestBody User user){//头像处理,如果为空,设置默认头像if(StringUtils.isBlank(user.getAvatar())){user.setAvatar(SysConstants.ADMIN_IMAGE_URL);}//设置默认密码123456user.setPassword(Md5Util.toMd5(SysConstants.ADMIN_DEFAULT_PASSWORD,SysConstants.PASSWORD_SALT,10));if(iUserService.save(user)){return RespBean.success("添加成功!");}return RespBean.error("添加失败!");}@ApiOperation(value = "检查账号是否可用")@GetMapping("/checkUsername")public RespBean checkUsername(String username){User user=iUserService.getUserByUserName(username);if(user!=null){return RespBean.error("账号已存在");}return RespBean.success("账号可用");}@ApiOperation("更新用户")@PutMapping("/updateUser")public RespBean updateUser(@RequestBody User user){if(iUserService.updateById(user)){return RespBean.success("更新成功!");}return RespBean.error("更新失败!");}@ApiOperation("删除用户")@DeleteMapping("/deleteUser")public RespBean deleteUser(@RequestBody User user){if(user!=null && iUserService.removeById(user.getId())){return RespBean.success("删除成功!");}return RespBean.error("删除失败!");}}
package lyp.itjiaochen.club.controller;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import lyp.itjiaochen.club.pojo.ProductEvaluation;
import lyp.itjiaochen.club.pojo.ProductEvaluationDetails;
import lyp.itjiaochen.club.pojo.dto.RespBean;
import lyp.itjiaochen.club.pojo.dto.RespPageBean;
import lyp.itjiaochen.club.pojo.dto.query.ProductEvaluationQueryDto;
import lyp.itjiaochen.club.service.IProductEvaluationDetailsService;
import lyp.itjiaochen.club.service.IProductEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.stream.Collectors;/*** <p>*  前端控制器* </p>** @author IT教程资源* @since 2023-04-04*/
@RestController
@RequestMapping("/admin/productEvaluation")
public class ProductEvaluationController {@Autowiredprivate IProductEvaluationService iProductEvaluationService;@Autowiredprivate IProductEvaluationDetailsService iProductEvaluationDetailsService;/*** @Author IT教程资源 2023/5/9 22:03* @Description 分页查询评论信息*/@ApiOperation("分页查询评论信息")@PostMapping("/getProductEvaluationPage")public RespPageBean getProductEvaluationPage(@RequestBody ProductEvaluationQueryDto queryDto){return iProductEvaluationService.getProductEvaluationPage(queryDto);}/*** @Author IT教程资源* @Date 2023/4/4 20:17* @Description 删除商品评论*/@ApiOperation("删除评论")@DeleteMapping("/deleteProductEvaluation")public RespBean deleteProductEvaluation(@RequestBody ProductEvaluation productEvaluation){//查询评论详情信息QueryWrapper<ProductEvaluationDetails> productEvaluationDetailsQueryWrapper=new QueryWrapper();productEvaluationDetailsQueryWrapper.eq("product_evaluation_id",productEvaluation.getId());List<ProductEvaluationDetails> productEvaluationDetails = iProductEvaluationDetailsService.list(productEvaluationDetailsQueryWrapper);//删除评论主表信息if(iProductEvaluationService.removeById(productEvaluation.getId())){//批量删除评论详情表记录if(productEvaluationDetails!=null && !productEvaluationDetails.isEmpty()){List<Integer> ids = productEvaluationDetails.stream().map(ProductEvaluationDetails::getId).collect(Collectors.toList());if(!iProductEvaluationDetailsService.removeByIds(ids)){return RespBean.error("删除失败!");};}return RespBean.success("删除成功!");}return RespBean.error("删除失败!");}}
<template><div style="margin-top: 30px;"><el-row><el-col :span="24" style="text-align: center;"><h1>填写并核对订单信息</h1></el-col></el-row><el-row style="text-align: left;border: 1px solid #EBEEF5;font-size: 25px;padding: 10px 12px 0;"><el-col :span="24"><strong>商品清单</strong></el-col></el-row><el-row><template><el-table:data="orders"borderstyle="width: 100%"><el-table-columnfixedlabel="商品"width="600"><template slot-scope="scope"><el-image :src="scope.row.product.imageUrl" fit="contain" style="width: 60px; height: 60px"@click="toProductInfo(scope.row.product.id)"></el-image><el-link :underline="false" @click="toProductInfo(scope.row.product.id)">{{ scope.row.product.name }}</el-link></template></el-table-column><el-table-columnlabel="单价"prop="product.shopPrice"width="275"></el-table-column><el-table-columnlabel="数量"prop="payAmount"width="300"></el-table-column><el-table-columnlabel="小计"><template slot-scope="scope">{{ scope.row.product.shopPrice | subTotal(scope.row.payAmount) }}</template></el-table-column></el-table></template></el-row><el-row><el-col :span="24" style="text-align: right;">总商品金额: <strongstyle="color:#e4393c;font-size:20px;">¥{{ getTotalPrice }}元</strong></el-col></el-row><el-row style="text-align: left;border: 1px solid #EBEEF5;font-size: 25px;margin-top: 20px;padding: 10px 12px 0;"><el-col :span="24"><strong>请选择收货地址</strong></el-col></el-row><el-row style="text-align: left;border: 1px solid #EBEEF5;"><template v-if="deliveryAddressList && deliveryAddressList.length>0"><el-radio-group v-model="deliveryAddressId"><template v-for="deliveryAddress in deliveryAddressList"><el-row style="margin-top: 15px;margin-bottom: 15px;"><el-radio :label="deliveryAddress.id">{{ deliveryAddress.province }} {{ deliveryAddress.city }} {{ deliveryAddress.district }}{{ deliveryAddress.address }}&nbsp;&nbsp;{{ deliveryAddress.name }}(收)&nbsp;&nbsp;{{ deliveryAddress.phone }}</el-radio><br></el-row></template></el-radio-group></template><template v-else><el-col :span="24"><el-link :underline="false" type="primary" @click="toDeliveryAddress">去添加地址</el-link></el-col></template></el-row><el-row style="text-align: left;border: 1px solid #EBEEF5;font-size: 25px;margin-top: 20px;padding: 10px 12px 0;"><el-col :span="2"><strong>支付方式</strong></el-col><el-col :span="22"><el-select v-model="paymentType" placeholder="请选择"><el-optionv-for="item in paymentTypeOptions":key="item.value":label="item.label":value="item.value"></el-option></el-select></el-col></el-row><el-row style="text-align: right;"><el-col :span="24">应付总额: <strong style="font-size:20px;color:#e4393c">¥{{ getTotalPrice }}元</strong></el-col></el-row><el-row style="text-align: right;margin-bottom: 30px;margin-top: 20px;"><el-col :span="24"><el-button type="danger" @click="handleSubmit">提交订单</el-button></el-col></el-row></div>
</template><script>
import {Loading} from "element-ui";export default {name: "OrderConfirmation",data() {return {orders: [],deliveryAddressList: [],deliveryAddressId: null,paymentType: '1',paymentTypeOptions: [{value: '1',label: '货到付款'},{value: '2',label: '在线支付'}],}},methods: {toProductInfo(val) {let _this = this;_this.$router.push({path: '/productInfo',query: {pid: val}});},queryDeliveryAddress() {let _this = this;_this.postRequest('/user/deliveryAddress/getDeliveryAddressList').then(resp => {if (resp) {_this.deliveryAddressList = resp.obj;//默认收货地址选中_this.deliveryAddressList.forEach(deliveryAddress => {if (deliveryAddress.isDefault === 1) {_this.deliveryAddressId = deliveryAddress.id;}})}})},toDeliveryAddress() {let _this = this;_this.$router.push({path: '/deliveryAddress',});},handleSubmit(){let _this = this;if(!_this.deliveryAddressId){_this.$message.error("请选择收货地址!");return;}//封装订单数据let order={deliveryAddress:{id:null,}};let orderItemList=[];let totalPrice = 0;order.paymentType=_this.paymentType;//订单明细_this.orders.forEach(item => {let orderItem={shoppingCart:{id:null,},};orderItem.buyCount=item.payAmount;orderItem.payAmount=item.payAmount * item.product.shopPrice;orderItem.productId=item.product.id;totalPrice += item.payAmount * item.product.shopPrice;orderItem.shoppingCart.id=item.id;orderItemList.push(orderItem);});order.orderDetailsDtoList=orderItemList;order.totalAmount=totalPrice;order.deliveryAddress.id=_this.deliveryAddressId;//  提交订单let loading = Loading.service({fullscreen: true, text: '处理中'});this.postRequest('/user/order/addOrder', order).then(resp => {loading.close();if (resp) {//跳转首页let order = resp.obj;_this.$router.push({path: '/orderSuccess',query: {order: order}});}})}},mounted() {let _this = this;_this.$nextTick(function () {// DOM 现在更新了_this.orders = _this.$route.query.orders;_this.queryDeliveryAddress();})},filters: {subTotal(price, count) {return price * count;}},computed: {getTotalPrice() {let _this = this;//总价let totalPrice = 0;if (_this.orders.length > 0) {_this.orders.forEach(item => {totalPrice += item.payAmount * item.product.shopPrice;});return totalPrice;} else {return 0;}}}
}
</script><style scoped></style>
package lyp.itjiaochen.club.controller;import com.google.code.kaptcha.impl.DefaultKaptcha;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;/*** 验证码** @author IT教程资源* @since 1.0.0*/
@RestController
public class CaptchaController {@Autowiredprivate DefaultKaptcha defaultKaptcha;@ApiOperation(value = "验证码")@GetMapping(value = "/captcha",produces = "image/jpeg")public void captcha(HttpServletRequest request, HttpServletResponse response){// 定义response输出类型为image/jpeg类型response.setDateHeader("Expires", 0);// Set standard HTTP/1.1 no-cache headers.response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");// Set IE extended HTTP/1.1 no-cache headers (use addHeader).response.addHeader("Cache-Control", "post-check=0, pre-check=0");// Set standard HTTP/1.0 no-cache header.response.setHeader("Pragma", "no-cache");// return a jpegresponse.setContentType("image/jpeg");//-------------------生成验证码 begin --------------------------//获取验证码文本内容String text = defaultKaptcha.createText();//将验证码文本内容放入sessionrequest.getSession().setAttribute("captcha",text);//根据文本验证码内容创建图形验证码BufferedImage image = defaultKaptcha.createImage(text);ServletOutputStream outputStream = null;try {outputStream = response.getOutputStream();//输出流输出图片,格式为jpgImageIO.write(image,"jpg",outputStream);outputStream.flush();} catch (IOException e) {e.printStackTrace();}finally {if (null!=outputStream){try {outputStream.close();} catch (IOException e) {e.printStackTrace();}}}//-------------------生成验证码 end --------------------------}}