一、项目简述
功能:一个基于javaweb+mysql的网上书店的设计与实现,归纳 出了几个模块,首先是登录注册模块,图书查找模块,购 物车模块,订单模块,个人中心模块,用户管理模块,图 书管理模块等。 该项目是javaJeb技术的实战操作,采用了MVC设计模 式,包括基本的entity, jscript, servlet,以及ajax异步请 求,查询分页,持久化层方法的封装等等,对javaweb技 术的巩固很有帮助,为J2EE的学习打下基础,适用于课程 设计,毕业设计。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术: JSP + Entity+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload 等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
}
}
@GetMapping("/payPage/{orderId}")
public String toPay(@PathVariable("orderId") String orderId, Model model) {
BSResult bsResult = orderService.findOrderById(orderId);
if (bsResult.getCode() == 200) {
model.addAttribute("order", bsResult.getData());
return "payment";
}
return "exception";
}
@RequestMapping("/deletion/{orderId}")
public String deletion(@PathVariable("orderId") String orderId) {
BSResult bsResult = orderService.deleteOrder(orderId);
if (bsResult.getCode() == 200) {
return "redirect:/order/list";
}
return "exception";
}
/**
* 订单列表
*
* @return
*/
@GetMapping("/list")
public String orderList(HttpServletRequest request) {
return "payment";
} else {
request.setAttribute("exception", bsResult.getMessage());
return "exception";
}
}
//普通购物车
Cart cart = (Cart) request.getSession().getAttribute("cart");
if (cart != null) {
BSResult bsResult = orderService.createOrder(cart, userDTO, express, payMethod);
if (bsResult.getCode() == 200) {
request.setAttribute("order", bsResult.getData());
cartService.clearCart(request, "cart");
return "payment";
} else {
request.setAttribute("exception", bsResult.getMessage());
return "exception";
}
SecurityUtils.getSubject().logout();
return "redirect:/page/login";
}
/**
* 注册 检验用户名是否存在
*
* @param username
* @return
*/
@RequestMapping("/checkUserExist")
@ResponseBody
public BSResult checkUserExist(String username) {
if (StringUtils.isEmpty(username)) {
return BSResultUtil.build(200, USERNAME_CANNOT_NULL, false);
}
return userService.checkUserExistByUsername(username);
}
return "redirect:" + url;
} catch (UnknownAccountException | IncorrectCredentialsException uae) {
model.addAttribute("loginMsg", USERNAME_PASSWORD_NOT_MATCH);
return "login";
} catch (LockedAccountException lae) {
model.addAttribute("loginMsg", "账户已被冻结!");
return "login";
} catch (AuthenticationException ae) {
model.addAttribute("loginMsg", "登录失败!");
return "login";
}
} else {
//用户已经登录
return "redirect:/index";
}
}
@RequestMapping("/info")
public String personInfo(){
return "user_info";
}
* @param user
* @return
*/
@RequestMapping("/register")
public String register(User user, Model model) {
BSResult isExist = checkUserExist(user.getUsername());
//尽管前台页面已经用ajax判断用户名是否存在,
// 为了防止用户不是点击前台按钮提交表单造成的错误,后台也需要判断
if ((Boolean) isExist.getData()) {
user.setActive("1");
BSResult bsResult = userService.saveUser(user);
//获得未激活的用户
User userNotActive = (User) bsResult.getData();
/* try {
mailService.sendHtmlMail(user.getEmail(), "<dd书城>---用户激活---",
"<html><body><a href='http://"+ip+"/user/active?activeCode=" + userNotActive.getCode() + "'>亲爱的" + user.getUsername() +
",请您点击此链接前往激活</a></body></html>");
} catch (Exception e) {
e.printStackTrace();
model.addAttribute("registerError", "发送邮件异常!请检查您输入的邮箱地址是否正确。");
return "fail";
}*/
model.addAttribute("username", user.getUsername());
return "register_success";
} else {
//用户名已经存在,不能注册
return "exception";
}
}
}
书籍信息控制层:
@Controller
@RequestMapping("/book")
public class BookInfoController {
@Autowired
private IBookInfoService bookInfoService;
@Autowired
private BookDescMapper bookDescMapper;
/**
* 查询某一本书籍详情
*
return "order_list";
}
/**
* 创建订单
*
* @return
*/
@PostMapping("/creation")
public String createOrder(User userDTO, String express, int payMethod, HttpServletRequest request) {
//立即购买,优先创建订单
Cart buyNowCart = (Cart) request.getSession().getAttribute("buyNowCart");
User loginUser = (User) request.getSession().getAttribute("loginUser");
userDTO.setUserId(loginUser.getUserId());
userDTO.setZipCode(loginUser.getZipCode());
if (buyNowCart != null) {
BSResult bsResult = orderService.createOrder(buyNowCart, userDTO, express, payMethod);
if (bsResult.getCode() == 200) {
request.setAttribute("order", bsResult.getData());
cartService.clearCart(request, "buyNowCart");
return "payment";
} else {
request.setAttribute("exception", bsResult.getMessage());
return "exception";
}
}
//普通购物车
public String register(User user, Model model) {
BSResult isExist = checkUserExist(user.getUsername());
//尽管前台页面已经用ajax判断用户名是否存在,
// 为了防止用户不是点击前台按钮提交表单造成的错误,后台也需要判断
if ((Boolean) isExist.getData()) {
user.setActive("1");
BSResult bsResult = userService.saveUser(user);
//获得未激活的用户
User userNotActive = (User) bsResult.getData();
/* try {
mailService.sendHtmlMail(user.getEmail(), "<dd书城>---用户激活---",
"<html><body><a href='http://"+ip+"/user/active?activeCode=" + userNotActive.getCode() + "'>亲爱的" + user.getUsername() +
",请您点击此链接前往激活</a></body></html>");
} catch (LockedAccountException lae) {
model.addAttribute("loginMsg", "账户已被冻结!");
return "login";
} catch (AuthenticationException ae) {
model.addAttribute("loginMsg", "登录失败!");
return "login";
}
} else {
//用户已经登录
return "redirect:/index";
}
}
@RequestMapping("/info")
public String personInfo(){
return "user_info";
}
/* @RequestMapping("/login1")
public String login1(@RequestParam(value = "username", required = false) String username,
@RequestParam(value = "password", required = false) String password,
Model model, HttpServletRequest request) {
if (StringUtils.isEmpty(username)) {
model.addAttribute("loginMsg", USERNAME_CANNOT_NULL);
return "login";
}
if (StringUtils.isEmpty(password)) {
model.addAttribute("loginMsg", "密码不能为空");
model.addAttribute("recommendBookList", recommendBookList);
return "book_info";
}
/**
* 通过关键字和书籍分类搜索书籍列表
*
* @param keywords
* @return
*/
@RequestMapping("/list")
public String bookSearchList(@RequestParam(defaultValue = "", required = false) String keywords,
@RequestParam(defaultValue = "0", required = false) int cateId,//分类Id,默认为0,即不按照分类Id查
@RequestParam(defaultValue = "1", required = false) int page,
@RequestParam(defaultValue = "6", required = false) int pageSize,
Model model) {
keywords = keywords.trim();
PageInfo<BookInfo> bookPageInfo = bookInfoService.findBookListByCondition(keywords, cateId, page, pageSize,0);//storeId为0,不按照商店Id查询
model.addAttribute("bookPageInfo", bookPageInfo);
model.addAttribute("keywords", keywords);
model.addAttribute("cateId", cateId);
return "book_list";
}
}