基于javaweb+mysql的springboot汽车配件销售管理系统(java+springboot+layui+html+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot汽车配件销售管理系统(java+springboot+layui+html+maven+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版本;
6.是否Maven项目:是;
技术栈
-
后端:SpringBoot
-
前端:HTML+CSS+JavaScript+layui
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8081/ 登录
管理员:admin/123456
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控制器
*/
@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,
//放行
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
@ControllerAdvice
public class MyExceptionHandler {
@ResponseBody
@ExceptionHandler(Exception.class)
public Map<String, Object> handleException(Exception e) {
Map<String, Object> map = new HashMap<>();
map.put("code", 100);
map.put("message", e.getMessage());
return map;
}
}
/**
* 控制台页面
*/
@Api("主页接口")
@Controller
public class ConsoleController {
@GetMapping("/")
public String loginUi() {
return "admin/index";
/*
* 动态获取数据库列 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;
}
}
/**
* 生成验证码
*
* @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 = "注销接口")
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;
}
}
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());
}
* @return
*/
@SuppressWarnings("rawtypes")
@ApiOperation(value = "公告模块接口",notes = "公告结果列表")
@GetMapping("/admin/notice/list")
public ServerLayResult<Notice> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
@SuppressWarnings("unchecked")
ServerLayResult<Notice> result = new ServerLayResult(0, "", noticeService.count(), noticeService.selectAll(page, limit));
return result;
}
/**
* 根据id删除
*
* @param id
* @return
*/
@ApiOperation(value = "公告删除接口",notes = "根据公告id删除公告")
@GetMapping("/admin/notice/del")
public String delete(Integer id) {
System.out.println("id = " + id);
int row = noticeService.deleteByPrimaryKey(id);
if (row > 0) {
return "success";
}
return "error";
}
/**
* 更新
*
* @param notice
* @return
*/
@ApiOperation(value = "更新公告接口",notes = "根据公告前台json数据对象进行删除公告!")
@PostMapping("/admin/notice/update")
public String update(@RequestBody Notice notice) {
Notice upNotice = notice;
}
@ApiOperation(value = "登出接口", notes = "注销接口")
@GetMapping("/logout")
public String logout(HttpSession session) {
//销毁session
session.invalidate();
return "/admin/login";
}
}
/**
* 配件类型控制器
*/
@Api("配件类型API接口")
@RestController
public class GoodsTypeController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private GoodsTypeService goodsTypeService;
/**
* 下拉动态加载
*
* @return
*/
@ApiOperation(value = "配件类型接口",notes = "用于动态更新加载配件类型")
@PostMapping("/admin/goodstype/list")
public List<GoodsType> list() {
/**
* 用户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;
}
/**
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
@ControllerAdvice
public class MyExceptionHandler {
@ResponseBody
@ExceptionHandler(Exception.class)
public Map<String, Object> handleException(Exception e) {
Map<String, Object> map = new HashMap<>();
map.put("code", 100);
map.put("message", e.getMessage());
return map;
}
}
/**
* 控制台页面
*/
@Api("主页接口")
@Controller
public class ConsoleController {
@GetMapping("/")
public String loginUi() {
/**
* 订单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")
GoodsType goodsType = new GoodsType();
goodsType.setId(Integer.parseInt(goodstypeId));
goods.setGoodstypeId(goodsType);
goods.setIputTime(new Date());
goods.setGpicture("/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("/views/upload/" + image);
int insert = goodsService.insert(goods);
if (insert > 0) {
return "success";
}
return "error";
}
/**
* 实现文件上传
*/
public ServerLayResult goodsTypeList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
int count = goodsTypeService.count();
//分页
PageHelper.startPage(page, limit);
List<GoodsType> goodsTypes = goodsTypeService.selectAll();
PageInfo info = new PageInfo(goodsTypes);
//组装数据
ServerLayResult result = new ServerLayResult(0, "", count, info.getList());
return result;
}
/**
* 配件添加
*
* @param goodsType
* @return
*/
@ApiOperation(value = "配件类型保存接口",notes = "根据前台传入的json数据对象进行保存配件类型")
@PostMapping("/admin/goodsType/save")
public String addGoodsType(@RequestBody GoodsType goodsType) {
logger.info("goodsType===" + goodsType);
int insert = goodsTypeService.insert(goodsType);
if (insert > 0) {
return "success";
}
return "error";
}
/**
* 根据id删除配件类型
*
* @param id
* @return
*/
@ApiOperation(value = "配件类型删除接口",notes = "根据配件ID删除配件类型")
@GetMapping("/admin/goodsType/del")
public String delGoodsType(@RequestParam(value = "id") Integer id) {
logger.info("删除的配件类型ID=" + id);
int del = goodsTypeService.deleteByPrimaryKey(id);
if (del > 0) {
return "success";
}
return "error";
}
/**
/**
* 订单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);
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);
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("用户电话");//为第三个单元格设值
*/
@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