源码获取:俺的博客首页 "资源" 里下载!
本系统分为前后台,分为管理员与普通用户两种角色,前台由普通用户登录,后台由管理员登录;
管理员:
登录,修改个人资料,用户管理,公告管理,教室管理,科目管理,听课记录管理等功能。
用户角色包含以下功能:
用户登录,修改个人资料,查看公告,查看听课记录等功能。
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项目:否;
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+jQuery+Ajax
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,http://localhost:8080/
用户账号/密码: user/123456
管理员账号/密码:admin/admin
- @Controller
- public class orderController {
- @Autowired
- private OrderService orderService;
-
- @RequestMapping("/toOrder")
- public String toOrder(HttpServletRequest request,Model model) throws Exception {
- Orders orders = new Orders();
- Cart cart = (Cart) request.getSession().getAttribute("cart");
- User loginUser = (User) request.getSession().getAttribute("loginUser");
- if(loginUser==null){
- model.addAttribute("message", "对不起您还没有登录");
- return "msg";
- }
- // 0表示没有付款、1表示已付款即将发货 2表示确认收货 3表示交易成功
- orders.setState(0);
- orders.setOrderTime(new Date());
- orders.setUid(loginUser.getUid());
- orders.setMoney(cart.getTotale());
-
- orderService.toOrder(orders);
-
- Map<Integer, CartItem> cartItems = cart.getCartItem();
- for (Entry<Integer, CartItem> entry : cartItems.entrySet()) {
- CartItem cartItem = entry.getValue();
- Orderitem orderitem = new Orderitem();
- orderitem.setProduct(cartItem.getProduct());
- orderitem.setCount(cartItem.getCount());
- orderitem.setPid(cartItem.getProduct().getPid());
- orderitem.setSubtotal(cartItem.getSubtotle());
- orderitem.setOid(orders.getOid());
- orders.getOiList().add(orderitem);
- orderService.toOrderItem(orderitem);
- }
- cart.clearCart();
- request.getSession().setAttribute("orders", orders);
- return "order";
- }
-
- // 为定单付款
- @RequestMapping("/payOrder")
- public String payOrder(Orders orders,@RequestParam String receiveInfo,@RequestParam String phoNum,@RequestParam String accepter) throws Exception {
- orders.setReceiveinfo(receiveInfo);
- orders.setPhonum(phoNum);
- orders.setAccepter(accepter);
- orderService.payOrder(orders);
- return "redirect:myOrder.action?page=1";
- }
- //payOrderAganin
- @RequestMapping("/payOrderAganin")
- public String payOrderAganin(@RequestParam int oid,HttpServletRequest request){
- Orders noPayOrder = orderService.findOrderByOid(oid);
- request.getSession().setAttribute("orders", noPayOrder);
- return "order";
- }
- // 查询myOrder
- @RequestMapping("/myOrder")
- public String myOrder(@RequestParam int page, Model model,
- HttpServletRequest request) throws Exception {
- User loginUser = (User) request.getSession().getAttribute("loginUser");
- PageBean<Orders> pageBean = orderService.findOrderByUidAndPage(page,loginUser.getUid());
- model.addAttribute("pageBean", pageBean);
- return "orderList";
- }
-
- // 确认收货
- @RequestMapping("/updateState")
- public String updateState(@RequestParam int oid ) throws Exception {
- orderService.updateOrderStatus(oid, 3);
- return "redirect:myOrder.action?page=1";
- }
- }
- @Controller
- public class loginController {
-
- @Autowired
- private UserService userService;
-
- @RequestMapping("login")
- public String login() {
- return "login";
- }
-
- // 用户登录
- @RequestMapping("/userLogin")
- public String userLogin(HttpServletRequest request,
- @RequestParam String checkImg, User user, Model model)
- throws zdyException, Exception {
- String sessionCode = (String) request.getSession().getAttribute(
- "checkcode");
- if (!sessionCode.equalsIgnoreCase(checkImg)) {
- //model.addAttribute("message", "验证码输入错误请重新注册");
- //throw new zdyException("验证码输入错误请重新注册");
- request.getSession().setAttribute("message", "验证码输入错误请重新注册");
- return "redirect:login.action";
- }
- User loginUser = userService.loginFindByUnameAndPwd(user.getUsername(),
- user.getPassword());
- if (loginUser == null) {
- //model.addAttribute("message", "密码输入错误请重新登陆");
- request.getSession().setAttribute("message", "密码输入错误请重新登陆");
- //throw new zdyException("密码输入错误请重新登陆");
- return "redirect:login.action";
- }
- request.getSession().setAttribute("loginUser", loginUser);
- request.getSession().removeAttribute("message");
- return "redirect:index.action";
- }
-
- // 用户退出
- @RequestMapping("userLogout")
- public String userLogout(HttpServletRequest request,
- HttpServletResponse response, Model model) {
- request.getSession().removeAttribute("loginUser");
- response.setHeader("content-type", "text/html;charset=UTF-8");
- response.setHeader("refresh", "5;url=/shop/index.action");
- model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
- return "msg";
- }
-
- //进入管理员页面
- @RequestMapping("/admin")
- public String AdminIndex(){
- return "admin/index";
- }
- //admin/adminUser_login.action
- //adminUser_login管理员登录
- @RequestMapping("/admin/adminUser_login")
- public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
- Adminuser adminuserLogin = userService.adminUser_login(username,password);
- System.out.println(username);
- System.out.println(password);
- if(adminuserLogin == null){
- model.addAttribute("message", "改用户未被授予管理员身份!");
- return "admin/index";
- }
- request.getSession().setAttribute("adminuserLogin", adminuserLogin);
- // model.addAttribute("adminuserLogin", adminuserLogin);
- return "admin/home";
- }
-
- }
- @Controller
- public class cartController {
- @Autowired
- private ProductService productService;
- // 添加到购物车
- @RequestMapping("/addCart")
- public String addCart(HttpServletRequest request,@RequestParam int pid,@RequestParam int count ,Model model){
- Product product = productService.finbProductByPid(pid);
- // 存进一个购物项
- CartItem cartItem = new CartItem();
- cartItem.setCount(count);
- cartItem.setProduct(product);
- cartItem.setSubtotle(count*product.getShopPrice());
- // 存进购物车
- Cart cart=getCart(request);
- cart.addCart(cartItem);
- return "cart";
- }
- // 查看我的购物车
- @RequestMapping("/myCart")
- public String myCart(HttpServletRequest request,Model model){
- User loginUser = (User) request.getSession().getAttribute("loginUser");
- if (loginUser == null) {
- model.addAttribute("message","您还没有登录!");
- return "msg";
- }
- return "cart";
- }
-
- // 清空购物车
- @RequestMapping("/clearCart")
- public String clearCart(HttpServletRequest request){
- Cart cart=getCart(request);
- cart.clearCart();
- return "redirect:myCart.action";
- }
- // 删除某个购物项
- @RequestMapping("/delProFromCart")
- public String delProFromCart(@RequestParam int pid,HttpServletRequest request){
- Cart cart=getCart(request);
- cart.delProFromCart(pid);
- return "redirect:myCart.action";
- }
- public Cart getCart(HttpServletRequest request) {
- Cart cart = (Cart) request.getSession().getAttribute("cart");
- if (cart == null) {
- cart = new Cart();
- request.getSession().setAttribute("cart", cart);
- }
- return cart;
- }
- }
源码获取:俺的博客首页 "资源" 里下载!