parent
e3918ebff6
commit
176610783b
@ -0,0 +1,208 @@
|
|||||||
|
用户登录模块:
|
||||||
|
package priv.jesse.mall.web.user;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import priv.jesse.mall.entity.User;
|
||||||
|
import priv.jesse.mall.entity.pojo.ResultBean;
|
||||||
|
import priv.jesse.mall.service.UserService;
|
||||||
|
import priv.jesse.mall.service.exception.LoginException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开注册页面
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/toRegister.html")
|
||||||
|
public String toRegister() {
|
||||||
|
return "mall/user/register";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开登录页面
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/toLogin.html")
|
||||||
|
public String toLogin() {
|
||||||
|
return "mall/user/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
*/
|
||||||
|
@RequestMapping("/login.do")
|
||||||
|
public void login(String username,
|
||||||
|
String password,
|
||||||
|
HttpServletRequest request,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
User user = userService.checkLogin(username, password);
|
||||||
|
if (user != null) {
|
||||||
|
//登录成功 重定向到首页
|
||||||
|
request.getSession().setAttribute("user", user);
|
||||||
|
response.sendRedirect("/mall/index.html");
|
||||||
|
} else {
|
||||||
|
throw new LoginException("登录失败! 用户名或者密码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
@RequestMapping("/register.do")
|
||||||
|
public void register(String username,
|
||||||
|
String password,
|
||||||
|
String name,
|
||||||
|
String phone,
|
||||||
|
String email,
|
||||||
|
String addr,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername(username);
|
||||||
|
user.setPhone(phone);
|
||||||
|
user.setPassword(password);
|
||||||
|
user.setName(name);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setAddr(addr);
|
||||||
|
userService.create(user);
|
||||||
|
// 注册完成后重定向到登录页面
|
||||||
|
response.sendRedirect("/mall/user/toLogin.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登出
|
||||||
|
*/
|
||||||
|
@RequestMapping("/logout.do")
|
||||||
|
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
request.getSession().removeAttribute("user");
|
||||||
|
response.sendRedirect("/mall/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证用户名是否唯一
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/checkUsername.do")
|
||||||
|
public ResultBean<Boolean> checkUsername(String username){
|
||||||
|
List<User> users = userService.findByUsername(username);
|
||||||
|
if (users==null||users.isEmpty()){
|
||||||
|
return new ResultBean<>(true);
|
||||||
|
}
|
||||||
|
return new ResultBean<>(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如发生错误 转发到这页面
|
||||||
|
*
|
||||||
|
* @param response
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/error.html")
|
||||||
|
public String error(HttpServletResponse response, HttpServletRequest request) {
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
购物订单模块:
|
||||||
|
package priv.jesse.mall.web.admin;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import priv.jesse.mall.entity.Order;
|
||||||
|
import priv.jesse.mall.entity.OrderItem;
|
||||||
|
import priv.jesse.mall.entity.pojo.ResultBean;
|
||||||
|
import priv.jesse.mall.service.OrderService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/admin/order")
|
||||||
|
public class AdminOrderController {
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开订单列表页面
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/toList.html")
|
||||||
|
public String toList() {
|
||||||
|
return "admin/order/list";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有订单的总数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/getTotal.do")
|
||||||
|
public ResultBean<Integer> getTotal() {
|
||||||
|
Pageable pageable = new PageRequest(1, 15, null);
|
||||||
|
int total = (int) orderService.findAll(pageable).getTotalElements();
|
||||||
|
return new ResultBean<>(total);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有订单
|
||||||
|
* @param pageindex
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/list.do")
|
||||||
|
public ResultBean<List<Order>> listData(int pageindex,
|
||||||
|
@RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
|
||||||
|
Pageable pageable = new PageRequest(pageindex, pageSize, null);
|
||||||
|
List<Order> list = orderService.findAll(pageable).getContent();
|
||||||
|
return new ResultBean<>(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订单项
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/getDetail.do")
|
||||||
|
public ResultBean<List<OrderItem>> getDetail(int orderId) {
|
||||||
|
List<OrderItem> list = orderService.findItems(orderId);
|
||||||
|
return new ResultBean<>(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发货
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/send.do")
|
||||||
|
public ResultBean<Boolean> send(int id) {
|
||||||
|
orderService.updateStatus(id,3);
|
||||||
|
return new ResultBean<>(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue