基于javaweb+mysql的springboot前台+后台精品水果商城系统设计和实现(java+springboot+ssm+mysql+html+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot前台+后台精品水果商城系统设计和实现(java+springboot+ssm+mysql+html+maven)
一、项目简述
本系统主要实现的功能有: 前台用户的登录注册,水果商品的展示,水果的购物车, 购物车新增结算等等,银行卡的支付绑定,收货地址的维护,密码修改等等功能 后台管理的用户管理,商品管理,分类管理,订单管理等等。
二、项目运行
1运行环境
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + HTML + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等
@Controller
@RequestMapping("/admin/orders")
public class OrdersController {
@Autowired
private OrderEntityMapper orderDao;
@RequestMapping("/ordersList")
public ModelAndView classifyList(HttpServletRequest request){
ModelAndView mv = new ModelAndView();
Map<String, Object> param = new HashMap<String, Object>();
List<OrderEntity> orders = orderDao.listByMap(param);
mv.addObject("orders",orders);
mv.setViewName("/admin/order/order_list");
return mv;
}
}
@RequestMapping("/system")
@Controller
public class SystemController {
@RequestMapping("/contactus")
public String contactus(){
return "/customer/contact";
}
@RequestMapping("/codes")
public String codes(){
return "/customer/codes";
}
@RequestMapping("/testLayer")
public String testLayer(){
return "/test/testLayer";
}
}
mv.addObject("message","用户名不能为空");
}else if(StringUtils.isEmpty(password)){
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
}
UserEntity user = userEntityMapper.getByUserName(username);
session.setAttribute("userId", user.getId());
if(user != null){
mv.addObject("code","100");
mv.addObject("msg","密码错误");
if(user.getPassword().equals(password)){
mv.addObject("code","100");
mv.addObject("user",user);
mv.addObject("contextPath",request.getContextPath());
mv.setViewName("/customer/myinfo");
}
}
return mv;
}
@RequestMapping("/usercenter")
public ModelAndView usercenter(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView("/customer/login");
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
mv.setViewName("/customer/login");
return mv;
}
UserEntity user = userEntityMapper.selectById(userId);
if(user != null){
mv.addObject("code","100");
mv.addObject("user",user);
mv.addObject("contextPath",request.getContextPath());
mv.setViewName("/customer/myinfo");
}
return mv;
}
@RequestMapping("/myinfo")
public ModelAndView myinfo(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
mv.addObject("code","100");
return mv;
}
@RequestMapping("/updateCarPage")
public ModelAndView updateCarPage(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView("/customer/add_bank_car");
Integer userId = (Integer) session.getAttribute("userId");
BankCarEntity bankCarEntity = new BankCarEntity();
try {
bankCarEntity=bankDao.selectByUserId(userId);
mv.addObject("bankCar",bankCarEntity);
} catch (Exception e) {
e.printStackTrace();
}
return mv;
}
@RequestMapping("/updateCar")
public ModelAndView updateCar(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView();
Integer userId = (Integer) session.getAttribute("userId");
BankCarEntity bankCarEntity = new BankCarEntity();
bankCarEntity.setCarType(request.getParameter("carType"));
bankCarEntity.setCarPhone(request.getParameter("carPhone"));
bankCarEntity.setBankAddress(request.getParameter("bankAddress"));
bankCarEntity.setBankMoney(new BigDecimal(request.getParameter("bankMoney")));
bankCarEntity.setBankName(request.getParameter("bankName"));
bankCarEntity.setBankPassword(request.getParameter("bankPassword"));
bankCarEntity.setCarNumber(request.getParameter("carNumber"));
try {
UserEntity user = new UserEntity();
user = userEntityMapper.selectById(userId);
bankCarEntity.setModifier(user.getUserName());
bankCarEntity.setModifyTime(new Date());
bankDao.update(bankCarEntity);
mv.addObject("bankCar",bankCarEntity);
mv.setViewName("/customer/bank_car");
} catch (Exception e) {
e.printStackTrace();
}
return mv;
result.put("message","用户名不能为空");
}
String orderId = request.getParameter("orderId");
try {
UserEntity userEntity = new UserEntity();
userEntity=userEntityMapper.selectById(userId);
OrderEntity orderEntity =new OrderEntity();
orderEntity.setId(Integer.valueOf(orderId));
orderEntity.setModifier(userEntity.getUserName());
orderEntity.setModifyTime(new Date());
orderEntity.setStatus((short)3);
orderDao.update(orderEntity);
result.put("code", "200");
result.put("msg", "取消成功");
} catch (Exception e) {
e.printStackTrace();
result.put("code", "100");
result.put("msg", "删除失败");
}
return result;
}
/**
* 支付订单
* @param session
* @param request
* @return
*/
@RequestMapping("/payOrder")
@ResponseBody
@Transactional(propagation=Propagation.REQUIRED)
public JSONObject payOrder(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
result.put("code","100");
result.put("message","用户名不能为空");
}
String orderId = request.getParameter("orderId");
UserEntity userEntity = new UserEntity();
userEntity=userEntityMapper.selectById(userId);
@RequestMapping("/bankcarPage")
public ModelAndView contactusPage(HttpServletRequest request){
ModelAndView mv = new ModelAndView("/customer/add_bank_car");
return mv;
}
@RequestMapping("/bankcarInfo")
public ModelAndView bankcarInfo(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView("/customer/bank_car");
Integer userId = (Integer) session.getAttribute("userId");
try {
BankCarEntity bankCar = bankDao.selectByUserId(userId);
if(bankCar == null){
mv.setViewName("/customer/add_bank_car");
}
mv.addObject("bankCar",bankCar);
} catch (Exception e) {
e.printStackTrace();
}
return mv;
}
@RequestMapping("/addBankCar")
public ModelAndView addCar(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView();
Integer userId = (Integer) session.getAttribute("userId");
BankCarEntity bankCarEntity = new BankCarEntity();
bankCarEntity.setCarType(request.getParameter("carType"));
bankCarEntity.setCarPhone(request.getParameter("carPhone"));
bankCarEntity.setBankAddress(request.getParameter("bankAddress"));
bankCarEntity.setBankMoney(new BigDecimal(request.getParameter("bankMoney")));
bankCarEntity.setBankName(request.getParameter("bankName"));
bankCarEntity.setBankPassword(request.getParameter("bankPassword"));
bankCarEntity.setCarNumber(request.getParameter("carNumber"));
try {
UserEntity user = new UserEntity();
user = userEntityMapper.selectById(userId);
bankCarEntity.setUserId(userId);
bankCarEntity.setStatus((short)1);
bankCarEntity.setCreater(user.getUserName());
bankCarEntity.setIsDelete((short)0);
bankCarEntity.setCreateTime(new Date());
bankDao.insert(bankCarEntity);
mv.addObject("msg", "失败");
}
return mv;
}
@RequestMapping("/deleteOrder")
@ResponseBody
public JSONObject deleteOrder(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
result.put("code","100");
result.put("message","用户名不能为空");
return result;
}
String orderId = request.getParameter("orderId");
try {
orderDao.delete(Integer.valueOf(orderId));
result.put("code", "200");
result.put("msg", "删除成功");
} catch (Exception e) {
e.printStackTrace();
result.put("code", "100");
result.put("msg", "删除失败");
}
return result;
}
@RequestMapping("/cancleOrder")
@ResponseBody
public JSONObject cancleOrder(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
result.put("code","100");
result.put("message","用户名不能为空");
}
String orderId = request.getParameter("orderId");
try {
UserEntity userEntity = new UserEntity();
userEntity=userEntityMapper.selectById(userId);
OrderEntity orderEntity =new OrderEntity();
orderEntity.setId(Integer.valueOf(orderId));
orderEntity.setModifier(userEntity.getUserName());
@Controller
@RequestMapping("/admin/orders")
public class OrdersController {
@Autowired
private OrderEntityMapper orderDao;
@RequestMapping("/ordersList")
public ModelAndView classifyList(HttpServletRequest request){
ModelAndView mv = new ModelAndView();
Map<String, Object> param = new HashMap<String, Object>();
List<OrderEntity> orders = orderDao.listByMap(param);
mv.addObject("orders",orders);
mv.setViewName("/admin/order/order_list");
return mv;
}
}
@RequestMapping("/system")
@Controller
public class SystemController {
@RequestMapping("/contactus")
public String contactus(){
return "/customer/contact";
}
@Autowired
private OrderEntityMapper orderDao;
@Autowired
private UserEntityMapper userEntityMapper;
@Autowired
private ShopCarEntityMapper shopCarDao;
@Autowired
private BankCarEntityMapper bankDao;
@Autowired
private TranstacRecordEntityMapper transtacDao;
@RequestMapping("/addOrder")
@ResponseBody
@Transactional(propagation=Propagation.NOT_SUPPORTED)
public JSONObject addOrder(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
String carIds = request.getParameter("carIds");
JSONArray jsonCarIds = JSONArray.parseArray(carIds);
if(userId == null){
result.put("code","100");
result.put("message","用户名不能为空");
}
try {
OrderEntity orderEntity = new OrderEntity();
for(Object item : jsonCarIds){
JSONObject param = (JSONObject) item;
ShopCarEntity shopCarEntity = shopCarDao.selectById(param.getInteger("carId"));
UserEntity user = userEntityMapper.selectById(userId);
orderEntity.setCreater(user.getName());
orderEntity.setCreateTime(new Date());
orderEntity.setOrderAddress(shopCarEntity.getReceiveAddress());
orderEntity.setOrderCode(RandomUtils.randomString(5)+RandomUtils.randomNumber(8));
orderEntity.setProductNumber(jsonCarIds.size());
if(orderEntity.getCountMoney() != null){
orderEntity.setOrderMoney(shopCarEntity.getRelPrice().add(orderEntity.getCountMoney()));
orderEntity.setDiscountMoney(shopCarEntity.getDiscountPrice().add(orderEntity.getDiscountMoney()));
orderEntity.setCountMoney(shopCarEntity.getCountProce().add(orderEntity.getOrderMoney()));
orderEntity.setProductName(shopCarEntity.getProductName()+" , "+orderEntity.getProductName());
}else{
orderEntity.setOrderMoney(shopCarEntity.getRelPrice());
orderEntity.setDiscountMoney(shopCarEntity.getDiscountPrice());
orderEntity.setCountMoney(shopCarEntity.getCountProce());
orderEntity.setProductName(shopCarEntity.getProductName());
}
orderEntity.setStatus((short)1);
orderEntity.setIsDelete((short)0);
orderEntity.setOrderUserId(userId);
shopCarEntity.setStatus((short)2);
shopCarDao.update(shopCarEntity);
}
orderDao.insert(orderEntity);
result.put("code", "200");
}
Map<String, Object> param = new HashMap<String, Object>();
List<UserEntity> userEntities = userEntityMapper.listByMap(param);
mv.addObject("username",username);
mv.addObject("users",userEntities);
mv.setViewName("/admin/user/user_list");
return mv;
}
}
@Controller
@RequestMapping("/admin/classify")
public class ClassifyController {
@Autowired
private ClassifyEntityMapper classifyDao;
@RequestMapping("/addClassifyPage")
public String addClassifyPage(){
return "/admin/classify/classify_add";
}
@RequestMapping("/addClassify")
public String addClassify(HttpServletRequest request,ClassifyEntity classify){
try {
if(classify != null){
classify.setCreater("admin");
classify.setCreateTime(new Date());
classify.setStatus((short)1);
// result.put("code","100");
// result.put("msg","库存不足");
// return result;
// }
shopCarEntity.setProductNum(Integer.parseInt(number));
shopCarEntity.setId(Integer.parseInt(carId));
shopCarDao.update(shopCarEntity);
result.put("code","200");
result.put("msg","删除成功");
} catch (Exception e) {
e.printStackTrace();
result.put("code","100");
result.put("msg","系统异常");
}
return result;
}
}
@Controller
@RequestMapping("/bankcar")
public class BankCarController {
@Autowired
private UserEntityMapper userEntityMapper;
@Autowired
private BankCarEntityMapper bankDao;
@RequestMapping("/bankcarPage")
public ModelAndView contactusPage(HttpServletRequest request){
ModelAndView mv = new ModelAndView("/customer/add_bank_car");
return mv;
}
@RequestMapping("/bankcarInfo")
Integer userId = (Integer) session.getAttribute("userId");
try {
Map<String, Object> param = new HashMap<String, Object>();
param.put("userId", userId);
param.put("status", 1);
List<ShopCarEntity> shopCarEntities = shopCarDao.listByMap(param);
mv.addObject("shopCars",shopCarEntities);
mv.setViewName("/customer/shop_car");
} catch (Exception e) {
e.printStackTrace();
}
return mv;
}
/**
* 删除购物车信息
* @param request
* @param session
* @return
*/
@RequestMapping("/deleShopCar")
@ResponseBody
public JSONObject deleShopCar(HttpServletRequest request,HttpSession session){
JSONObject result = new JSONObject();
try {
Integer userId = (Integer) session.getAttribute("userId");
String carId = request.getParameter("carId");
UserEntity userEntity = userDao.selectById(userId);
if(userEntity != null){
shopCarDao.delete(Integer.valueOf(carId));
}
result.put("msg", "删除购物车成功");
result.put("code", "200");
} catch (Exception e) {
e.printStackTrace();
result.put("msg", "系统异常");
result.put("code", "500");
}
return result;
}
@RequestMapping("/delete")
@ResponseBody
public JSONObject delete(HttpServletRequest request){
JSONObject result = new JSONObject();
String carId = request.getParameter("carId");
if(StringUtils.isEmpty(carId)){
result.put("code","100");
result.put("msg","");
param.put("status", 1);
List<ShopCarEntity> shopCarEntities = shopCarDao.listByMap(param);
mv.addObject("shopCars",shopCarEntities);
mv.setViewName("/customer/shop_car");
} catch (Exception e) {
e.printStackTrace();
}
return mv;
}
/**
* 删除购物车信息
* @param request
* @param session
* @return
*/
@RequestMapping("/deleShopCar")
@ResponseBody
public JSONObject deleShopCar(HttpServletRequest request,HttpSession session){
JSONObject result = new JSONObject();
try {
Integer userId = (Integer) session.getAttribute("userId");
String carId = request.getParameter("carId");
UserEntity userEntity = userDao.selectById(userId);
if(userEntity != null){
shopCarDao.delete(Integer.valueOf(carId));
}
result.put("msg", "删除购物车成功");
result.put("code", "200");
} catch (Exception e) {
e.printStackTrace();
result.put("msg", "系统异常");
result.put("code", "500");
}
return result;
}
@RequestMapping("/delete")
@ResponseBody
public JSONObject delete(HttpServletRequest request){
JSONObject result = new JSONObject();
String carId = request.getParameter("carId");
if(StringUtils.isEmpty(carId)){
result.put("code","100");
result.put("msg","");
return result;
}
try {
shopCarDao.delete(Integer.parseInt(carId));
try {
Integer userId = (Integer) session.getAttribute("userId");
String carId = request.getParameter("carId");
UserEntity userEntity = userDao.selectById(userId);
if(userEntity != null){
shopCarDao.delete(Integer.valueOf(carId));
}
result.put("msg", "删除购物车成功");
result.put("code", "200");
} catch (Exception e) {
e.printStackTrace();
result.put("msg", "系统异常");
result.put("code", "500");
}
return result;
}
@RequestMapping("/delete")
@ResponseBody
public JSONObject delete(HttpServletRequest request){
JSONObject result = new JSONObject();
String carId = request.getParameter("carId");
if(StringUtils.isEmpty(carId)){
result.put("code","100");
result.put("msg","");
return result;
}
try {
shopCarDao.delete(Integer.parseInt(carId));
result.put("code","200");
result.put("msg","删除成功");
} catch (Exception e) {
e.printStackTrace();
result.put("code","100");
result.put("msg","系统异常");
}
return result;
}
@RequestMapping("/updateProNum")
@ResponseBody
public JSONObject updateProNum(HttpServletRequest request){
JSONObject result = new JSONObject();
String carId = request.getParameter("carId");
mv.addObject("message","用户名不能为空");
mv.setViewName("/admin/admin_login");
return mv;
}else if(!adminUsername.equals(username)){
mv.addObject("code","100");
mv.addObject("message","用户名不正确");
mv.setViewName("/admin/admin_login");
return mv;
}else if(!adminPassword.equals(password)){
mv.addObject("code","100");
mv.addObject("message","密码 不正确");
mv.setViewName("/admin/admin_login");
return mv;
}
Map<String, Object> param = new HashMap<String, Object>();
List<UserEntity> userEntities = userEntityMapper.listByMap(param);
mv.addObject("username",username);
mv.addObject("users",userEntities);
mv.setViewName("/admin/user/user_list");
return mv;
}
}
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
}
UserEntity user = userEntityMapper.getByUserName(username);
if(user != null){
mv.addObject("code","100");
mv.addObject("msg","用户名已存在");
}else{
UserEntity userEntity = new UserEntity();
userEntity.setUserName(username);
userEntity.setCreater(username);
userEntity.setCreateTime(new Date());
userEntity.setEmail(email);
userEntity.setIsDelete((short)0);
userEntity.setPassword(password);
userEntity.setSex((short)1);
userEntity.setName(username);
userEntity.setAddress(address);
userEntity.setPhone(phone);
userEntity.setStatus((short)1);
userEntity.setUserCode(RandomUtils.randomString(4)
+RandomUtils.randomNumber(6));
userEntityMapper.insert(userEntity);
mv.addObject("code","200");
mv.addObject("msg","注册成功");
mv.addObject("data",username);
mv.setViewName("/customer/login");
}
return mv;
}
@RequestMapping("/shopcar")
public ModelAndView shopcar(HttpServletRequest request){
ModelAndView mv = new ModelAndView("/customer/login");
String username = request.getParameter("username");
String password = request.getParameter("password");
if(StringUtils.isEmpty(username)){
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
}else if(StringUtils.isEmpty(password)){
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
mv.addObject("code","100");
mv.addObject("user",user);
mv.addObject("contextPath",request.getContextPath());
mv.setViewName("/customer/myinfo");
}
return mv;
}
@RequestMapping("/myinfo")
public ModelAndView myinfo(HttpServletRequest request,HttpSession session){
ModelAndView mv = new ModelAndView();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
}
UserEntity user = userEntityMapper.selectById(userId);
if(user != null){
mv.addObject("code","100");
mv.addObject("user",user);
mv.addObject("contextPath",request.getScheme()+"://"+request.getRemoteAddr()+request.getRemotePort());
System.out.println(request.getScheme()+"://"+request.getRemoteAddr()+request.getRemotePort());
mv.setViewName("/customer/myinfo");
}else{
mv.addObject("code","100");
mv.addObject("msg","用户不存在");
}
return mv;
}
@RequestMapping("/changePasswordPage")
public String changePasswordPage(){
return "/customer/change_password";
}
@RequestMapping("/changePassword")
@ResponseBody
public JSONObject changePassword(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
result.put("code","100");
result.put("msg","用户名不能为空");
}
try {
String oldPassword = request.getParameter("oldPassword");
String newPassword = request.getParameter("newPassword");
String againPassword = request.getParameter("againPassword");
if(StringUtils.isEmpty(oldPassword)){
ModelAndView mv = new ModelAndView();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
mv.addObject("code","100");
mv.addObject("message","用户名不能为空");
}
UserEntity user = userEntityMapper.selectById(userId);
if(user != null){
mv.addObject("code","100");
mv.addObject("user",user);
mv.addObject("contextPath",request.getScheme()+"://"+request.getRemoteAddr()+request.getRemotePort());
System.out.println(request.getScheme()+"://"+request.getRemoteAddr()+request.getRemotePort());
mv.setViewName("/customer/myinfo");
}else{
mv.addObject("code","100");
mv.addObject("msg","用户不存在");
}
return mv;
}
@RequestMapping("/changePasswordPage")
public String changePasswordPage(){
return "/customer/change_password";
}
@RequestMapping("/changePassword")
@ResponseBody
public JSONObject changePassword(HttpSession session,HttpServletRequest request){
JSONObject result = new JSONObject();
Integer userId = (Integer) session.getAttribute("userId");
if(userId == null){
result.put("code","100");
result.put("msg","用户名不能为空");
}
try {
String oldPassword = request.getParameter("oldPassword");
String newPassword = request.getParameter("newPassword");
String againPassword = request.getParameter("againPassword");
if(StringUtils.isEmpty(oldPassword)){
result.put("code","100");
result.put("msg","原始密码不能为空");
return result;
}else if(StringUtils.isEmpty(newPassword)){
result.put("code","100");
result.put("msg","新密码不能为空");
return result;
}else if(StringUtils.isEmpty(againPassword)){
result.put("code","100");
result.put("msg","重复密码不能为空");
return result;
}else if(!newPassword.equals(againPassword)){
result.put("code","100");
result.put("msg","两次密码不一致");
}
Map<String, Object> param = new HashMap<String, Object>();
List<UserEntity> userEntities = userEntityMapper.listByMap(param);
mv.addObject("username",username);
mv.addObject("users",userEntities);
mv.setViewName("/admin/user/user_list");
return mv;
}
}
@Controller
@RequestMapping("/admin/classify")
public class ClassifyController {
@Autowired
private ClassifyEntityMapper classifyDao;
@RequestMapping("/addClassifyPage")
public String addClassifyPage(){
return "/admin/classify/classify_add";
}