易居3

HouseViewController 中代码

@Controller
@RequestMapping("house")
public class HouseViewController {

    @Autowired
    private IHouseViewService houseViewService;

    @RequestMapping("findFourHouse.do")
    public ModelAndView findFourHouse(){
        ModelAndView mv=new ModelAndView();
        List<HouseView> newHouses = houseViewService.findFourHouseByType(0);
        List<HouseView> oldHouse = houseViewService.findFourHouseByType(1);
        List<HouseView> rentHouses =houseViewService.findFourHouseByType(2);
        mv.addObject("newHouses",newHouses);
        mv.addObject("oldHouse",oldHouse);
        mv.addObject("rentHouses",rentHouses);
        mv.setViewName("../main");
        return mv;
    }

    @RequestMapping("findHouseById.do")
    public ModelAndView findHouseById(int houseId){
        HouseView house = houseViewService.findHouseByHouseId(houseId);
        ModelAndView mv=new ModelAndView();
        mv.addObject("houseInfo",house);
        mv.setViewName("details");
        return mv;
    }

    @RequestMapping("findHouse.do")
    public ModelAndView findHouse(@RequestParam(defaultValue = "1") int currentPage, int houseType){
        ModelAndView mv=new ModelAndView();
        List<HouseView> houses = houseViewService.findHouseByType(currentPage,houseType);
        List<HouseView> fh = houseViewService.findFourHouseByType(houseType);
        PageInfo<HouseView> pageInfo=new PageInfo<>(houses);
        mv.addObject("pageInfo",pageInfo);
        mv.addObject("fh",fh);
        if(houseType==0){
            mv.setViewName("newhouse");
        }else if(houseType==1){
            mv.setViewName("oldhouse");
        }else {
            mv.setViewName("renthouse");
        }
        return mv;
    }
    @RequestMapping("toHousePost2.do")
    public ModelAndView toHousePost2(@Param(value = "houseTitle") String houseTitle,
                                     @Param(value = "houseAddress") String houseAddress,
                                     @Param(value = "housePrice") BigDecimal housePrice,
                                     @Param(value = "priceUnit") String priceUnit,
                                     @Param(value = "houseHeadimg") MultipartFile houseHeadimg,
                                     @Param(value = "housePlanimg1") MultipartFile housePlanimg1,
                                     @Param(value = "housePlanimg2") MultipartFile housePlanimg2,
                                     @Param(value = "houseImg1") MultipartFile houseImg1,
                                     @Param(value = "houseImg2") MultipartFile houseImg2,
                                     @Param(value = "houseImg3") MultipartFile houseImg3,
                                     @Param(value = "houseImg4") MultipartFile houseImg4,
                                     @Param(value = "houseImg5") MultipartFile houseImg5,
                                     @Param(value = "houseImg6") MultipartFile houseImg6,
                                     HttpSession session
    ) throws IOException {
        House house=new House();
        house.setHouseTitle(houseTitle);
        house.setHouseAddress(houseAddress);
        house.setHousePrice(housePrice);
        house.setPriceUnit(priceUnit);
//        house.setUserId(10005);

        Map<String, byte[]> images=new HashMap<>();

        if (houseHeadimg.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseHeadimg.getBytes());
        }

        if (housePlanimg1.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,housePlanimg1.getBytes());
        }

        if (housePlanimg2.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,housePlanimg2.getBytes());
        }

        if (houseImg1.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg1.getBytes());
        }
        if (houseImg2.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg2.getBytes());
        }
        if (houseImg3.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg3.getBytes());
        }
        if (houseImg4.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg4.getBytes());
        }
        if (houseImg5.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg5.getBytes());
        }
        if (houseImg6.getSize()!=0){
            String picName = YijuUtil.getPicName();
            house.setHouseHeadimg(picName);
            images.put(picName,houseImg6.getBytes());
        }
