脚本宝典收集整理的这篇文章主要介绍了Java项目:酒店预定管理系统(java+JDBC+jsp+servlet+Mysql),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
/**
* @Author: yy
* @Description: TODO(酒店信息)
*/
@Controller
@RequestMapping("/hotels")
public class HotelController {
@Autowired
private IHotelService hotelService;
@Autowired
private IUserService iUserService;
//根据hid查看已拥有的房型
@RequestMapping("/findRooms.do")
public ModelAndView findRooms(Integer hid)throws Exception{
ModelAndView mv = new ModelAndView();
List<Hoteldetail> list = hotelService.findDetail(hid);
mv.addObject("room",list);
mv.setViewName("hotel-room-remove");
return mv;
}
//移除已拥有的房型
@RequestMapping("/removeRoom.do")
public String removeRoom(@RequestParam(name = "hid") Integer hid, @RequestParam(name = "ids") int[] ids)throws Exception{
hotelService.removeRoom(hid,ids);
return "redirect:findAll.do";
}
//根据hid查看未拥有的房型
@RequestMapping("/findOtherRooms.do")
public ModelAndView findOtherRooms(Integer hid)throws Exception{
ModelAndView mv = new ModelAndView();
Hotel hotel = hotelService.findByHid(hid);
mv.addObject("hotel",hotel);
List<Hoteltype> list = hotelService.findOtherRooms(hid);
mv.addObject("room",list);
mv.setViewName("hotel-room-add");
return mv;
}
//添加未拥有的房型
@RequestMapping("/addRoom.do")
public String addRoom(@RequestParam(name = "hid") Integer hid, @RequestParam(name = "ids") int[] ids,@RequestParam(name = "prices")String[] prices)throws Exception{
List list = new ArrayList();
for (int i=0;i<prices.length;i++) {
if (prices[i]!=""){
list.add(Double.valueOf(prices[i]));
}
}
if (ids.length==list.size()){
hotelService.addRoom(hid,ids,list);
}
return "redirect:findAll.do";
}
//查看酒店房型详情
@RequestMapping("/findByUid.do")
public ModelAndView findByUid(Integer hid)throws Exception{
ModelAndView mv = new ModelAndView();
Hotel hotel = hotelService.findByHid(hid);
mv.addObject("hotel",hotel);
List<Hoteldetail> hoteldetail = hotelService.findDetail(hid);
mv.addObject("details",hoteldetail);
mv.setViewName("hotel-detail");
return mv;
}
//新增酒店
@RequestMapping("/findUsers.do")
public ModelAndView findUsers() throws Exception{
List<User> list = hotelService.findUsers();
ModelAndView mv = new ModelAndView();
mv.addObject("users",list);
mv.setViewName("hotel-add");
return mv;
}
@RequestMapping("/save.do")
public String save(Hotel hotel) throws Exception{
if (hotel.getHimageFile()!=null){
String filename = Upload.uploadImg(HIMAGE,hotel.getHimageFile());
hotel.setHimage("img/hotel/"+filename);
hotelService.save(hotel);
}
return "redirect:findAll.do";
}
//删除酒店
@RequestMapping("/delete.do")
public String delete(Integer hid) throws Exception {
hotelService.delete(hid);
return "redirect:findAll.do";
}
//修改酒店信息
@RequestMapping("/findU.do")
public ModelAndView findU(Integer hid) throws Exception{
ModelAndView mv = new ModelAndView();
Hotel hotel = hotelService.findByHid(hid);
mv.addObject("hotel",hotel);
List<User> list = iUserService.findAll(1,100,"%%");
mv.addObject("UList",list);
mv.setViewName("hotel-update");
return mv;
}
@RequestMapping("/update.do")
public String update(Hotel hotel) throws Exception{
if (hotel.getHimageFile().getSize()!=0&&hotel.getHimageFile()!=null){//修改过图片
String filename = Upload.uploadImg(HIMAGE,hotel.getHimageFile());
hotel.setHimage("img/hotel/"+filename);
hotelService.update(hotel);
}else{//未修改图片
hotelService.update(hotel);
}
return "redirect:findAll.do";
}
//查询所有订单
@RequestMapping("/findAll.do")
public ModelAndView findAll(
@RequestParam(name = "page",defaultValue = "1")Integer page,
@RequestParam(name = "size",defaultValue = "10")Integer size,
@RequestParam(name = "search",defaultValue = "")String search
) throws Exception{
ModelAndView mv = new ModelAndView();
List<Hotel> list = hotelService.findAll(page,size,"%"+search+"%");
PageInfo pageInfo = new PageInfo(list);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("hotel-list");
return mv;
}
}
/**
* @Author: yy
* @Description: TODO(房型管理)
*/
@Controller
@RequestMapping("/rooms")
public class RoomController {
@Autowired
private IHoteltypeService hoteltypeService;
//新增房型
@RequestMapping("/save.do")
@PreAuthorize("hasAnyAuthority('/rooms/save.do')")
public String save(Hoteltype hoteltype) throws Exception{
hoteltypeService.save(hoteltype);
return "redirect:findAll.do";
}
//删除分类
@RequestMapping("/delete.do")
@PreAuthorize("hasAnyAuthority('/rooms/delete.do')")
public String delete(Integer tid) throws Exception{
hoteltypeService.delete(tid);
return "redirect:findAll.do";
}
//查询所有房型
@RequestMapping("/findAll.do")
@PreAuthorize("hasAnyAuthority('/rooms/findAll.do')")
public ModelAndView findAll(
@RequestParam(name = "page",defaultValue = "1") Integer page,
@RequestParam(name = "size",defaultValue = "10") Integer size,
@RequestParam(name = "search",defaultValue = "") String search
) throws Exception{
ModelAndView mv = new ModelAndView();
List<Hoteltype> list = hoteltypeService.findAll(page,size,"%"+search+"%");
PageInfo pageInfo = new PageInfo(list);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("room-list");
return mv;
}
}
/**
* @Author: yy
* @Description: TODO(用户操作)
*/
@Controller
@RequestMapping("/users")
public class UserController {
@Autowired
private IUserService userService;
//给用户添加角色
@RequestMapping("/addRoleToUser.do")
@PreAuthorize("hasAnyAuthority('/users/addRoleToUser.do')")
public String addRoleToUser(@RequestParam(name = "userId", required = true) Integer userId, @RequestParam(name = "ids", required = true) int[] roleIds) throws Exception {
userService.addRoleToUser(userId, roleIds);
return "redirect:findAll.do";
}
//查询用户以及用户可以添加的角色
@RequestMapping("/findUserByIdAndAllRole.do")
@PreAuthorize("hasAnyAuthority('/users/findUserByIdAndAllRole.do')")
public ModelAndView findUserByIdAndAllRole(@RequestParam(name = "id", required = true) Integer uid) throws Exception {
ModelAndView mv = new ModelAndView();
//1.根据用户id查询用户
User user = userService.findByUid(uid);
//2.根据用户id查询可以添加的角色
List<Role> otherRoles = userService.findOtherRoles(uid);
mv.addObject("user", user);
mv.addObject("roleList", otherRoles);
mv.setViewName("user-role-add");
return mv;
}
//查询用户拥有的角色
@RequestMapping("/findRoleByUserId.do")
@PreAuthorize("hasAnyAuthority('/users/findRoleByUserId.do')")
public ModelAndView findRoleByUserId(Integer userId) throws Exception{
ModelAndView mv = new ModelAndView();
User user = userService.findByUid(userId);
List<Role> roleList = userService.findRoleByUserId(userId);
mv.addObject("user", user);
mv.addObject("roleList", roleList);
mv.setViewName("user-role-rmove");
return mv;
}
//移除用户指定的角色
@RequestMapping("/removeRole.do")
@PreAuthorize("hasAnyAuthority('/users/removeRole.do')")
public String removeRole( @RequestParam(name = "userId") Integer userId, @RequestParam(name = "ids") int[] roleIds) throws Exception{
userService.removeRole(userId,roleIds);
return "redirect:findAll.do";
}
//添加用户
@RequestMapping("/save.do")
@PreAuthorize("hasAnyAuthority('/users/save.do')")
public String save(User user) throws Exception {
userService.save(user);
return "redirect:findAll.do";
}
//删除用户,设置status=0
@RequestMapping("/delete.do")
@PreAuthorize("hasAnyAuthority('/users/delete.do')")
public String delete(Integer uid) throws Exception{
userService.delete(uid);
return "redirect:findAll.do";
}
//修改用户
@RequestMapping("/findU.do")
@PreAuthorize("hasAnyAuthority('/users/findU.do')")
public ModelAndView findU(Integer uid) throws Exception {
ModelAndView mv = new ModelAndView();
User user = userService.findByUid(uid);
mv.addObject("user",user);
mv.setViewName("user-update");
return mv;
}
@RequestMapping("/update.do")
@PreAuthorize("hasAnyAuthority('/users/update.do')")
public String update(User user) throws Exception{
userService.update(user);
return "redirect:findAll.do";
}
//根据uid查询用户
@RequestMapping("/findByUid.do")
@PreAuthorize("hasAnyAuthority('/users/findByUid.do')")
public ModelAndView findByUid(Integer uid) throws Exception {
ModelAndView mv = new ModelAndView();
User user = userService.findByUid(uid);
mv.addObject("user", user);
mv.setViewName("user-details");
return mv;
}
//查询用户相关信息
@RequestMapping("/findAll.do")
@PreAuthorize("hasAnyAuthority('/users/findAll.do')")
public ModelAndView findAll(
@RequestParam(name="page",required = true, defaultValue = "1") Integer page,
@RequestParam(name="size",required = true, defaultValue = "6") Integer size,
@RequestParam(name="username",required = true, defaultValue = "") String username
) throws Exception{
ModelAndView mv = new ModelAndView();
List<User> userList = userService.findAll(page,size,"%"+username+"%");
PageInfo pageInfo = new PageInfo(userList);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("user-list");
return mv;
}
}
以上是脚本宝典为你收集整理的Java项目:酒店预定管理系统(java+JDBC+jsp+servlet+Mysql)全部内容,希望文章能够帮你解决Java项目:酒店预定管理系统(java+JDBC+jsp+servlet+Mysql)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。