packagecom.dengfeng.house.controller;importjava.text.ParseException;importjava.util.Date;importjava.util.List;importjavax.annotation.Resource;importjavax.servlet.http.HttpSession;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.ResponseBody;importcom.github.pagehelper.PageHelper;importcom.github.pagehelper.PageInfo;importcom.dengfeng.house.pojo.District;importcom.dengfeng.house.pojo.House;importcom.dengfeng.house.pojo.HouseQuery;importcom.dengfeng.house.pojo.Street;importcom.dengfeng.house.pojo.Type;importcom.dengfeng.house.pojo.User;importcom.dengfeng.house.service.IDistrictService;importcom.dengfeng.house.service.IHouseService;importcom.dengfeng.house.service.IStreetService;importcom.dengfeng.house.service.ITypeService;
@Controller
@RequestMapping("/house")public classHouseController {
@ResourceprivateIHouseService houseService;
@ResourceprivateITypeService typeService;
@ResourceprivateIDistrictService districtService;
@ResourceprivateIStreetService streetService;//manage页面全查
@RequestMapping("/findAll")
@ResponseBodypublic PageInfo findAll(@RequestParam(defaultValue="1")intpageIndex){
PageHelper.startPage(pageIndex,3);
List housList =houseService.selectHouse();
PageInfo pageInfo=new PageInfo(housList);returnpageInfo;
}//修改渲染
@RequestMapping("/update/{id}")public String update(Model model,@PathVariable intid){
List typeList =typeService.findAllType();
List districtList =districtService.findAllDistrict();
List streetList=streetService.findAllStreet();
House house=houseService.findHouseById(id);
model.addAttribute("house", house);
model.addAttribute("typeList", typeList);
model.addAttribute("districtList", districtList);
model.addAttribute("streetList", streetList);return "/page/update";
}//保存修改
@RequestMapping("/updateSave")publicString update(House house){
houseService.alterHouse(house);return "redirect:/page/manage.jsp";
}//渲染增加,下拉框推荐用ajxj做,,=所有这个方法没什么用
@RequestMapping("/add")publicString add(Model model){
List typeList =typeService.findAllType();/*List districtList = districtService.findAllDistrict();
List streetList= streetService.findAllStreet();*/model.addAttribute("typeList", typeList);/*model.addAttribute("districtList", districtList);
model.addAttribute("streetList", streetList);*/
return "/page/add";
}//真正保存增加的方法
@RequestMapping("/addSave")publicString addSave(House house,HttpSession session){
houseService.insertHouse(house);return "redirect:/page/manage.jsp";
}/*house_list.jsp查询。*/@RequestMapping("/find")
@ResponseBodypublic Listfind(HouseQuery houseQuery,String money,String size){//如果是选中状态
if(money!=null&&!money.equals("")){
String[] moneyArray=money.split("-");
houseQuery.setMinPrice(Integer.parseInt(moneyArray[0]));
houseQuery.setMaxPrice(Integer.parseInt(moneyArray[1]));
}if(size!=null&&!size.equals("")){
String[] sizeArray=size.split("-");
houseQuery.setMinFloorAge(Integer.parseInt(sizeArray[0]));
houseQuery.setMaxFloorAge(Integer.parseInt(sizeArray[1]));
}
List list =houseService.find(houseQuery);returnlist;
}//推荐,多条件模糊查询/*@RequestMapping("/findAllHouseList")
@ResponseBody
public PageInfo findAll(HttpSession session,@RequestParam(defaultValue="1")Integer pageIndex,
@RequestParam(defaultValue="")String title,
@RequestParam(defaultValue="")String price,
@RequestParam(defaultValue="")Integer typeId,
@RequestParam(defaultValue="0")String floorage,Date beginTime,Date endTime) throws ParseException{
User user=(User)session.getAttribute("userSession");
String[] prices = price.split("-");
String[] floorages = floorage.split("-");
if(user!=null) {
PageHelper.startPage(pageIndex,2);
House house =new House ();
house.setTitle(title);
house.setMinPrice(Integer.parseInt(prices[0]));
house.setMaxPrice(Integer.parseInt(prices[1]));
house.setTypeId(typeId);
house.setMinFloorage(Integer.parseInt(floorages[0]));
house.setMaxFloorage(Integer.parseInt(floorages[1]));
if(beginTime!=null && endTime!=null){
house.setBeginTime(beginTime);
house.setEndTime(endTime);
}else if(beginTime!=null){
house.setBeginTime(beginTime);
}else if(endTime!=null){
house.setEndTime(endTime);
}
List list = houseService.findByCondition(house);
PageInfo pageInfo=new PageInfo(list);
return pageInfo;
}
return new PageInfo();
}*/
//删除房子
@RequestMapping("/deleteById")
@ResponseBodypublic String delete(intid){
houseService.deletehouse(id);return "删除成功";
}
}