基于javaweb+mysql的springboot前台后台玩具商城系统(java+ssm+springboot+html+maven+mysql+redis)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot前台后台玩具商城系统(java+ssm+springboot+html+maven+mysql+redis)
一、项目简述本系统主要实现的功能有: 网上商城系统,前台+后台管理,用户注册,登录,商品展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等。
二、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
Springboot+ SpringMVC + MyBatis + Html+ JavaScript + JQuery + Ajax + maven等等
@GetMapping("list.do")
public String list(Model model)throws Exception{
return "mobile/article/list";
}
/**
* 分页
* @return
* @throws Exception
*/
@GetMapping("page.do")
@ResponseBody
public PageVo page(String title, String summary,int page , int limit)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
if(!StringUtils.isEmpty(title)){
entityWrapper.like(ArticleTable.TITLE,title);
}
if(!StringUtils.isEmpty(summary)){
entityWrapper.like(ArticleTable.SUMMARY,summary);
}
entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
Page<ArticleEntity> paged = new Page();
paged.setSize(limit);
paged.setCurrent(page);
Page<ArticleEntity> userTablePage = articleService.selectPage(paged, entityWrapper);
List<ArticleEntity> list = userTablePage.getRecords();
if(list!=null && !list.isEmpty()){
for (ArticleEntity articleEntity : list) {
ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
if(childTypeEntity!=null){
articleEntity.setChildName(childTypeEntity.getName());
}
}
}
PageVo<ArticleEntity> pageVo = new PageVo<>();
pageVo.setCode(0);
pageVo.setCount(paged.getTotal());
pageVo.setData(list);
pageVo.setPageNum(limit);
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.htm")
@ResponseBody
@ImLog(type = "角色",mark = "删除角色 {id}")
public Result del(String id)throws Exception{
roleService.deleteById(id);
return Result.success("保存成功");
}
/**
* 权限界面
* @return
* @throws Exception
*/
@RequestMapping("auth.htm")
public String auth(String id,Model model)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleMenuTable.ROLE_ID,id);
List<RoleMenuEntity> entity = roleMenuService.selectList(entityWrapper);
List<MenuEntity> menuEntities = menuService.selectList(null);
if(entity!=null && !entity.isEmpty()){
Set<String> menuids = new HashSet<>();
for (RoleMenuEntity roleMenuEntity : entity) {
menuids.add(roleMenuEntity.getMenuId());
}
for (MenuEntity menuEntity : menuEntities) {
if(menuids.contains(menuEntity.getId())){
menuEntity.setAuth(true);
}
}
}
model.addAttribute("menuEntities",menuEntities);
model.addAttribute("roleId",id);
return "role/auth";
}
/**
* 权限分配
* @param ids
* @param model
* @return
* @throws Exception
*/
@RequestMapping("authData.htm")
orderShopEntity.setCover(shopEntity.getCover());
orderShopEntity.setShopId(shopEntity.getId());
orderShopEntity.setCustomerId(userEntity.getId());
orderShopService.insert(orderShopEntity);
shopEntity.setStock(shopEntity.getStock() - nums[i]);
shopService.updateById(shopEntity);
if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) {
RoyaltyEntity royaltyEntity = new RoyaltyEntity();
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(shoppingGatEntity.getCid());
royaltyEntity.setMark("订单下单抽取提成");
royaltyEntity.setTime(new Date());
royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
royaltyService.insert(royaltyEntity);
}
}
jedis.set("WSY-SHOPID", name);
return Result.success("订单结算成功");
}
}
/**
* Created by Wsy
*/
@Controller
@RequestMapping("fileNoCos")
CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId());
articleEntity.setCustomerEntity(userEntity);
}
}
model.addAttribute("topArticle",topArticle);
//查询分类
List<ChildTypeEntity> list = childTypeService.selectList(new EntityWrapper<>());
model.addAttribute("childTypes",list);
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ArticleTable.STATUS,1);
entityWrapper.orderBy("time",false);
List<ArticleEntity> articleEntities = articleService.selectList(entityWrapper);
if(articleEntities!=null && !articleEntities.isEmpty()){
for (ArticleEntity articleEntity : articleEntities) {
articleEntity.setCustomerName("系统发布");
CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId());
articleEntity.setCustomerEntity(userEntity);
ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
if(childTypeEntity!=null){
articleEntity.setChildName(childTypeEntity.getName());
}
}
}
model.addAttribute("articleEntities",articleEntities);
return "mobile/articleHome";
}
}
private String payResult() {
List<String> ids = jedis.lrange("WSY-IDS", 0, -1);
jedis.del("WSY-IDS");
for (String id : ids) {
shoppingGatService.deleteById(id);
}
String flag = jedis.get("WSY-FLAG");
if ("true".equals(flag)) {
String integralStr = jedis.get("WSY-INTEGRAL");
Integer integralInt = Integer.valueOf(integralStr);
String userId = jedis.get("WSY-USERID");
CustomerEntity customerEntity = customerService.selectById(userId);
customerEntity.setIntegral(integralInt);
customerService.updateById(customerEntity);
}
String orderId = jedis.get("WSY-ORDERID");
OrderEntity orderEntity = new OrderEntity();
orderEntity.setId(orderId);
orderEntity.setStatus(1);
orderService.updateById(orderEntity);
return "shoping/index";
}
}
@Controller
@RequestMapping("file")
public class ImgControllerNoCos {
public static final String FILE_PATH = "D:\\immersive_shopping\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
@Controller
@RequestMapping("mobileShop")
public class MobileShopController {
@Autowired
private ShopService shopService;
@Autowired
private OrderShopDao orderShopDao;
@Autowired
private ArticleService articleService;
@RequestMapping("info.html")
public String info(String id,String customerId, Model model)throws Exception{
ShopEntity shopEntity = shopService.selectById(id);
model.addAttribute("shop",shopEntity);
model.addAttribute("id",id);
List<OrderShopEntity> list = orderShopDao.list(id);
model.addAttribute("list",list);
model.addAttribute("customerId",customerId);
return "mobile/shop_info";
}
/**
* @param id
* @return
* @throws Exception
*/
@RequestMapping("aList.html")
@ResponseBody
public Result shopList(String id)throws Exception{
ShopEntity shopEntity = shopService.selectById(id);
if(StringUtils.isEmpty(shopEntity.getLabel())){
return Result.success("无");
}
String[] lebel = shopEntity.getLabel().split(",");
//查询
List<String> ids = new ArrayList<>();
for (String s : lebel) {
EntityWrapper wrapper = new EntityWrapper();
entityWrapper.like(ArticleTable.TITLE,title);
}
if(!StringUtils.isEmpty(summary)){
entityWrapper.like(ArticleTable.SUMMARY,summary);
}
entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
Page<ArticleEntity> paged = new Page();
paged.setSize(limit);
paged.setCurrent(page);
Page<ArticleEntity> userTablePage = articleService.selectPage(paged, entityWrapper);
List<ArticleEntity> list = userTablePage.getRecords();
if(list!=null && !list.isEmpty()){
for (ArticleEntity articleEntity : list) {
ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
if(childTypeEntity!=null){
articleEntity.setChildName(childTypeEntity.getName());
}
}
}
PageVo<ArticleEntity> pageVo = new PageVo<>();
pageVo.setCode(0);
pageVo.setCount(paged.getTotal());
pageVo.setData(list);
pageVo.setPageNum(limit);
pageVo.setPageSize(page);
return pageVo;
}
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("add.do")
public String add(Model model)throws Exception{
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "mobile/article/add";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("addData.do")
@ResponseBody
public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{
articleEntity.setId(IdWorkerUtil.getId());
articleEntity.setTime(new Date());
/**
* 评价界面
*
* @param id
* @return
* @throws Exception
*/
@RequestMapping("comment.do")
public String comment(String id, Model model) throws Exception {
OrderShopEntity orderShopEntity = orderShopService.selectById(id);
model.addAttribute("entity", orderShopEntity);
return "mobile/comment";
}
@RequestMapping("commentData.do")
@ResponseBody
public Result commentData(OrderShopEntity orderShopEntity) throws Exception {
String content = orderShopEntity.getContent();
content = content.replace("操", "*");
content = content.replace("sb", "**");
content = content.replace("傻", "*");
orderShopEntity.setContent(content);
orderShopService.updateById(orderShopEntity);
orderShopEntity = orderShopService.selectById(orderShopEntity.getId());
Double num = orderShopDao.num(orderShopEntity.getShopId());
ShopEntity shopEntity = new ShopEntity();
shopEntity.setId(orderShopEntity.getShopId());
shopEntity.setScore(num);
shopService.updateById(shopEntity);
return Result.success(1);
}
/**
* 收货
*
* @param id
* @return
* @throws Exception
/**
* 订单结算
*
* @param ids 购物车ids
* @param nums 数量
* @return
* @throws Exception
*/
@RequestMapping("jiesuan.do")
@ResponseBody
public Result jiesuan(String ids[], Integer nums[], String prices[], OrderEntity orderEntity, String addressId) throws Exception {
CustomerEntity userEntity = Contants.getCustomer();
String orderId = IdWorkerUtil.getId();
jedis.set("WSY-ORDERID", orderId);
orderEntity.setId(orderId);
orderEntity.setCustomerId(userEntity.getId());
orderEntity.setStatus(1);
orderEntity.setTime(new Date());
CustomerAddressEntity customerAddressEntity = customerAddressService.selectById(addressId);
if (customerAddressEntity == null) {
return Result.error("请选择收货地址");
}
//验证库存是否足够
for (int i = 0; i < ids.length; i++) {
ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
if (shopEntity.getStock() == null || shopEntity.getStock() < shoppingGatEntity.getNum()) {
return Result.error(shopEntity.getName() + "库存不足");
}
}
orderEntity.setAddress(customerAddressEntity.getAddress());
orderEntity.setName(customerAddressEntity.getName());
orderEntity.setPhone(customerAddressEntity.getPhone());
orderService.insert(orderEntity);
String name = StrUtil.EMPTY;
for (int i = 0; i < ids.length; i++) {
ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
OrderShopEntity orderShopEntity = new OrderShopEntity();
orderShopEntity.setId(IdWorkerUtil.getId());
orderShopEntity.setPrice(new BigDecimal(prices[i]));
orderShopEntity.setNum(nums[i]);
orderShopEntity.setOrderId(orderEntity.getId());
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("edit.do")
public String edit(String id, Model model )throws Exception{
ArticleEntity articleEntity = articleService.selectById(id);
model.addAttribute("articleEntity",articleEntity);
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "mobile/article/edit";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("editData.do")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
@Autowired
private UserService userService;
/**
* 用户界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.htm")
public String list(Model model)throws Exception{
List<UserEntity> list = userDao.list();
model.addAttribute("list",list);
return "user/list";
}
/**
* 保存界面
* @param model
* @param id
* @return
* @throws Exception
*/
@RequestMapping("save.htm")
public String save(Model model,String id)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleTable.STATUS,true);
List<RoleEntity> entities = roleService.selectList(entityWrapper);
model.addAttribute("roles",entities);
UserEntity userEntity = new UserEntity();
userEntity.setSex(true);
userEntity.setStatus(true);
if(!StringUtils.isEmpty(id)){
userEntity = userService.selectById(id);
}
model.addAttribute("userEntity",userEntity);
return "user/save";
}
jedis.del("WSY-IDS");
for (String id : ids) {
shoppingGatService.deleteById(id);
}
String flag = jedis.get("WSY-FLAG");
if ("true".equals(flag)) {
String integralStr = jedis.get("WSY-INTEGRAL");
Integer integralInt = Integer.valueOf(integralStr);
String userId = jedis.get("WSY-USERID");
CustomerEntity customerEntity = customerService.selectById(userId);
customerEntity.setIntegral(integralInt);
customerService.updateById(customerEntity);
}
String orderId = jedis.get("WSY-ORDERID");
OrderEntity orderEntity = new OrderEntity();
orderEntity.setId(orderId);
orderEntity.setStatus(1);
orderService.updateById(orderEntity);
return "shoping/index";
}
}
@Controller
@RequestMapping("file")
public class ImgControllerNoCos {
public static final String FILE_PATH = "D:\\immersive_shopping\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
@Autowired
private CustomerService customerService;
@Autowired
private ChildTypeService childTypeService;
@Autowired
private ShopService shopService;
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("list.do")
public String list(Model model)throws Exception{
return "mobile/article/list";
}
/**
* 分页
* @return
* @throws Exception
*/
@GetMapping("page.do")
@ResponseBody
public PageVo page(String title, String summary,int page , int limit)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
if(!StringUtils.isEmpty(title)){
entityWrapper.like(ArticleTable.TITLE,title);
}
if(!StringUtils.isEmpty(summary)){
entityWrapper.like(ArticleTable.SUMMARY,summary);
}
entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
Page<ArticleEntity> paged = new Page();
paged.setSize(limit);
paged.setCurrent(page);
Page<ArticleEntity> userTablePage = articleService.selectPage(paged, entityWrapper);
List<ArticleEntity> list = userTablePage.getRecords();
if(list!=null && !list.isEmpty()){
for (ArticleEntity articleEntity : list) {
*/
@RequestMapping("editData.do")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {
@Autowired
private ShoppingGatService shoppingGatService;
@Autowired
private ShopService shopService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
}
}
model.addAttribute("gats",gats);
CustomerEntity customerEntity = customerService.selectById(userEntity.getId());
model.addAttribute("integral",customerEntity.getIntegral());
List<CustomerAddressEntity> customerAddressEntities = customerAddressService.selectList(entityWrapper);
model.addAttribute("customerAddressEntities",customerAddressEntities);
return "mobile/gat";
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@RequestMapping("delete.do")
@ResponseBody
public Result delete(String id)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
if(StringUtils.isEmpty(id)){
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
shoppingGatService.delete(entityWrapper);
}else{
shoppingGatService.deleteById(id);
}
return Result.success("成功");
}
/**
* 添加到购物车
* @param shopId
* @return
* @throws Exception
*/
@RequestMapping("add.do")
@ResponseBody
public Result add(String shopId,Integer num,String customerId)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId())
.eq(ShoppingGatTable.SHOP_ID,shopId);
ShoppingGatEntity gatEntity = shoppingGatService.selectOne(entityWrapper);
if(gatEntity!=null){
gatEntity.setNum(gatEntity.getNum()+num);
shoppingGatService.updateById(gatEntity);
}else{
gatEntity = new ShoppingGatEntity();
gatEntity.setId(IdWorker.get32UUID());
gatEntity.setNum(num);
// }
//
// /**
// * 文件上传返回code为200
// *
// * @param file
// * @return
// * @throws Exception
// */
// @PostMapping("/upload")
// @ResponseBody
// public Result uplaod(@RequestParam("file") MultipartFile file) throws Exception {
// //用来检测程序运行时间
// String fileName = IdWorker.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// try {
// File file1 = transferToFile(file);
// // 1 初始化用户身份信息(secretId, secretKey)。
// COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
// Region region = new Region(REGION);
// ClientConfig clientConfig = new ClientConfig(region);
这里建议设置使用 https 协议
// clientConfig.setHttpProtocol(HttpProtocol.https);
// // 3 生成 cos 客户端。
// COSClient cosClient = new COSClient(cred, clientConfig);
// // 指定要上传的文件
// // 指定文件将要存放的存储桶
// String bucketName = BUCKETNAME;
// // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下
// String key = KEY + fileName;
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1);
// PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
// } catch (Exception e) {
// e.printStackTrace();
// return Result.error("上传文件失败");
// }
// return Result.success(BASEURL + fileName, "文件上传成功");
// }
public static final String FILE_PATH = "D:\\immersive_shopping\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
// */
// private static File transferToFile(MultipartFile multipartFile) {
// File file = null;
// try {
// String originalFilename = multipartFile.getOriginalFilename();
// System.out.println(originalFilename);
// String[] filename = originalFilename.split("\\.");
// file = File.createTempFile(filename[0], filename[1]);
// multipartFile.transferTo(file);
// file.deleteOnExit();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return file;
// }
//
// /**
// * 文件上传返回code为200
// *
// * @param file
// * @return
// * @throws Exception
// */
// @PostMapping("/upload")
// @ResponseBody
// public Result uplaod(@RequestParam("file") MultipartFile file) throws Exception {
// //用来检测程序运行时间
// String fileName = IdWorker.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// try {
// File file1 = transferToFile(file);
// // 1 初始化用户身份信息(secretId, secretKey)。
// COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
// Region region = new Region(REGION);
// ClientConfig clientConfig = new ClientConfig(region);
这里建议设置使用 https 协议
// clientConfig.setHttpProtocol(HttpProtocol.https);
// // 3 生成 cos 客户端。
// COSClient cosClient = new COSClient(cred, clientConfig);
// // 指定要上传的文件
// // 指定文件将要存放的存储桶
// String bucketName = BUCKETNAME;
// // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下
// String key = KEY + fileName;
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1);