1.使用Foreach循环,从数据库读取房屋信息
代码:
<c:forEach items="${newHouse}" var="nh">
<dl>
<dt><a href="#"><img src="http://image.cxhit.com/${nh.houseHeadimg}" width="286"
height="188"/></a></dt>
<dd>
<h3><a href="#">${nh.houseTitle}</a></h3>
<div class="hui">${nh.houseLayout} | ${nh.houseArea} | ${nh.houseDecorate}</div>
</dd>
</dl>
</c:forEach>
2.点击更多实现页面跳转
jsp代码:
<h2 class="title"><a style="color:#F1323B">❤</a>新房推荐<a href="${pageContext.request.contextPath}/house/searchHouseViewByType.do?houseType=0">更多>></a></h2>
<div class="index-fang-list">
controller代码:
@RequestMapping("searchHouseViewByType.do")
public ModelAndView searchHouseViewByType(int houseType){
List<HouseView> houses = houseService.searchHouseByType(houseType);
for(HouseView houseView:houses){
long createTime=houseView.getCreateTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String ct = sdf.format(new Date(createTime));
houseView.setDate(ct);
}
ModelAndView mv=new ModelAndView();
mv.addObject("houses",houses);
if(houseType==0){
mv.setViewName("newhouse");
}else if(houseType==1){
mv.setViewName("oldhouse");
}else if(houseType==2){
mv.setViewName("renthouse");
}
return mv;
}
3.实现首页四张图的显示
controller代码:
@RequestMapping("findFourHouseByType.do")
public ModelAndView findFourHouseByType(){
List<HouseView> newhouse=houseService.findFourHouseByType(0);
List<HouseView> oldhouse=houseService.findFourHouseByType(1);
List<HouseView> renthouse=houseService.findFourHouseByType(2);
ModelAndView mv=new ModelAndView();
mv.addObject("newHouse",newhouse);
mv.addObject("oldHouse",oldhouse);
mv.addObject("rentHouse",renthouse);
mv.setViewName("../home");
return mv;
}
mapper代码:
<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=0 order by rand() LIMIT 4
</select>
<select id="searchHouseByType" parameterType="int" resultType="com.yiju.pojo.HouseView">
select * from tb_house a,tb_house_info b,tb_user c where a.is_delete=0 and a.house_id=b.house_id
and a.user_id=c.user_id and a.house_type=#{houseType}
order by a.house_id desc
</select>
点击更多跳转到一下以下页面