//        Set<String> keys = images.keySet();
//        for(String key:keys){
//            MultipartFile file = images.get(key);
//            YijuUtil.upload(file.getBytes(),key);
//        }
//        houseViewService.postHouse(house);
        session.setAttribute("house",house);
        session.setAttribute("images",images);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("housePost2");
        return mv;
    }
    @RequestMapping("responsePost2.do")
    @ResponseBody
    public String responsePost2(HouseInfo houseInfo,HttpSession session){
//        houseInfo.setHouseId(10001);
//        houseViewService.postHouseInfo(houseInfo);
        session.setAttribute("houseInfo",houseInfo);
        return new JSONObject().toString();
    }

    @RequestMapping("responsePost3.do")
    @ResponseBody
    public String responsePost3(HouseInter houseInter,HttpSession session){
//        houseInter.setHouseId(10013);
//        houseViewService.postHouseInter(houseInter);
        session.setAttribute("houseInter",houseInter);
        return new JSONObject().toString();
    }

    @RequestMapping("doHousePost.do")
    @Transactional
    public String doHousePost(HttpSession session) throws IOException {
        House house =(House) session.getAttribute("house");
        house.setUserId(10001);
        Map<String,byte[]> images=( Map<String,byte[]> ) session.getAttribute("images");
        HouseInfo houseInfo=(HouseInfo) session.getAttribute("houseInfo");
        HouseInter houseInter=(HouseInter) session.getAttribute("houseInter");
        houseViewService.postHouse(house);
        Set<String> keys=images.keySet();
        for(String key:keys){
            byte[] bytes=images.get(key);
            YijuUtil.upload(bytes,key);
        }
        houseInfo.setHouseId(house.getHouseId());
        houseViewService.postHouseInfo(houseInfo);
        houseInter.setHouseId(house.getHouseId());
        houseViewService.postHouseInter(houseInter);
        return "redirect:findHouseById.do?houseId="+house.getHouseId();
    }

}

HouseViewDao中添加这句代码

void postHouseInter(HouseInter houseInter);

IHouseViewService中添加这句代码

void postHouseInter(HouseInter houseInter);

HouseViewService中实现这个方法

@Override
    public void postHouseInter(HouseInter houseInter) {
        houseViewDao.postHouseInter(houseInter);
    }

