package com.serve.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.serve.entity.Album;
import com.serve.entity.Consignee;
import com.serve.entity.OrderViewModel;
import com.serve.entity.Orderdetail;
import com.serve.entity.Orders;
import com.serve.entity.User;
import com.serve.service.AlbumService;
import com.serve.service.ConsigneeService;
import com.serve.service.OrderDetailService;
import com.serve.service.OrderService;
import com.serve.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private ConsigneeService consigneeService;
@Autowired
private OrderService ors;
@Autowired
private OrderDetailService orderdetailService;
@Autowired
private AlbumService albumService;
@RequestMapping("/login")
public String userlogin(){
return "user-login";
}
@RequestMapping("/dologin")
public String dologin(String username,String password,HttpSession s){
User user = userService.getUserByUsername(username);
if(user != null&&password.equals(user.getPassword())){
s.setAttribute("name", user.getUsername());
s.setAttribute("userid", user.getId());
return "redirect:/album/getalbumlist";
}
return "redirect:/user/login";
}
@RequestMapping("/register")
public String userregister(){
return "user-register";
}
@RequestMapping("/doregister")
public String doUserLogin(User user,HttpSession s){
if(user!=null && userService.addUser(user)){
//从新获取user对象,id字段才有值
user = userService.getUserByUsername(user.getUsername());
s.setAttribute("name", user.getUsername());
s.setAttribute("userid", user.getId());
Orders newOrder = new Orders();
java.util.Date date = new java.util.Date();
java.sql.Date d = new java.sql.Date(date.getTime());
newOrder.setUser(user);
newOrder.setIsDeliveried(0);
newOrder.setIsPay(0);
newOrder.setPayMethod(0);
newOrder.setTotalpayment(0.0);
newOrder.setTotalquantity(0.0);
newOrder.setOrderDate(d);
ors.addOrder(newOrder);
return "redirect:/album/getalbumlist";
}
return "user-register";
}
@RequestMapping("/dologout ")
public String dologout(HttpSession s){
s.removeAttribute("name");
return "redirect:/album/getalbumlist";
}
@RequestMapping("/getAllUser")
public String getAllUser(HttpServletRequest request){
request.setAttribute("userList", userService.getAllUser());
return "/index";
}
@RequestMapping("/getUser")
public String getUser(int id,HttpServletRequest request){
request.setAttribute("user", userService.getUserById(id));
return "/editUser";
}
@RequestMapping("/toAddUser")
public String toAddUser(){
return "/addUser";
}
@RequestMapping("/addUser")
public String addUser(User user,HttpServletRequest request){
userService.addUser(user);
return "redirect:/user/getAllUser";
}
@RequestMapping("/delUser")
public void delUser(String id,HttpServletResponse response){
String result = "{\"result\":\"error\"}";
if(userService.delUser(id)){
result = "{\"result\":\"success\"}";
}
response.setContentType("application/json");
try {
PrintWriter out = response.getWriter();
out.write(result);
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/updateUser")
public String updateUser(User user,HttpServletRequest request){
if(userService.updateUser(user)){
user = userService.getUserById(user.getId());
request.setAttribute("user", user);
return "redirect:/user/getAllUser";
}else{
return "/error";
}
}
@RequestMapping("/getuserdesc/{id}")
public String getUserDesc(@PathVariable int id,HttpServletRequest req){
//获取用户
User user = userService.getUserById(id);
//获取用户地址列表
List<Consignee> consignee = consigneeService.getConsigneeByUsername(user.getUsername());
//获取用户订单列表
List<Orders> orders = new ArrayList<Orders>(user.getOrder());
//set转成list后是乱序,通过Collections.sort定义排序规则排序
Collections.sort(orders,new Comparator<Orders>(){
public int compare(Orders arg0, Orders arg1) {
return arg0.getId().compareTo(arg1.getId());
}
});
List<Orderdetail> orderlist = new ArrayList<Orderdetail>(orderdetailService.getCurrentOrderById(user.getId()).getOrderdetail());
List<OrderViewModel> viewmodellist = new ArrayList<OrderViewModel>();
double totalPrice = 0;
int totalquantity = 0;
//list的重新包装
for(Orderdetail orde : orderlist){
OrderViewModel viewmodel =new OrderViewModel();
Album al = new Album();
al=albumService.getAlbum(orde.getAlbumId());
totalPrice += orde.getUnitPrice();
totalquantity += orde.getQuantity();
viewmodel.setId(orde.getId());
viewmodel.setAlbumId(orde.getAlbumId());
viewmodel.setUnitPrice(orde.getUnitPrice());
viewmodel.setQuantity(orde.getQuantity());
viewmodel.setAlbumName(al.getTitle());
viewmodel.setArtist(al.getArtist());
viewmodel.setPrice(al.getPrice());
viewmodellist.add(viewmodel);
}
//将list返回给视图
req.setAttribute("viewmodel", viewmodellist);
req.setAttribute("totalPrice", totalPrice);
req.setAttribute("totalquantity", totalquantity);
req.setAttribute("user", user);
req.setAttribute("consigneelist", consignee);
req.setAttribute("userorderlist", orders);
return "user-desc";
}
@RequestMapping("/getconsigneedesc/{id}")
public String getConsigneeDesc( @PathVariable int id,HttpServletRequest req){
/*
* 将orderdetail表和album的信息重新包装成视图模型viewmodellist
*/
Orders order = ors.getOrderById(id);
Consignee consignee = order.getConsignee();
List<Orderdetail> orderlist = new ArrayList<Orderdetail>(order.getOrderdetail());
List<OrderViewModel> viewmodellist = new ArrayList<OrderViewModel>();
//set转成list后是乱序,通过Collections.sort定义排序规则排序
Collections.sort(orderlist,new Comparator<Orderdetail>(){
public int compare(Orderdetail arg0, Orderdetail arg1) {
return arg0.getId().compareTo(arg1.getId());
}
});
//list的重新包装
for(Orderdetail orde : orderlist){
OrderViewModel viewmodel =new OrderViewModel();
Album al = new Album();
al=albumService.getAlbum(orde.getAlbumId());
viewmodel.setId(orde.getId());
viewmodel.setAlbumId(orde.getAlbumId());
viewmodel.setAlbumName(albumService.getAlbum(orde.getAlbumId()).getTitle());
viewmodel.setUnitPrice(orde.getUnitPrice());
viewmodel.setQuantity(orde.getQuantity());
viewmodel.se
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java Web期末课程设计项目。使用了Spring+Spring MVC+Hibernate框架.zip (169个子文件)
.classpath 588B
org.eclipse.wst.common.component 482B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 144KB
bootstrap.min.css 120KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
common.css 3KB
dashboard.css 2KB
glyphicons-halflings-regular.eot 20KB
.gitignore 8B
ehcache-2.10.1.jar 8.5MB
hibernate-core-5.1.0.Final.jar 5.42MB
aspectjweaver-1.5.0.jar 1.67MB
jackson-databind-2.5.0.jar 1.08MB
spring-context-4.2.6.RELEASE.jar 1.05MB
spring-core-4.2.6.RELEASE.jar 1.05MB
spring-webmvc-4.2.6.RELEASE.jar 857KB
mysql-connector-java-5.1.26-bin.jar 836KB
spring-web-4.2.6.RELEASE.jar 749KB
javassist-3.20.0-GA.jar 733KB
spring-beans-4.2.6.RELEASE.jar 714KB
spring-orm-4.2.6.RELEASE.jar 456KB
antlr-2.7.7.jar 435KB
spring-jdbc-4.2.6.RELEASE.jar 414KB
standard.jar 384KB
spring-aop-4.2.6.RELEASE.jar 362KB
org.osgi.core-4.3.1.jar 342KB
dom4j-1.6.1.jar 307KB
spring-tx-4.2.6.RELEASE.jar 259KB
spring-expression-4.2.6.RELEASE.jar 257KB
jackson-core-2.5.0.jar 224KB
jandex-2.0.0.Final.jar 183KB
commons-io-2.4.jar 181KB
spring-context-support-4.2.6.RELEASE.jar 173KB
commons-dbcp.jar 118KB
hibernate-jpa-2.1-api-1.0.0.Final.jar 111KB
servlet-api-6.0.20.jar 86KB
hibernate-commons-annotations-5.0.1.Final.jar 74KB
commons-fileupload-1.3.1.jar 67KB
jboss-logging-3.3.0.Final.jar 65KB
classmate-1.3.0.jar 63KB
commons-logging-1.1.3.jar 61KB
spring-aspects-4.2.6.RELEASE.jar 57KB
commons-pool.jar 41KB
jackson-annotations-2.5.0.jar 39KB
jstl.jar 20KB
geronimo-jta_1.1_spec-1.1.1.jar 16KB
aopalliance-1.0.jar 4KB
UserController.java 9KB
AdminController.java 8KB
OrderController.java 6KB
Orders.java 3KB
AlbumDaoImpl.java 3KB
User.java 3KB
OrderDaoImpl.java 2KB
UserDaoImp.java 2KB
OrderDetailDaoImpl.java 2KB
ConsigneeDaoImpl.java 2KB
Album.java 2KB
Consignee.java 2KB
AlbumController.java 2KB
GenreDaoImpl.java 2KB
OrderViewModel.java 2KB
OrderDetailServiceImple.java 1KB
Orderdetail.java 1KB
ConsigneeServiceImpl.java 1KB
OrderServiceImpl.java 1KB
AlbumServiceImpl.java 1KB
LoginInterceptor.java 1KB
UserServiceImpl.java 1KB
GenreServiceImpl.java 1KB
Genre.java 1KB
UserRole.java 925B
AlbumService.java 680B
OrderDetailService.java 548B
OrderDetailDao.java 538B
AlbumDao.java 494B
ConsigneeService.java 477B
ConsigneeDao.java 469B
OrderService.java 464B
OrderDao.java 456B
UserService.java 437B
UserDao.java 364B
GenreService.java 350B
GenreDao.java 340B
1.jpg 22KB
17.jpg 19KB
22.jpg 17KB
27.jpg 17KB
12.jpg 17KB
9.jpg 16KB
24.jpg 16KB
14.jpg 16KB
15.jpg 15KB
11.jpg 15KB
26.jpg 15KB
8.jpg 15KB
5.jpg 15KB
7.jpg 15KB
共 169 条
- 1
- 2
资源评论
生瓜蛋子
- 粉丝: 3924
- 资源: 7441
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Annotations_Train_abstract_v002.zip
- ap5030dn-openwrt-ath79-generic-huawei-ap5030dn-initramfs-kernel
- 华为AP无线接入控制器学习资料
- 金铲铲S13双城之战自动拿牌助手2.0
- Sigrity Power SI 仿真分析教程与实例分析.rar
- 基于Vue和JavaScript的掌上生活超市小程序配送解决方案设计源码
- 基于Java和安卓基础知识的简易记事本设计源码
- 基于SaToken轻量级Java权限认证的XrSaTokenVue Vue设计源码
- 基于Java语言的RxTool设计源码集合
- PHP性能检测扩展XHProf与FirePHP线上调试工具详解
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功