首页>代码>基于ssm的房屋租赁系统>/house/src/main/java/controller/HoustlistController.java
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";
    }
}
最近下载更多
胡棋俊  LV4 11月17日
lisansiwu  LV2 11月8日
罗清晨  LV13 11月1日
bridge_44  LV2 10月28日
yayacui  LV2 10月28日
yfb790910  LV3 9月22日
Peny_ZH  LV5 9月19日
zolscy  LV12 9月11日
lyws1986  LV17 7月14日
799743530  LV11 7月7日
最近浏览更多
驱蚊器我 11月18日
暂无贡献等级
citybird  LV4 11月17日
学熊涅槃  LV2 11月15日
oceanchen  LV14 11月13日
lisansiwu  LV2 11月8日
罗清晨  LV13 11月1日
林kkkkkk  LV6 10月31日
416696772 10月31日
暂无贡献等级
bridge_44  LV2 10月28日
shunlun8855  LV1 10月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友