基于javaweb+mysql的ssm宠物商城带后台管理系统(java+ssm+jsp+jquery+ajax+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM宠物商城带后台管理系统(java+ssm+jsp+jquery+ajax+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项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+jQuery+Ajax
使用说明
- 使用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
// String words
// ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
String words = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a\u5730\u5230\u5927\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7\u51fa\u5c0f\u4e48\u8d77\u4f60\u90fd\u628a\u597d\u8fd8";
Random random = new Random();// 生成随机数
// 定义StringBuffer
StringBuffer sb = new StringBuffer();
// 定义x坐标
int x = 10;
for (int i = 0; i < 4; i++) {
// 随机颜色
graphics2d.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
// 旋转 -30 --- 30度
int jiaodu = random.nextInt(60) - 30;
// 换算弧度
double theta = jiaodu * Math.PI / 180;
// 生成一个随机数字
int index = random.nextInt(words.length()); // 生成随机数 0 到 length - 1
// 获得字母数字
char c = words.charAt(index);
sb.append(c);
// 将c 输出到图片
graphics2d.rotate(theta, x, 20);
graphics2d.drawString(String.valueOf(c), x, 20);
graphics2d.rotate(-theta, x, 20);
x += 30;
}
// 将生成的字母存入到session中
request.getSession().setAttribute("checkcode", sb.toString());
System.out.println(sb.toString());
// 步骤五 绘制干扰线
graphics.setColor(getRandColor(160, 200));
int x1;
int x2;
int y1;
int y2;
for (int i = 0; i < 30; i++) {
x1 = random.nextInt(width);
x2 = random.nextInt(12);
@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();
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";
}
}
package com.shop.controller;
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
public CategoryService categoryService;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping("/admin/admin_findAll")
public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<User> userList = userService.admin_findAll();
model.addAttribute("userList", userList);
return "admin/user/list";
}
@RequestMapping("/admin/adminCategory_findAll")
public String adminCategory_findAll(Model model, HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
@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";
}
}
}
package com.shop.controller;
@Controller
public class messageController {
@Autowired
private MessageService messageService;
@RequestMapping("/saveMessage")
public String saveMessage(@RequestParam String messageinfo,HttpServletRequest request,Model model) throws Exception {
Message Message = new Message();
User loginUser = (User) request.getSession().getAttribute("loginUser");
if(loginUser==null){
model.addAttribute("message", "对不起您还没有登录");
return "msg";
}
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Message.setMessage(messageinfo);
Message.setUid(loginUser.getUid());
Message.setMessagedate(sdf.format(new Date()));
messageService.insertMessage(Message);
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;
}
}
package com.shop.controller;
}
package com.shop.util;
public class EncodingInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) throws Exception {
response.setContentType("text/html;charset=UTF-8");
/*String method = request.getMethod();
if (method.equalsIgnoreCase("post")) {
request.setCharacterEncoding("utf-8");
} else {
// new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8");
Iterator iter = request.getParameterMap().values().iterator();
while (iter.hasNext()) {
String[] parames = (String[]) iter.next();
for (int i = 0; i < parames.length; i++) {
parames[i] = new String(parames[i].getBytes("iso8859-1"),
"utf-8");// 此处utf-8与页面编码一样
}
}
}*/
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2, ModelAndView arg3) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse arg1, Object arg2, Exception arg3)
public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
orderService.updateOrderStatus(oid, status);
return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
}
//后台留言管理
@RequestMapping("/admin/adminMessage_findAllByPage")
public String adminMessage_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
model.addAttribute("pageBean", pageBean);
return "admin/message/list";
}
@RequestMapping("/admin/adminMessage_delete")
public String adminOrder_updateState(@RequestParam int messageid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
messageService.deleteMessage(messageid);
return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
}
// List<Category> categoryList = categoryService.adminbFindCategory();
// model.addAttribute("categoryList", categoryList);
return "admin/category/add";
}
@RequestMapping("/admin/adminCategory_save")
public String adminCategory_save(@RequestParam String cname,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category addCategory = new Category();
addCategory.setCname(cname);
categoryService.addCategory(addCategory);
return "redirect:/admin/adminCategory_findAll.action";
}
@RequestMapping("/admin/adminCategory_edit")
public String adminCategory_delete(@RequestParam int cid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category existCategory = categoryService.findCategory(cid);
model.addAttribute("existCategory", existCategory);
return "admin/category/edit";
}
@RequestMapping("/admin/adminCategory_update")
public String adminCategory_update(@RequestParam int cid,
@RequestParam String cname,HttpServletRequest request) {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category category = new Category();
category.setCid(cid);
category.setCname(cname);
categoryService.adminCategory_update(category);
@Controller
public class registController {
@Autowired
private UserService userService;
@RequestMapping("regist")
public String regist() {
return "regist";
}
@RequestMapping("/userRegist")
public String userRegist(Model model, HttpServletRequest request,
@Validated User user, BindingResult bindingResult,
@RequestParam String checkImg) throws Exception {
if (bindingResult.hasErrors()) {
List<ObjectError> errors =bindingResult.getAllErrors();
List<String> list = new ArrayList<>();
for (ObjectError objectError : errors) {
String str = new String(objectError.getDefaultMessage()
.getBytes("ISO-8859-1"), "gbk");
list.add(str);
}
model.addAttribute("errors", list);
return "regist";
}
// 查看验证码
String sessionCode = (String) request.getSession().getAttribute(
"checkcode");
// System.out.println("adadadad" + sessionCode);
if (!sessionCode.equalsIgnoreCase(checkImg)) {
// model.addAttribute("message", "验证码错误请重新注册");
throw new zdyException("验证码错误请重新注册");
}
// 开始写入数据库
userService.saveUser(user);
//model.addAttribute("message", "注册成功请去邮箱激活");
model.addAttribute("message", "注册成功请登录");
return "msg";
}
@RequestMapping("/activeUser")
public String activeUser(@RequestParam String code,Model model) throws zdyException,Exception {
/*
* 根据传递激活码进行用户查询. 如果用户不为空: 修改用户状态 改为1 如果用户为空: 激活码被篡改了.
*/
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
public CategoryService categoryService;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping("/admin/admin_findAll")
public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<User> userList = userService.admin_findAll();
model.addAttribute("userList", userList);
return "admin/user/list";
}
@RequestMapping("/admin/adminCategory_findAll")
public String adminCategory_findAll(Model model, HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<Category> categoryList = categoryService.adminbFindCategory();
/*for (Category category : categoryList) {
System.out.println(category.getCname());
}*/
}
package com.shop.util;
@Controller
public class PrivilageInterceptor implements HandlerInterceptor{
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object object) throws Exception {
String uri = request.getRequestURI();
if(uri.indexOf("admin.action")>=0){
return true;
}
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin!=null){
return true ;
}
request.getRequestDispatcher("/WEB-INF/jsp/admin/index.jsp").forward(request, response);
return true;
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
}
package com.shop.util;
public class golbalException implements HandlerExceptionResolver {
response.setContentType("text/html;charset=UTF-8");
/*String method = request.getMethod();
if (method.equalsIgnoreCase("post")) {
request.setCharacterEncoding("utf-8");
} else {
// new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8");
Iterator iter = request.getParameterMap().values().iterator();
while (iter.hasNext()) {
String[] parames = (String[]) iter.next();
for (int i = 0; i < parames.length; i++) {
parames[i] = new String(parames[i].getBytes("iso8859-1"),
"utf-8");// 此处utf-8与页面编码一样
}
}
}*/
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2, ModelAndView arg3) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
}
package com.shop.util;
@Controller
public class PrivilageInterceptor implements HandlerInterceptor{
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object object) throws Exception {
}
// 清空购物车
@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;
}
}
package com.shop.controller;
@Controller
public class messageController {
@Autowired
private MessageService messageService;
@RequestMapping("/saveMessage")
public String saveMessage(@RequestParam String messageinfo,HttpServletRequest request,Model model) throws Exception {
Message Message = new Message();
User loginUser = (User) request.getSession().getAttribute("loginUser");
package com.shop.controller;
@Controller
public class ajaxController {
@Autowired
private UserService userService;
@RequestMapping("/loginFindByid")
public void loginFindByid(HttpServletRequest request,
HttpServletResponse response, @RequestParam String username) {
response.setContentType("text/html;charset=UTF-8");
try {
User user = userService.loginFindByid(username);
if (user!=null) {
response.getWriter().write("可以登录");
}else{
response.getWriter().write("不可以登录");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping("/registFindByid")
public void registFindByid(HttpServletRequest request,
HttpServletResponse response, @RequestParam String username) {
response.setContentType("text/html;charset=UTF-8");
try {
model.addAttribute("sList", hList);
}
return "index";
}
@RequestMapping("/about")
public String about(Model model,HttpServletRequest request) throws Exception {
return "about";
}
@RequestMapping("/contact")
public String contact(Model model,HttpServletRequest request) throws Exception {
return "contact";
}
@RequestMapping("/delivery")
public String delivery(Model model,HttpServletRequest request) throws Exception {
return "delivery";
}
//
@RequestMapping("/searchProduct")
public String searchProduct(@RequestParam String condition,Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
//查询商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//搜索商品
List<Product> srList = productService.searchProduct(condition);
model.addAttribute("srList", srList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
Categorysecond categorysecond = new Categorysecond();
categorysecond.setCsname(csname);
categorysecond.setCsid(csid);
categorySecondService.adminCategorySecond_update(categorysecond);
return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
}
@RequestMapping("admin/adminCategorySecond_delete")
public String adminCategorySecond_delete(@RequestParam int csid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
categorySecondService.adminCategorySecond_delete(csid);
return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
}
//admin的商品管理
@RequestMapping("/admin/adminProduct_findAllByPage")
public String adminProduct_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Product> allProPageBean = productService.findAllProduct(page);
model.addAttribute("allProPageBean", allProPageBean);
return "admin/product/list";
}
@RequestMapping("/admin/adminProduct_addPage")
public String adminProduct_addPage(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
//查询出所有的二级分类
List<Categorysecond> cslist = categorySecondService.findAll();
/*for (Categorysecond categorysecond : cslist) {
System.out.println(categorysecond.getCsname());
}*/
@RequestMapping("/searchProduct")
public String searchProduct(@RequestParam String condition,Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
//查询商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//搜索商品
List<Product> srList = productService.searchProduct(condition);
model.addAttribute("srList", srList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}
return "searchProduct";
}
}
package com.shop.controller;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping("/admin/admin_findAll")
public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<User> userList = userService.admin_findAll();
model.addAttribute("userList", userList);
return "admin/user/list";
}
@RequestMapping("/admin/adminCategory_findAll")
public String adminCategory_findAll(Model model, HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<Category> categoryList = categoryService.adminbFindCategory();
/*for (Category category : categoryList) {
System.out.println(category.getCname());
}*/
model.addAttribute("categoryList", categoryList);
return "admin/category/list";
}
@RequestMapping("/admin/adminCategory_add")
public String adminCategory_add(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
// List<Category> categoryList = categoryService.adminbFindCategory();
// model.addAttribute("categoryList", categoryList);
return "admin/category/add";
// String words
// ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
String words = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a\u5730\u5230\u5927\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7\u51fa\u5c0f\u4e48\u8d77\u4f60\u90fd\u628a\u597d\u8fd8";
Random random = new Random();// 生成随机数
// 定义StringBuffer
StringBuffer sb = new StringBuffer();
// 定义x坐标
int x = 10;
for (int i = 0; i < 4; i++) {
// 随机颜色
graphics2d.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
// 旋转 -30 --- 30度
int jiaodu = random.nextInt(60) - 30;
// 换算弧度
double theta = jiaodu * Math.PI / 180;
// 生成一个随机数字
int index = random.nextInt(words.length()); // 生成随机数 0 到 length - 1
// 获得字母数字
char c = words.charAt(index);
sb.append(c);
// 将c 输出到图片
graphics2d.rotate(theta, x, 20);
graphics2d.drawString(String.valueOf(c), x, 20);
graphics2d.rotate(-theta, x, 20);
x += 30;
}
// 将生成的字母存入到session中
request.getSession().setAttribute("checkcode", sb.toString());
System.out.println(sb.toString());
// 步骤五 绘制干扰线
graphics.setColor(getRandColor(160, 200));
int x1;
int x2;
int y1;
int y2;
for (int i = 0; i < 30; i++) {
x1 = random.nextInt(width);
x2 = random.nextInt(12);
@Controller
public class indexController {
@Autowired
private CategoryService categoryService;
@Autowired
private ProductService productService;
@RequestMapping("/index")
public String index(Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
// model.addAttribute("cList", cList);
//查询热门商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//查询最新商品
List<Product> nList = productService.findNewProduct();
model.addAttribute("nList", nList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}
return "index";
}
@Controller
public class registController {
@Autowired
private UserService userService;
@RequestMapping("regist")
public String regist() {
return "regist";
}
@RequestMapping("/userRegist")
public String userRegist(Model model, HttpServletRequest request,
@Validated User user, BindingResult bindingResult,
@RequestParam String checkImg) throws Exception {
if (bindingResult.hasErrors()) {
List<ObjectError> errors =bindingResult.getAllErrors();
List<String> list = new ArrayList<>();
for (ObjectError objectError : errors) {
String str = new String(objectError.getDefaultMessage()
.getBytes("ISO-8859-1"), "gbk");
list.add(str);
}
model.addAttribute("errors", list);
return "regist";
}
// 查看验证码
String sessionCode = (String) request.getSession().getAttribute(
"checkcode");
// System.out.println("adadadad" + sessionCode);
if (!sessionCode.equalsIgnoreCase(checkImg)) {
// model.addAttribute("message", "验证码错误请重新注册");
throw new zdyException("验证码错误请重新注册");
}
// 开始写入数据库
userService.saveUser(user);
//model.addAttribute("message", "注册成功请去邮箱激活");
model.addAttribute("message", "注册成功请登录");
return "msg";
}
@RequestMapping("/activeUser")
public String activeUser(@RequestParam String code,Model model) throws zdyException,Exception {
/*
* 根据传递激活码进行用户查询. 如果用户不为空: 修改用户状态 改为1 如果用户为空: 激活码被篡改了.
*/
User activeUser = userService.findByCode(code);
if(activeUser==null){
@Controller
public class indexController {
@Autowired
private CategoryService categoryService;
@Autowired
private ProductService productService;
@RequestMapping("/index")
public String index(Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
// model.addAttribute("cList", cList);
//查询热门商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//查询最新商品
List<Product> nList = productService.findNewProduct();
model.addAttribute("nList", nList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}
return "index";
}
@RequestMapping("/about")
public String about(Model model,HttpServletRequest request) throws Exception {
return "about";
}
@RequestMapping("/contact")
public String contact(Model model,HttpServletRequest request) throws Exception {
return "contact";
}
@RequestMapping("/delivery")
userService.activeUser(activeUser);
model.addAttribute("message", "激活码成功");
return "msg";
}
}
package com.shop.controller;
@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";
}
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
public CategoryService categoryService;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping("/admin/admin_findAll")
public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<User> userList = userService.admin_findAll();
model.addAttribute("userList", userList);
return "admin/user/list";
}
model.addAttribute("pageBean", allProPageBean);
return "admin/order/list";
}
//订单详情
//adminOrder_findOrderItem
@RequestMapping("/admin/adminOrder_findOrderItem")
public String adminOrder_findOrderItem(@RequestParam int oid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Orders orderItems = orderService.findOrderByOid(oid);
model.addAttribute("orderItems", orderItems);
return "admin/order/list";
}
//更新订单状态
@RequestMapping("/admin/adminOrder_updateState")
public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
orderService.updateOrderStatus(oid, status);
return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
}
//后台留言管理
@RequestMapping("/admin/adminMessage_findAllByPage")
public String adminMessage_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";