HouseMapper.xml中代码修改添加为

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yiju.dao.IHouseViewDao">

   <select id="findFourHouseByType" parameterType="int" resultType="com.yiju.pojo.HouseView">
      SELECT * FROM tb_house a,tb_house_info b WHERE a.house_id=b.house_id AND a.is_delete=0
      AND a.house_type=#{houseType} order by rand() limit 4;
   </select>
   <select id="findHouseByHouseId" parameterType="int" resultType="com.yiju.pojo.HouseView">
      SELECT * FROM tb_house a,tb_house_info b WHERE a.house_id=b.house_id AND a.is_delete=0
      AND a.house_id=#{houseId}
   </select>
   <select id="findHouseByType" parameterType="int" resultType="com.yiju.pojo.HouseView" >
      SELECT * FROM tb_house a,tb_house_info b WHERE a.house_id=b.house_id AND a.is_delete=0
      AND a.house_type=#{houseType}
   </select>
    <insert id="postHouse" parameterType="com.yiju.bean.House" useGeneratedKeys="true" keyProperty="houseId">
        insert into tb_house(user_id, house_type, house_title, house_headimg, house_planimg1, house_planimg2, house_img1, house_img2, house_img3, house_img4, house_img5, house_img6, house_price, price_unit, house_address, is_delete, create_time, update_time)
        values ("10005", #{houseType}, #{houseTitle}, #{houseHeadimg}, #{housePlanimg1}, #{housePlanimg2}, #{houseImg1}, #{houseImg2}, #{houseImg3}, #{houseImg4}, #{houseImg5}, #{houseImg6}, #{housePrice}, #{priceUnit}, #{houseAddress}, #{isDelete}, #{createTime}, #{updateTime})
    </insert>
    <insert id="postHouseInfo" parameterType="com.yiju.bean.HouseInfo" useGeneratedKeys="true" keyProperty="infoId">
        insert into tb_house_info(house_id, house_nature, house_model, house_year, house_valid, house_layout, house_area, house_turn, house_floor, floor_all, house_decorate, house_lift, create_time, update_time)
        values (#{houseId}, #{houseNature}, #{houseModel}, #{houseYear}, #{houseValid}, #{houseLayout}, #{houseArea}, #{houseTurn}, #{houseFloor}, #{floorAll}, #{houseDecorate}, #{houseLift}, #{createTime}, #{updateTime})
    </insert>
    <insert id="postHouseInter" parameterType="com.yiju.bean.HouseInter" useGeneratedKeys="true" keyProperty="interId">
         insert into tb_house_inter(house_id, bed, washing, air, balcony, ice, toilet, kitchen, tv, heater, wardrobe, heating, internet, sofa, create_time, update_time)
        values (#{houseId}, #{bed}, #{washing}, #{air}, #{balcony}, #{ice}, #{toilet}, #{kitchen}, #{tv}, #{heater}, #{wardrobe}, #{heating}, #{internet}, #{sofa}, #{createTime}, #{updateTime})
    </insert>

</mapper>

housePost3.xml中代码修改添加为以下

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>发布房源信息</title>
    <!--下面是几个导入的包-->
    <link rel="stylesheet" href="../css/houseCheckStyle.css"/>
    <link type="text/css" href="../css/css.css" rel="stylesheet"/>
    <link type="text/css" href="../css/searchInputStyle.css" rel="stylesheet"/>
    <link type="text/css" href="../css/searchReset.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../css/houseSend.css"/>
    <script type="text/javascript" src="../js/js.js"></script>
    <script type="text/javascript" src="../js/jquery.js"></script>
</head>
<body>
<!--头部最上方的框-->
<jsp:include page="${pageContext.request.contextPath}/pages/basehead.jsp"></jsp:include>
<!--头部最上方的框-->

<!--Logo栏和手机号栏-->
<div class="logo-phone">
    <div class="width1190">

        <table align="center" width="100%">
            <tr>
                <td>
                    <h1 class="logo"><a href="../index.jsp"><img src="../images/logo.png" width="163" height="59" /></a></h1>
                </td>
                <td align="center">
                    <div class="phones"><strong>000-00000000</strong></div>
                    <div class="clears"></div>
                </td>

            </tr>
        </table>
    </div><!--width1190/-->
</div><!--logo-phone/-->
<!--Logo栏和手机号栏 END-->

<!--导航栏-->
<div class="list-nav">
    <div class="width1190">
        <ul class="nav">
            <li><a href="index.jsp">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/house/searchHouseViewByType.do?houseType=0&currentPage=1">新房</a></li>
            <li><a href="${pageContext.request.contextPath}/house/searchHouseViewByType.do?houseType=1&currentPage=1">二手房</a></li>
            <li><a href="${pageContext.request.contextPath}/house/searchHouseViewByType.do?houseType=2&currentPage=1">租房</a></li>
            <li class="zhiding"><a href="#">指定购房</a></li>
            <li><a href="${pageContext.request.contextPath}/pages/housePost1.jsp">发布房源</a></li>
            <li><a href="#">公告中心</a></li>
            <li><a href="#">关于我们</a></li>
            <div class="clears"></div>
        </ul><!--nav-->
        <div class="clears"></div>
    </div><!--width1190-->
</div><!--list-nav-->
<!--导航栏End-->

<%--信息填写栏--%>
<div class="width1190" align="center">
    <br/>
    <h4 style="font-size:16px; text-align:center; font-weight:bold;">房源内饰信息填写</h4>
    <br/>
    <div align="center">
        <table align="cenetr">
            <tr>
                <td>
                    <ul class="tg-list">
                        <li class="tg-list-item">
                            <h4>床</h4>
                            <input class="tgl tgl-flip" id="bed" type="checkbox" onclick="bedClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="bed"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>洗衣机</h4>
                            <input class="tgl tgl-flip" id="washing" type="checkbox" onclick="washingClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="washing"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>空调</h4>
                            <input class="tgl tgl-flip" id="air" type="checkbox" onclick="airClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="air"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>阳台</h4>
                            <input class="tgl tgl-flip" id="balcony" type="checkbox" onclick="balconyClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="balcony"></label>
                        </li>

                        <li class="tg-list-item">
                            <h4>冰箱</h4>
                            <input class="tgl tgl-flip" id="ice" type="checkbox" onclick="iceClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="ice"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>卫生间</h4>
                            <input class="tgl tgl-flip" id="toilet" type="checkbox" onclick="toiletClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="toilet"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>厨房</h4>
                            <input class="tgl tgl-flip" id="kitchen" type="checkbox" onclick="kitchenClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="kitchen"></label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr align="center">
                <td style="align-content: center">
                    <ul class="tg-list">
                        <li class="tg-list-item">
                            <h4>电视</h4>
                            <input class="tgl tgl-flip" id="tv" type="checkbox" onclick="tvClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="tv"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>热水器</h4>
                            <input class="tgl tgl-flip" id="heater" type="checkbox" onclick="heaterClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="heater"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>衣柜</h4>
                            <input class="tgl tgl-flip" id="wardrobe" type="checkbox" onclick="wardrobeClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="wardrobe"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>暖气</h4>
                            <input class="tgl tgl-flip" id="heating" type="checkbox" onclick="heatingClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="heating"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>宽带</h4>
                            <input class="tgl tgl-flip" id="internet" type="checkbox" onclick="internetClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="internet"></label>
                        </li>
                        <li class="tg-list-item">
                            <h4>沙发</h4>
                            <input class="tgl tgl-flip" id="sofa" type="checkbox" name="sofa" onclick="sofaClick()"/>
                            <label class="tgl-btn" data-tg-off="无" data-tg-on="有" for="sofa" id="sofal"></label>
                        </li>
                    </ul>
                </td>
            </tr>
        </table>
    </div>
    <%--下一步按钮--%>
    <div align="cneter">
        <div align="center">
            <div class="register-box-con2-box clearfix mar-bottom20 mar-top50" align="center">
                <label class="register-box-con2-box-left" style="width: 500px"></label>
                <div class="register-box-con2-box-right" align="center">
                    <input type="submit" value="提交" class="login-box-cen-form-button w180" id="next_submit"
                           align="center"/>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript" src="../js/jqueryhouse.min.js"></script>
<script type="text/javascript" src="../js/tbdValidate.js"></script>
<script type="text/javascript" src="../js/upload.js"></script>
<script src="../js/jquery-2.1.1.min.js"></script>



<!--这是页脚-->
<jsp:include page="../pages/basefoot.jsp"></jsp:include>

</body>
<script type="text/javascript">
    var bed = 0;
    var washing = 0;
    var air = 0;
    var balcony = 0;
    var ice = 0;
    var toilet = 0;
    var kitchen = 0;
    var tv = 0;
    var heater = 0;
    var wardrobe = 0;
    var heating = 0;
    var internet = 0;
    var sofa = 0;

    function bedClick() {
        if (bed == 0) bed = 1;
        else bed = 0;
    }

    function washingClick() {
        if (washing == 0) washing = 1;
        else washing = 0;
    }

    function airClick() {
        if (air == 0) air = 1;
        else air = 0;
    }

    function balconyClick() {
        if (balcony == 0) balcony = 1;
        else balcony = 0;
    }

    function iceClick() {
        if (ice == 0) ice = 1;
        else ice = 0;
    }

    function toiletClick() {
        if (toilet == 0) toilet = 1;
        else toilet = 0;
    }

    function kitchenClick() {
        if (kitchen == 0) kitchen = 1;
        else kitchen = 0;
    }

    function tvClick() {
        if (tv == 0) tv = 1;
        else tv = 0;
    }

    function heaterClick() {
        if (heater == 0) heater = 1;
        else heater = 0;
    }

    function wardrobeClick() {
        if (wardrobe == 0) wardrobe = 1;
        else wardrobe = 0;
    }

    function heatingClick() {
        if (heating == 0) heating = 1;
        else heating = 0;
    }

    function internetClick() {
        if (internet == 0) internet = 1;
        else internet = 0;
    }

    function sofaClick() {
        if (sofa == 0) sofa = 1;
        else sofa = 0;
    }
    function bedClick() {
        if (bed==0) bed=1;
        else bed=0;
    }
    $(function () {
        $("#next_submit").on("click",function () {
            $.ajax({
                url:"${pageContext.request.contextPath}/house/responsePost3.do",
                type:"post",
                dataType:"json",
                data:{
                    bed:bed,
                    washing:washing,
                    air:air,
                    balcony:balcony,
                    ice:ice,
                    toilet:toilet,
                    kitchen:kitchen,
                    tv:tv,
                    heater:heater,
                    wardrobe:wardrobe,
                    heating:heating,
                    internet:internet,
                    sofa:sofa
                },
                success:function () {
                    window.location.href="${pageContext.request.contextPath}/house/doHousePost.do"
                }
            })
        })
    })

</script>
</html>

bean中新建了一个java文件HouseInter
HouseInter中代码

package com.yiju.bean;

/**
 * 出租房屋内饰表
 */
public class HouseInter {

    private int interId; //内饰表ID
    private int houseId; //对应房源id
    private int bed; //床:0无 1有
    private int washing; //洗衣机:0无 1有
    private int air; //空调: 0无 1有
    private int balcony; //阳台:0无 1有
    private int ice; //冰箱:0无 1有
    private int toilet; //卫生间:0无 1有
    private int kitchen; //厨房:0无 1有
    private int tv; //电视:0无 1有
    private int heater; //热水器:0无 1有
    private int wardrobe; //衣柜:0无 1有
    private int heating; //暖气:0无 1有
    private int internet; //宽带:0无 1有
    private int sofa; //沙发:0无 1有
    private long createTime; //创建时间
    private long updateTime; //更新时间

    public int getInterId() {
        return interId;
    }

    public void setInterId(int interId) {
        this.interId = interId;
    }

    public int getHouseId() {
        return houseId;
    }

    public void setHouseId(int houseId) {
        this.houseId = houseId;
    }

    public int getBed() {
        return bed;
    }

    public void setBed(int bed) {
        this.bed = bed;
    }

    public int getWashing() {
        return washing;
    }

    public void setWashing(int washing) {
        this.washing = washing;
    }

    public int getAir() {
        return air;
    }

    public void setAir(int air) {
        this.air = air;
    }

    public int getBalcony() {
        return balcony;
    }

    public void setBalcony(int balcony) {
        this.balcony = balcony;
    }

    public int getIce() {
        return ice;
    }

    public void setIce(int ice) {
        this.ice = ice;
    }

    public int getToilet() {
        return toilet;
    }

    public void setToilet(int toilet) {
        this.toilet = toilet;
    }

    public int getKitchen() {
        return kitchen;
    }

    public void setKitchen(int kitchen) {
        this.kitchen = kitchen;
    }

    public int getTv() {
        return tv;
    }

    public void setTv(int tv) {
        this.tv = tv;
    }

    public int getHeater() {
        return heater;
    }

    public void setHeater(int heater) {
        this.heater = heater;
    }

    public int getWardrobe() {
        return wardrobe;
    }

    public void setWardrobe(int wardrobe) {
        this.wardrobe = wardrobe;
    }

    public int getHeating() {
        return heating;
    }

    public void setHeating(int heating) {
        this.heating = heating;
    }

    public int getInternet() {
        return internet;
    }

    public void setInternet(int internet) {
        this.internet = internet;
    }

    public int getSofa() {
        return sofa;
    }

    public void setSofa(int sofa) {
        this.sofa = sofa;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "HouseInter{" +
                "interId=" + interId +
                ", houseId=" + houseId +
                ", bed=" + bed +
                ", washing=" + washing +
                ", air=" + air +
                ", balcony=" + balcony +
                ", ice=" + ice +
                ", toilet=" + toilet +
                ", kitchen=" + kitchen +
                ", tv=" + tv +
                ", heater=" + heater +
                ", wardrobe=" + wardrobe +
                ", heating=" + heating +
                ", internet=" + internet +
                ", sofa=" + sofa +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值