package controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import pojo.Houselist; import service.HouselistService; import java.util.List; @Controller public class HoustlistController { @Autowired private HouselistService houselistService; /* 租客查找所有的房源列表*/ @RequestMapping("/houselist") public String houselist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "2") Integer pageSize) { PageHelper.startPage(page, pageSize); List<Houselist> houselist = houselistService.selectAll(); PageInfo<Houselist> p = new PageInfo<Houselist>(houselist); model.addAttribute("p", p); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "houselist.jsp"); return "/jsp/zuke/main"; } /* 租客模糊查询房源*/ @RequestMapping("findhouseList") public String findhouseList(Houselist houselist1, Model model, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "2") Integer pageSize) { PageHelper.startPage(page, pageSize); String houselist_address = houselist1.getAddress(); List<Houselist> houselist = houselistService.selectByaddress(houselist_address); PageInfo<Houselist> p = new PageInfo<>(houselist); model.addAttribute("p", p); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "houselist.jsp"); return "/jsp/zuke/main"; } /* 管理员查看所有房源列表*/ @RequestMapping("/ahouselist") public String ahouselist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "13") Integer pageSize) { /* 分页插件*/ PageHelper.startPage(page, pageSize); List<Houselist> houselist = houselistService.selectAll(); PageInfo<Houselist> p = new PageInfo<>(houselist); model.addAttribute("p", p); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "ahouselist.jsp"); return "/jsp/admin/main1"; } /* 添加房源*/ @RequestMapping("/addhouse") public String addhouse(Model model, Houselist houselist) { String houseid = houselist.getHouseid(); Houselist houselist1 = houselistService.findhouseid(houseid); if (houselist1 != null) { model.addAttribute("error", "该房屋id已存在"); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "addhouse.jsp"); return "/jsp/admin/main1"; } else { model.addAttribute("error", "添加成功"); houselistService.inserthouse(houselist); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "addhouse.jsp"); return "/jsp/admin/main1"; } } @RequestMapping("/toaddhouse") public String toaddhoust(Model model) { model.addAttribute("mainPage", "addhouse.jsp"); return "/jsp/admin/main1"; } @RequestMapping("/deletehouse") public String deletehouse(Integer id) { houselistService.deletehouse(id); return "redirect:ahouselist.action"; } @RequestMapping("/toahouselist") public String toahouselist() { return "redirect:ahouselist.action"; } @RequestMapping("/findid") public String findid(Integer id, Model model) { Houselist list = houselistService.findid(id); model.addAttribute("houselist", list); model.addAttribute("mainPage", "changehouse.jsp"); return "/jsp/admin/main1"; } @RequestMapping("/findhouseidupdate") public String findhouseidupdate(Houselist houselist, Model model) { Houselist list = houselistService.findhouseidupdate(houselist); if (list != null) { model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "changehouse.jsp"); model.addAttribute("error", "该房屋id已存在"); } else { houselistService.updatehouse(houselist); model.addAttribute("houselist", houselist); model.addAttribute("mainPage", "changehouse.jsp"); model.addAttribute("error", "更新成功"); } return "/jsp/admin/main1"; } }
最近下载更多