发布房源页面

今天写了发布发布房源页面,用到了ajax的方法

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>发布房源信息</title>
    <!--    下面是几个导入的包-->
    <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="#">新房</a></li>
            <li><a href="#">二手房</a></li>
            <li><a href="#">租房</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">

    <br/>
    <h4 style="font-size:16px; text-align:center; font-weight:bold;">房源详细信息填写</h4>
    <br/>

    <!--中心-->
    <div class="content">
        <div class="register-box">
            <div class="wrap">
                <div class="register-box-con2">

                    <!--房源性质-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源性质</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseNature"
                                   placeholder="如:商品房、住宅房等" id="house_natuer"/>
                        </div>
                    </div>

                    <!--房源类型-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源类型</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseModel"
                                   placeholder="如:普通住宅、公寓式住宅、别墅等" id="house_model"/>
                        </div>
                    </div>

                    <!--房源建造年-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源建造年</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseYear"
                                   placeholder="如:2008、2019等" id="house_year"/>
                        </div>
                    </div>

                    <!--房源期限-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源期限</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseValid"
                                   placeholder="如:70年、80年、永久等" id="house_valid"/>
                        </div>
                    </div>

                    <!--房源户型-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源户型</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseLayout"
                                   placeholder="如:2厅4室2卫等" id="house_layout"/>
                        </div>
                    </div>

                    <!--房源面积-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源面积</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseArea"
                                   placeholder="如:100、85等。单位:m²" id="house_narea"/>
                        </div>
                    </div>

                    <!--房源朝向-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源朝向</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseTurn"
                                   placeholder="如:南北、西南等" id="house_turn"/>
                        </div>
                    </div>

                    <!--房源楼层-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>房源楼层</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseFloor"
                                   placeholder="如:6、8、9等" id="house_floor"/>
                        </div>
                    </div>

                    <!--总楼层-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>总楼层</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="floorAll"
                                   placeholder="如:7、13、16等" id="floor_all"/>
                        </div>
                    </div>

                    <!--装修类型-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>装修类型</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseDecorate"
                                   placeholder="如:精装修、简装修等" id="house_decorate"/>
                        </div>
                    </div>

                    <!--是否有电梯-->
                    <div class="register-box-con2-box clearfix mar-bottom20">
                        <label class="register-box-con2-box-left"><em class="bitian">* </em>是否有电梯</label>
                        <div class="register-box-con2-box-right">
                            <input type="text" class="login-box-cen-form-input w358" name="houseLift"
                                   placeholder="如:是、否等" id="house_lift"/>
                        </div>
                    </div>

                    <div class="register-box-con2-box clearfix mar-bottom20 mar-top50" align="center">
                        <label class="register-box-con2-box-left"></label>
                        <div class="register-box-con2-box-right" align="center">
                            <input type="button" value="下一步" class="login-box-cen-form-button w180" id="next_submit"/>
                        </div>
                    </div>
                </div>
            </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">
  $(function () {
      $("#next_submit").on("click",function () {
          var houseNature = $("input[name=houseNature]").val();
          var houseModel = $("input[name=houseModel]").val();
          var houseYear = $("input[name=houseYear]").val();
          var houseValid = $("input[name=houseValid]").val();
          var houseLayout = $("input[name=houseLayout]").val();
          var houseArea = $("input[name=houseArea]").val();
          var houseTurn = $("input[name=houseTurn]").val();
          var houseFloor = $("input[name=houseFloor]").val();
          var floorAll = $("input[name=floorAll]").val();
          var houseDecorate = $("input[name=houseDecorate]").val();
          var houseLift;
          if ($("input[name=houseLift]").val() == "是") {
              houseLift = 1;
          } else {
              houseLift = 0;
          }
          //校验信息
          if (houseNature == "") {
              alert("请输入房源性质!");
              return;
          }
          else if (houseModel == "") {
              alert("请输入房源类型!");
              return;
          }
          else if (houseYear == "") {
              alert("请输入建造时间!");
              return;
          }
          else if (houseValid == "") {
              alert("请输入房源期限!");
              return;
          }
          else if (houseLayout == "") {
              alert("请输入房源户型!");
              return;
          }
          else if (houseArea == "") {
              alert("请输入房源面积!");
              return;
          }
          else if (houseTurn == "") {
              alert("请输入朝向!");
              return;
          }
          else if (houseFloor == "") {
              alert("请输入楼层!");
              return;
          }
          else if (floorAll == "") {
              alert("请输入预售价格!");
              return;
          }
          else if (houseDecorate == "") {
              alert("请输入装饰类型!");
              return;
          } else if (houseLift == "") {
              alert("请说明有无电梯!");
              return;
          }else{
              $.ajax({
                  url:"${pageContext.request.contextPath}/house/responsePost2.do",
                  type:"post",
                  dataType:"json",
                  data:{
                      houseNature:houseNature,
                      houseModel:houseModel,
                      houseYear:houseYear,
                      houseValid:houseValid,
                      houseLayout:houseLayout,
                      houseArea:houseArea,
                      houseTurn:houseTurn,
                      houseFloor:houseFloor,
                      floorAll:floorAll,
                      houseDecorate:houseDecorate,
                      houseLift:houseLift
                  },
                  success:function () {
                      window.location.href="${pageContext.request.contextPath}/pages/housePost3.jsp"

                  }
              });
          }
      });
  })
</script>
</html>

package com.yiju.controller;

import com.github.pagehelper.PageInfo;
import com.yiju.bean.House;
import com.yiju.bean.HouseInfo;
import com.yiju.pojo.HouseView;
import com.yiju.service.IHouseViewService;
import com.yiju.util.YijuUtil;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@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) throws IOException {
       House house=new House();
       house.setHouseTitle(houseTitle);
       house.setHouseAddress(houseAddress);
       house.setHousePrice(housePrice);
       house.setPriceUnit(priceUnit);
       house.setUserId(10005);

        Map<String, MultipartFile> images=new HashMap<>();

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

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

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

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

首页
在这里插入图片描述
发布房源页面

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值