基于javaweb+mysql的springboot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
一、项目简述
功能: 主页显示商品; 所有蛋糕商品展示,可进行商品搜索; 点击商品进入商品详情页,具有立即购买功能,可增减购买商品数量亦可手动输入,热销商品展示。 立即购买进入确认订单页面,可选择已经添加的地址,亦可新增地址。 可选择购买哪些商品,可删除不需要的商品。 点击结算进入确认订单页面,确认后提交订单。后台管理:(修改密码等),商品管理(商品批量添加、上下架等),订单管理。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + FTP+ JavaScript + JQuery + Ajax + maven等等
/**
* @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();
wrapper.like("label",s);
List<ArticleEntity> shops = articleService.selectList(wrapper);
if(shops!=null){
for (ArticleEntity shop : shops) {
ids.add(shop.getId());
}
}
}
EntityWrapper wrapper = new EntityWrapper();
wrapper.in("id",ids).orderBy("rand()");
List<ArticleEntity> shops = articleService.selectList(wrapper);
if(shops!=null){
if(shops.size()>3){
shops = shops.subList(0,3);
}
}
return Result.success(shops);
}
}
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private UserDao userDao;
@Autowired
private RoleService roleService;
@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";
}
* @throws Exception
*/
@RequestMapping("infoData.do")
@ResponseBody
public Result infoData(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
return Result.success(customerEntity);
}
/**
* 我的界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("info.do")
public String info(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
model.addAttribute("customer",customerEntity);
return "mobile/my";
}
/**
* 我的界面 -- 修改
* @param model
* @return
* @throws Exception
*/
@RequestMapping("myUpdate.do")
public String my_update(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
model.addAttribute("entity",customerEntity);
return "mobile/my_update";
}
/**
* 我的界面 -- 修改
* @return
* @throws Exception
*/
@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")
@ResponseBody
@ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
public Result data(String[] ids,String roleId,Model model)throws Exception{
List<String> list = new ArrayList<>();
for (String id : ids) {
list.add(id);
}
List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
//删除原有权限
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
}
@Controller
@RequestMapping("royalty")
public class RoyaltyController {
@Autowired
private RoyaltyService royaltyService;
@Autowired
private CustomerService customerService;
/**
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq("customer",Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
List<RoyaltyEntity> list = royaltyService.selectList(entityWrapper);
model.addAttribute("list",list);
BigDecimal all = new BigDecimal(0);
if(list!=null){
for (RoyaltyEntity royaltyEntity : list) {
all = all.add(royaltyEntity.getMoney());
}
}
model.addAttribute("all",all);
return "mobile/royalty";
}
/**
//输出数据
outStream.write(data);
outStream.flush();
} catch (Exception e) {
return;
}finally {
if(outStream!=null){
//关闭输出流
outStream.close();
//关闭输入流
fileIs.close();
}
}
}
}
/**
* 文章
*/
@Controller
@RequestMapping("article")
public class ArticleController {
@Autowired
private ArticleService articleService;
@Autowired
private CustomerService customerService;
* 评价界面
*
* @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
*/
@RequestMapping("shouhuo.do")
@ResponseBody
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 = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
customerEntity.setHeader("/img/a5.jpg");
customerService.insert(customerEntity);
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
}
/**
* 文章
*/
for (RoyaltyEntity royaltyEntity : list) {
all = all.add(royaltyEntity.getMoney());
}
}
model.addAttribute("all",all);
return "mobile/royalty";
}
/**
* 用户提取佣金
* @param money
* @return
* @throws Exception
*/
@RequestMapping("tiqu.do")
@ResponseBody
public Result tiqu(String money)throws Exception{
RoyaltyEntity royaltyEntity = new RoyaltyEntity();
String id = Contants.getCustomer().getId();
BigDecimal bigDecimal = new BigDecimal(money);
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(id);
royaltyEntity.setMark("用户提取佣金");
royaltyEntity.setTime(new Date());
royaltyEntity.setMoney(bigDecimal);
royaltyService.insert(royaltyEntity);
CustomerEntity customerEntity = customerService.selectById(id);
money = money.replace("-","");
Integer integer = Integer.valueOf(money);
customerEntity.setIntegral(customerEntity.getIntegral()+integer/10);
customerService.updateById(customerEntity);
return Result.success("提取成功");
}
}
return "login";
}
/**
* 登录
* @return
*/
@GetMapping("logout.htm")
public String logout(HttpServletResponse response){
Cookie cookie = new Cookie("login_key_auth","");
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
return "redirect:/login.html";
}
/**
* 登录
* @param loginName
* @param password
* @return
* @throws Exception
*/
@PostMapping("loginData.html")
@ResponseBody
@ImLog(type = "登录",mark = "用户 {loginName} 登录")
public Result loginData(String loginName, String password, HttpServletResponse response)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(UserTable.LOGIN_NAME,loginName);
UserEntity userEntity = userService.selectOne(entityWrapper);
if(userEntity==null){
return Result.error("用户名或密码错误");
}
if(!password.equals(userEntity.getPassword())){
return Result.error("用户名或密码错误");
}
RoleEntity roleEntity = roleService.selectById(userEntity.getRoleId());
if(roleEntity==null || roleEntity.getStatus()==false ){
return Result.error("用户无角色可用");
}
Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success("登录成功");
}
/**
* 文章
*/
@Controller
@RequestMapping("article")
public class MobileArticleController {
@Autowired
private ArticleService articleService;
@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";
}
/**
* 分页
public Result stock(Model model, Integer stock,String id ,Integer type)throws Exception{
ShopEntity entity = service.selectById(id);
if(entity.getStock()==null){
entity.setStock(0);
}
if(type==1){ //添加库存
entity.setStock(entity.getStock()+stock);
}else{ //减少库存
if(entity.getStock()-stock<0){
return Result.error("库存不够");
}
entity.setStock(entity.getStock()-stock);
}
service.updateById(entity);
return Result.success("保存成功");
}
}
/**
* 普通用户管理
*/
@Controller
@RequestMapping("childType")
public class ChildTypeController {
@Autowired
private ChildTypeService childTypeService ;
/**
* 根据1级分类查询2级分类
* @param type
* @return
* @throws Exception
*/
@RequestMapping("loginData.html")
@ResponseBody
public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq("phone",phone);
CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
if(customerEntity==null){
return Result.error("用户不存在");
}
if(!customerEntity.getPassword().equals(password)){
return Result.error("密码错误");
}
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
/**
* 登陆界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("reg.html")
public String reg(Model model) throws Exception{
return "mobile/reg";
}
/**
* 登陆
* @return
* @throws Exception
*/
@RequestMapping("regData.html")
@ResponseBody
public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
customerEntity.setId(IdWorkerUtil.getId());
customerEntity.setHeader("/img/a5.jpg");
customerService.insert(customerEntity);
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("saveData.htm")
@ResponseBody
@ImLog(type = "用户",mark = "保存用户 {name}")
public Result save(Model model, UserEntity userEntity)throws Exception{
if(StringUtils.isEmpty(userEntity.getId())){
userEntity.setId(IdWorker.get32UUID());
userEntity.setTime(new Date());
userService.insert(userEntity);
}else{
userService.updateById(userEntity);
}
return Result.success("保存成功");
}
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("del.htm")
@ResponseBody
@ImLog(type = "用户",mark = "删除用户 {id}")
public Result del(Model model, String id )throws Exception{
userService.deleteById(id);
return Result.success("保存成功");
}
}
* 角色界面
* @param model
* @return
* @throws Exception
*/
@GetMapping("list.htm")
public String list(Model model)throws Exception{
List<RoleEntity> list = roleService.selectList(new EntityWrapper<>());
model.addAttribute("list",list);
return "role/list";
}
/**
* 保存
* @param id
* @param name
* @return
* @throws Exception
*/
@PostMapping("save.htm")
@ResponseBody
@ImLog(type = "角色",mark = "保存角色 {id} {name} {status}")
public Result save(String id,String name,Boolean status)throws Exception{
RoleEntity roleEntity = new RoleEntity();
roleEntity.setName(name);
roleEntity.setStatus(status);
if(StringUtils.isEmpty(id)){
roleEntity.setId(IdWorker.get32UUID());
roleEntity.setTime(new Date());
roleService.insert(roleEntity);
}else{
roleEntity.setId(id);
roleService.updateById(roleEntity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.htm")
@ResponseBody
@ImLog(type = "角色",mark = "删除角色 {id}")
}
double s = Double.parseDouble(amount);
Integer pay = (int) s;
Integer flag = (int) s;
CustomerEntity customer = Contants.getCustomer();
CustomerEntity customerEntity = customerService.selectById(customer.getId());
Integer integral = customerEntity.getIntegral();
String INTEGRALFLA = jedis.get("WSY-INTEGRALFLAG");
if (integral != null && integral > 0 && "true".equals(INTEGRALFLA)) {
pay = pay - integral;
if (pay < 0) {
pay = 0;
integral = integral - flag;
} else {
integral = 0;
}
jedis.set("WSY-FLAG", "true");
jedis.set("WSY-INTEGRAL", String.valueOf(integral));
jedis.set("WSY-USERID", customerEntity.getId());
} else {
jedis.set("WSY-FLAG", "false");
}
name = name.substring(0, name.length() - 1);
String id = IdUtil.simpleUUID();
// String pays = alipayService.webPagePay(id, pay, name);
return "下单成功";
}
@RequestMapping("/payresult")
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";
}
}