基于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等等
@Controller
public class LoginController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 登录
* @return
*/
@GetMapping("login.html")
public String login(){
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")
}
/**
* 保存
* @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("保存成功");
}
}
if(outStream!=null){
//关闭输出流
outStream.close();
//关闭输入流
fileIs.close();
}
}
}
}
/**
* 文章
*/
@Controller
@RequestMapping("article")
public class ArticleController {
@Autowired
private ArticleService articleService;
@Autowired
private CustomerService customerService;
@Autowired
private ChildTypeService childTypeService;
@Autowired
private ArticleShopService articleShopService;
@Autowired
private ShopService shopService;
}
@Controller
@RequestMapping("customerAddress")
public class CustomerAddressController {
@Autowired
private CustomerAddressService service;
/**
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
List<CustomerAddressEntity> list = service.selectList(wrapper);
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
List<CustomerAddressEntity> list = service.selectList(wrapper);
model.addAttribute("list",list);
return "mobile/address_list";
}
/**
* 保存界面
* @param model
* @param id
* @return
* @throws Exception
*/
@RequestMapping("save.do")
public String save(Model model,String id)throws Exception{
CustomerAddressEntity entity = new CustomerAddressEntity();
if(!StringUtils.isEmpty(id)){
entity = service.selectById(id);
}
model.addAttribute("entity",entity);
return "mobile/address_save";
}
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("saveData.do")
@ResponseBody
public Result save(Model model, CustomerAddressEntity entity)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
entity.setCustomerId(customerEntity.getId());
if(StringUtils.isEmpty(entity.getId())){
entity.setId(IdWorkerUtil.getId());
service.insert(entity);
}else{
service.updateById(entity);
}
return Result.success("保存成功");
}
//关闭输入流
fileIs.close();
}
}
}
}
/**
* 商品管理
*/
@Controller
@RequestMapping("shop")
public class ShopController {
@Autowired
private ShopService service;
@Autowired
private ShopTypeService shopTypeService;
/**
* 界面
* @param model
* @return
*/
@RequestMapping("list.htm")
public String list(Model model){
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);
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";
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}")
public Result del(String id)throws Exception{
roleService.deleteById(id);
*/
@GetMapping("page.htm")
@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.orderBy("top",false).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) {
CustomerEntity customerEntity = customerService.selectById(articleEntity.getCustomerId());
if(customerEntity!=null){
articleEntity.setCustomerName(customerEntity.getName());
}
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.htm")
public String add(Model model)throws Exception{
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "article/add";
}
if(customerEntity!=null){
model.addAttribute("customer",customerEntity);
}
return "shoping/index";
}
@RequestMapping("articleHome.html")
public String articleHome(Model model)throws Exception{
//查询置顶
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(ArticleTable.STATUS,1).eq("top",1).orderBy("time",false);
List<ArticleEntity> topArticle = articleService.selectList(wrapper);
if(topArticle!=null && !topArticle.isEmpty()){
for (ArticleEntity articleEntity : topArticle) {
articleEntity.setCustomerName("系统发布");
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";
}
return Result.success("退出成功");
}
/**
* 登陆
* @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);
* @return
* @throws Exception
*/
@RequestMapping("login.html")
public String login(Model model) throws Exception{
return "mobile/login";
}
/**
* 退出登陆
* @return
* @throws Exception
*/
@RequestMapping("logOut.do")
@ResponseBody
public Result logOut( HttpServletResponse response)throws Exception{
Cookie cookie = new Cookie("login_key_auth_customer","-1");
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
return Result.success("退出成功");
}
/**
* 登陆
* @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
is.close();
InputStream inputStream = new FileInputStream(file1.getPath());
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
return Result.error("上传文件失败");
}
return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
}
/**
* 获取本地图片
* @param pictureName //文件名
* @return
*/
@RequestMapping("/pic")
public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
//这里是存放图片的文件夹地址
FileInputStream fileIs=null;
OutputStream outStream = null;
try {
fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
//得到文件大小
int i=fileIs.available();
//准备一个字节数组存放二进制图片
byte data[]=new byte[i];
//读字节数组的数据
fileIs.read(data);
//设置返回的文件类型
response.setContentType("application/octet-stream;charset=UTF-8");
//得到向客户端输出二进制数据的对象
outStream=response.getOutputStream();
//输出数据
outStream.write(data);
outStream.flush();
} catch (Exception e) {
return;
}finally {
if(outStream!=null){
//关闭输出流
outStream.close();
//关闭输入流
fileIs.close();
}
}
}
}
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";
}
/**
* 用户提取佣金
* @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 Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.do")
@ResponseBody
public Result del(String id)throws Exception{
service.deleteById(id);
return Result.success("保存成功");
}
}
@Controller
@RequestMapping("royalty")
public class RoyaltyController {
@Autowired
private RoyaltyService royaltyService;
@Autowired
private CustomerService customerService;
/**
* 列表界面
* @param model
* @return
/**
* 购物车界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
List<ShoppingGatEntity> gats = shoppingGatService.selectList(entityWrapper);
if(gats!=null ){
for (ShoppingGatEntity gat : gats) {
ShopEntity shopEntity = shopService.selectById(gat.getShopId());
gat.setShopEntity(shopEntity);
}
}
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();
entity.setHot(false);
if(!StringUtils.isEmpty(id)){
entity = service.selectById(id);
}
model.addAttribute("entity",entity);
List<ShopTypeEntity> types = shopTypeService.selectList(new EntityWrapper<>());
model.addAttribute("types",types);
return "shop/save";
}
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("saveData.htm")
@ResponseBody
public Result save(Model model, ShopEntity entity)throws Exception{
if(StringUtils.isEmpty(entity.getId())){
entity.setId(IdWorkerUtil.getId());
entity.setStock(0);
entity.setScore(0.0);
service.insert(entity);
}else{
service.updateById(entity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.htm")
@ResponseBody
public Result del(String id)throws Exception{
service.deleteById(id);
return Result.success("保存成功");
}
/**
* 保存
* @param model
* @return