Java项目:SSM网上汽车配件商城

139 篇文章 4 订阅
111 篇文章 0 订阅

作者主页:夜未央5788

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目分为前后台,前台为普通用户角色,后台为管理员角色;
管理员角色包含以下功能:
人员管理,修改个人信息,图片管理,图表管理,管理员登录,订单管理,配件管理等功能。

用户角色包含以下功能:
修改个人信息,提交付款,查看商品详情,查看我的订单,查看购物车,查看首页,用户登录,确认订单等功能。

由于本程序规模不大,可供课程设计,毕业设计学习演示之用

环境需要

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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

6.数据库:MySql 5.7、8.0等版本均可;

技术栈

1. 后端:Spring springmvc mybatis

2. 前端:JSP+css+javascript+jQuery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2.使用IDEA/Eclipse/MyEclipse导入项目,配置tomcat;
3. 将项目中config/jdbc.properties配置文件中的数据库配置改为自己的配置;
4.运行项目,前台地址:http://localhost:8080/snack/shop/index
用户账号/密码: user/123456

后台地址:http://localhost:8080/snack/admin/login/adminLogin

管理员账号/密码:admin/admin

运行截图

前台界面-用户角色

 

 

 

 

管理员角色

 

 

 

 

相关代码 

配件管理控制器

@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;
    }


}

后台登录管理控制器

/**
 * 后台系统登入控制器
 */
@Api(value = "登入接口API")
@Controller
public class LoginController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    //注入
    @Autowired
    private Producer producer;

    @Autowired
    private AdminUserService adminUserService;

    /**
     * @return
     */
    @ApiOperation(value = "控制登入跳转", notes = "登入控制器跳转")
    @GetMapping("/admin/login")
    public String showLogin() {

        return "admin/login";
    }

    @ApiOperation(value = "登入处理接口", notes = "根据json对象处理登入")
    @PostMapping("/admin/login_do")
    @ResponseBody
    public String loginDo(@RequestBody AdminUser user, HttpServletRequest request) {
        logger.info("登入用户的信息:" + user);
        String vrifyCode = (String) request.getSession().getAttribute("vrifyCode");
        if (user != null) {
            AdminUser adminUser = adminUserService.selectByUser(user.getAusername(), user.getApassword());
            if (adminUser == null) {
                return "passwordError";
            } else if (!vrifyCode.equals(user.getVercode())) {
                return "vrifyCodeErroe";
            }
            request.getSession().setAttribute("loginName", user);
            return "success";
        } else {
            return "userNull";
        }
    }


    /**
     * 生成验证码
     *
     * @param httpServletRequest
     * @param httpServletResponse
     * @throws Exception
     */
    @ApiOperation(value = "验证码接口API", notes = "用于更新验证码")
    @GetMapping("/defaultKaptcha")
    public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws Exception {
        byte[] captchaChallengeAsJpeg = null;
        ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
        try {
            //生产验证码字符串并保存到session中
            String createText = producer.createText();
            httpServletRequest.getSession().setAttribute("vrifyCode", createText);
            //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中
            BufferedImage challenge = producer.createImage(createText);
            ImageIO.write(challenge, "jpg", jpegOutputStream);
        } catch (IllegalArgumentException e) {
            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        //定义response输出类型为image/jpeg类型,使用response输出流输出图片的byte数组
        captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
        httpServletResponse.setHeader("Cache-Control", "no-store");
        httpServletResponse.setHeader("Pragma", "no-cache");
        httpServletResponse.setDateHeader("Expires", 0);
        httpServletResponse.setContentType("image/jpeg");
        ServletOutputStream responseOutputStream =
                httpServletResponse.getOutputStream();
        responseOutputStream.write(captchaChallengeAsJpeg);
        responseOutputStream.flush();
        responseOutputStream.close();
    }


    @ApiOperation(value = "登出接口", notes = "注销接口")
    @GetMapping("/logout")
    public String logout(HttpSession session) {
        //销毁session
        session.invalidate();
        return "/admin/login";
    }

}

如果也想学习本系统,下面领取。关注并回复:259ssm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜未央5788

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

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

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

打赏作者

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

抵扣说明:

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

余额充值