基于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等等
@Controller
@RequestMapping("order")
public class SpOrderController {
public static final String PAYURL = "http://localhost:8080/pay?id=%s&name=%s&amount=%s";
@Autowired
private ShoppingGatService shoppingGatService;
@Autowired
private ShopService shopService;
@Autowired
private OrderShopService orderShopService;
@Autowired
private OrderService orderService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private OrderShopDao orderShopDao;
@Autowired
private RoyaltyService royaltyService;
@Autowired
@Qualifier("alipayService")
private AlipayService alipayService;
@Autowired
public Jedis jedis;
/**
* 评价界面
*
* @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";
for (String article : articles) {
str.add(article);
}
List<ShopEntity> shopEntities = shopService.selectBatchIds(str);
model.addAttribute("shopEntities",shopEntities);
}
return "article/info";
}
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("edit.htm")
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 "article/edit";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("editData.htm")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
@Controller
@RequestMapping("mobileCustomer")
public class MobileCustomerController {
@Autowired
private CustomerService customerService;
/**
* 我的界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("jump.html")
public String my(Model model,String url)throws Exception{
model.addAttribute("url",url);
return "mobile/jump";
}
/**
* 我的Data
* @param model
* @return
* @throws Exception
*/
@RequestMapping("infoData.do")
@ResponseBody
public Result infoData(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
return Result.success(customerEntity);
}
/**
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("edit.htm")
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 "article/edit";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("editData.htm")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
/**
* 商品管理
*/
@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){
List<ShopEntity> list = service.selectList(new EntityWrapper<>());
model.addAttribute("list",list);
return "shop/list";
}
/**
* 保存界面
* @param model
* @param id
* @return
* @throws Exception
*/
@RequestMapping("save.htm")
@Autowired
private OrderShopService orderShopService;
@Autowired
private OrderService orderService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private OrderShopDao orderShopDao;
@Autowired
private RoyaltyService royaltyService;
@Autowired
@Qualifier("alipayService")
private AlipayService alipayService;
@Autowired
public Jedis jedis;
/**
* 评价界面
*
* @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());
/**
* 登录
* @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")
@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("/");
/**
* 收货
*
* @param id
* @return
* @throws Exception
*/
@RequestMapping("shouhuo.do")
@ResponseBody
public Result shouhuo(String id) throws Exception {
OrderEntity orderEntity = orderService.selectById(id);
orderEntity.setStatus(3);
orderService.updateById(orderEntity);
return Result.success("欢迎下次光临");
}
/**
* 退货收货
*
* @param id
* @return
* @throws Exception
*/
@RequestMapping("tuihuo.do")
@ResponseBody
public Result tuihuo(String id) throws Exception {
orderService.deleteById(id);
return Result.success("下次再买 - -");
}
/**
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model) throws Exception {
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(OrderTable.CUSTOMER_ID, userEntity.getId()).orderBy("time", false);
List<OrderEntity> orders = orderService.selectList(wrapper);
if (orders != null) {
for (OrderEntity order : orders) {
wrapper = new EntityWrapper();
wrapper.eq("order_id", order.getId());
List<OrderShopEntity> orderShops = orderShopService.selectList(wrapper);
order.setOrderShops(orderShops);
}
}
model.addAttribute("orders", orders);
return "mobile/orderList";
}
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);
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);
@Controller
@RequestMapping("role")
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private MenuService menuService;
@Autowired
private RoleMenuService roleMenuService;
/**
* 角色界面
* @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";
}
/**
* 保存
public Jedis jedis;
/**
* 评价界面
*
* @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
public Result shouhuo(String id) throws Exception {
OrderEntity orderEntity = orderService.selectById(id);
orderEntity.setStatus(3);
orderService.updateById(orderEntity);
return Result.success("欢迎下次光临");
/**
* 保存
* @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("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.do")
@ResponseBody
public Result del(String id)throws Exception{
service.deleteById(id);
return Result.success("保存成功");
}
}
@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) {
* @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);
gatEntity.setShopId(shopId);
gatEntity.setCustomerId(userEntity.getId());
gatEntity.setCid(customerId);
shoppingGatService.insert(gatEntity);
}
return Result.success("成功");
}
}
@Controller
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("editData.htm")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
@Controller
//获取输出流
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
os.write(temp);
}
os.flush();
os.close();
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];
//读字节数组的数据
@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {
@Autowired
private ShoppingGatService shoppingGatService;
@Autowired
private ShopService shopService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private CustomerService customerService;
@Autowired
private RoyaltyService royaltyService;
/**
* 购物车界面
* @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
*/
@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}")