Java项目:汽配商城系统(java+HTML+JavaScript+jsp+Mysql)

源码获取:俺的博客首页 "资源" 里下载!

项目介绍

管理员角色包含以下功能:
修改管理员信息,订单管理,客户管理,鞋子管理,类目管理等功能。

用户角色包含以下功能:
查看首页,用户登录,修改个人信息,按分类查看鞋子,查看热销鞋子,查看新鞋子·,查看商品详情,查看我的购物车,提交订单,查看我的订单等功能。


环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 5.7版本;


技术栈

HTML+CSS+JavaScript+jsp+mysql


使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/login.jsp 登录

 

 

 

 

 

配件管理控制器:

/**
 * 配件控制器
 */
@Api("配件接口API")
@RestController
public class GoodsController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private GoodsService goodsService;

    private String image = "";

    @ApiOperation(value = "配件列表接口", notes = "配件结果集列表")
    @GetMapping("/admin/goodsList")
    public ServerLayResult<Goods> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                       @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        //查询结果总数
        int count = goodsService.count();
        List<Goods> goods = goodsService.selectAll(page, limit);
        //组装Json数据
        ServerLayResult result = new ServerLayResult(0, "", count, goods);
        return result;
    }

    @ApiOperation(value = "配件删除接口", notes = "根据配件ID删除配件")
    @GetMapping("/admin/goods/del")
    public String delete(Integer id) {
        System.out.println("id = " + id);
        int row = goodsService.deleteByPrimaryKey(id);
        if (row > 0) {
            return "success";
        }
        return "error";
    }

    @ApiOperation(value = "配件更新接口", notes = "根据json数据对象来更新接口")
    @PostMapping("/admin/goods/update")
    public String update(@RequestBody JSONObject ob) {
        com.alibaba.fastjson.JSONObject json = JSON.parseObject(ob.toJSONString());
        logger.info(ob.toJSONString());
        String gname = json.getString("gname");
        Integer id = json.getInteger("id");
        Double goprice = json.getDouble("goprice");
        Double grprice = json.getDouble("grprice");
        Integer gstore = json.getInteger("gstore");
        String goodstypeId = json.getString("goodstypeId");
        if (goodstypeId == null) {
            return "error";
        }
        Goods goods = new Goods();
        goods.setId(id);
        goods.setGname(gname);
        goods.setGoprice(goprice);
        goods.setGrprice(grprice);
        goods.setGstore(gstore);
        GoodsType goodsType = new GoodsType();
        goodsType.setId(Integer.parseInt(goodstypeId));
        goods.setGoodstypeId(goodsType);
        goods.setIputTime(new Date());

//        goods.setGpicture("http://www.csbishe.cn:18081/views/upload/" + image);
        goods.setGpicture("http://localhost:18081/views/upload/" + image);
        logger.info(String.valueOf(goods));
        int insert = goodsService.updateByPrimaryKey(goods);
        if (insert > 0) {
            return "success";
        }
        return "error";
    }

    @ApiOperation(value = "配件保存接口", notes = "根据json数据来保存配件")
    @PostMapping("/admin/goods/add")
    public String addGoods(@RequestBody JSONObject ob) {
        com.alibaba.fastjson.JSONObject json = JSON.parseObject(ob.toJSONString());
        String gname = json.getString("gname");
        Double goprice = json.getDouble("goprice");
        Double grprice = json.getDouble("grprice");
        Integer gstore = json.getInteger("gstore");
        String goodstypeId = json.getString("goodstypeId");
        Goods goods = new Goods();
        goods.setGname(gname);
        goods.setGoprice(goprice);
        goods.setGrprice(grprice);
        goods.setGstore(gstore);
        GoodsType goodsType = new GoodsType();
        goodsType.setId(Integer.parseInt(goodstypeId));
        goods.setGoodstypeId(goodsType);
        goods.setIputTime(new Date());

        goods.setGpicture("http://localhost:18081/views/upload/" + image);
        int insert = goodsService.insert(goods);
        if (insert > 0) {
            return "success";
        }
        return "error";
    }

    /**
     * 实现文件上传
     */
    @ApiOperation(value = "图片上传接口", notes = "根据MultipartFile类上传文件")
    @PostMapping(value = "/admin/uploadImg")
    public Map<String, Object> ramanage(@RequestParam("file") MultipartFile file,
                                        HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();
        try {
            //获取跟目录
            File path = new File(ResourceUtils.getURL("classpath:").getPath());
            if (!path.exists()) path = new File("");
            System.out.println("path:" + path.getAbsolutePath());
            File upload = new File(path.getAbsolutePath(), "static/images/upload/");
            if (!upload.exists())
                upload.mkdirs();
            String realPath = path.getAbsolutePath() + "/static/views/upload";
            request.setAttribute("path", realPath);
            image = FileUploadUtils.uploadFile(file, realPath);
            result.put("code", 0);
            result.put("image", image);
        } catch (Exception e) {
            result.put("code", 1);
            e.printStackTrace();
        }
        return result;
    }


}

用户Controller控制器:

/**
 * 用户Controller控制器
 */
@Api(value = "用户管理接口")
@RestController
public class UserController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    //注入业务
    @Autowired
    private UserService userService;

    /**
     * table数据列表
     *
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "用户列表", notes = "查询用户结果集")
    @GetMapping("/admin/user/tableList")
    public ServerLayResult userList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                    @RequestParam(value = "limit", defaultValue = "10") Integer limit,
                                    @RequestParam(value = "keyword", defaultValue = "") String keyword) {
        if (keyword == null || keyword.equals("")) {
            logger.info("====================================1======" + keyword);
            //封装Json数据对象
            ServerLayResult result = new ServerLayResult(0, "", userService.count(), userService.selectAll(page, limit));
            return result;
        } else if (keyword != null) {
            logger.info("====================================2======" + keyword);
            ServerLayResult result = new ServerLayResult(0, "", userService.selectByUsername(keyword, page, limit).size(),
                    userService.selectByUsername(keyword, page, limit));
            return result;
        }
        logger.info("====================================3======" + keyword);
        return null;
    }


    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "用户删除", notes = "根据用户ID删除用户")
    @GetMapping("/admin/user/del")
    public String del(@RequestParam("id") Integer id) {
        if (id != null && id != 0) {
            int del = userService.deleteByPrimaryKey(id);
            if (del > 0) {
                return "success";
            }
        }
        return "error";
    }

    /**
     * 根据用户传入的对象进行更新
     *
     * @param user
     * @return
     */
    @ApiOperation(value = "用户对象更新", notes = "根据用户对象更新")
    @PostMapping("/admin/user/update")
    public String updateUser(@RequestBody User user) {

        if (user != null) {
            //根据用户对象的id 查询用户的密码,防止密码丢失
            User user1 = userService.selectByPrimaryKey(user.getId());
            //再次封装进对象中
            if (user1 != null) {
                user.setPassword(user1.getPassword());
                //更新对象
                int update = userService.updateByPrimaryKey(user);
                if (update > 0) {
                    return "success";
                }
            }
        }
        return "error";
    }

    /**
     * 重置用户密码
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "重置密码接口", notes = "根据用户ID查询用户重置密码为123456,最后进行MD5加密")
    @GetMapping("/admin/user/resetPwd")
    public String restPwd(@RequestParam("id") Integer id) {
        if (id != null && id > 0) {
            //根据id查询出用户
            User user = userService.selectByPrimaryKey(id);
            //开始重置密码,重置密码使用的Spring提供的工具类进行对密码123456进行加密
            user.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            //调用更新方法
            int restPwd = userService.updateByPrimaryKey(user);
            if (restPwd > 0) {
                return "success";
            }
        }
        return "error";
    }

    @ApiOperation(value = "Excel表格接口", notes = "表格导出")
    @GetMapping(value = "/admin/exportBtn")
    public void export(HttpServletResponse response) throws IOException {
        List<User> users = userService.selectAll();

        HSSFWorkbook wb = new HSSFWorkbook();

        HSSFSheet sheet = wb.createSheet("获取excel测试表格");

        HSSFRow row = null;

        row = sheet.createRow(0);//创建第一个单元格
        row.setHeight((short) (26.25 * 20));
        row.createCell(0).setCellValue("用户信息表");//为第一行单元格设值

        /*为标题设计空间
         * firstRow从第1行开始
         * lastRow从第0行结束
         *
         *从第1个单元格开始
         * 从第3个单元格结束
         */
        CellRangeAddress rowRegion = new CellRangeAddress(0, 0, 0, 2);
        sheet.addMergedRegion(rowRegion);

      /*CellRangeAddress columnRegion = new CellRangeAddress(1,4,0,0);
      sheet.addMergedRegion(columnRegion);*/


        /*
         * 动态获取数据库列 sql语句 select COLUMN_NAME from INFORMATION_SCHEMA.Columns where table_name='user' and table_schema='test'
         * 第一个table_name 表名字
         * 第二个table_name 数据库名称
         * */
        row = sheet.createRow(1);
        row.setHeight((short) (22.50 * 20));//设置行高
        row.createCell(0).setCellValue("用户Id");//为第一个单元格设值
        row.createCell(1).setCellValue("用户登入名");//为第二个单元格设值
        row.createCell(2).setCellValue("用户密码");//为第三个单元格设值
        row.createCell(3).setCellValue("用户邮箱");//为第三个单元格设值
        row.createCell(4).setCellValue("用户名");//为第三个单元格设值
        row.createCell(5).setCellValue("用户地址");//为第三个单元格设值
        row.createCell(6).setCellValue("用户电话");//为第三个单元格设值

        for (int i = 0; i < users.size(); i++) {
            row = sheet.createRow(i + 2);
            User user = users.get(i);
            row.createCell(0).setCellValue(user.getId());
            row.createCell(1).setCellValue(user.getUsername());
            row.createCell(2).setCellValue(user.getPassword());
            row.createCell(3).setCellValue(user.getEmail());
            row.createCell(4).setCellValue(user.getName());
            row.createCell(5).setCellValue(user.getAddress());
            row.createCell(6).setCellValue(user.getPhone());
        }
        sheet.setDefaultRowHeight((short) (16.5 * 20));
        //列宽自适应
        for (int i = 0; i <= 13; i++) {
            sheet.autoSizeColumn(i);
        }

        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        OutputStream os = response.getOutputStream();
        response.setHeader("Content-disposition", "attachment;filename=user.xls");//默认Excel名称
        wb.write(os);
        os.flush();
        os.close();
    }

    @RequestMapping(value = "/import")
    public String exImport(@RequestParam(value = "filename") MultipartFile file, HttpSession session) {
        return null;
    }


}

订单管理Controller:

/**
 * 订单Controller
 */
@Api("后台订单接口")
@RestController
public class OrderController {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	// 注入Service
	@Autowired
	private OrderService orderService;

	// 注入订单详情Service
	@Autowired
	private OrderDetailService orderDetailService;

	/**
	 * 订单列表
	 *
	 * @param page
	 * @param limit
	 * @return
	 */
	@ApiOperation(value = "订单列表", notes = "查询结果集合数据")
	@GetMapping("/admin/order/list")
	public ServerLayResult<Order> OrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
		return new ServerLayResult(0, "", orderService.count(), orderService.selectAll(page, limit));
	}

	/**
	 * 根据id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "订单删除", notes = "根据订单的id删除订单")
	@GetMapping("/admin/order/del")
	public String orderDel(@RequestParam(value = "id") Integer id) {
		logger.info("订单id----" + id);
		if (id != null && id > 0) {
			// 删除关联订单详情
			int index = orderDetailService.deleteByOrderId(id);
			if (index > 0) {
				int delete = orderService.deleteByPrimaryKey(id);
				if (delete > 0) {
					return "success";
				}
			}
		}
		return "error";
	}
}

源码获取:俺的博客首页 "资源" 里下载!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq1334611189

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值