目录
- 13. 旅游线路的详情展示
- 13.1 分析
- 13.2 代码实现
- 13.2.1 后台代码
- 13.2.2 前台代码
分类-分页-查询-详情展示功能源码:
链接:https://pan.baidu.com/s/1xzvE0GqfV_uo0j7NCzWRhQ
提取码:mxpw
复制这段内容后打开百度网盘手机App,操作更方便哦
13. 旅游线路的详情展示
13.1 分析
13.2 代码实现
13.2.1 后台代码
Servlet
/*** 根据id查询一个旅游线路的详细信息* @param request* @param response* @throws ServletException* @throws IOException*/
public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//1.接收idString rid = request.getParameter("rid");//2.调用service查询route对象Route route = routeService.findOne(rid);//3.转为json写回客户端writeValue(route,response);
}
Service
@Override
public Route findOne(String rid) {//1.根据id去route表中查询route对象Route route = routeDao.findOne(Integer.parseInt(rid));//2.根据route的id 查询图片集合信息List<RouteImg> routeImgList = routeImgDao.findByRid(route.getRid());//2.2将集合设置到route对象route.setRouteImgList(routeImgList);//3.根据route的sid(商家id)查询商家对象Seller seller = sellerDao.findById(route.getSid());route.setSeller(seller);return route;
}
SellerDao
public class SellerDaoImpl implements SellerDao {private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());@Overridepublic Seller findById(int id) {String sql = "select * from tab_seller where sid = ? ";return template.queryForObject(sql,new BeanPropertyRowMapper<Seller>(Seller.class),id);}
}
routeDao
@Override
public Route findOne(int rid) {String sql = "select * from tab_route where rid = ?";return template.queryForObject(sql,new BeanPropertyRowMapper<Route>(Route.class),rid);
}
RouteImgDao
public class RouteImgDaoImpl implements RouteImgDao {private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());@Overridepublic List<RouteImg> findByRid(int rid) {String sql = "select * from tab_route_img where rid = ? ";return template.query(sql,new BeanPropertyRowMapper<RouteImg>(RouteImg.class),rid);}
}
13.2.2 前台代码
Route_detail.html中加载后
- 获取rid
- 发送ajax请求,获取route对象
- 解析对象的数据
//1.获取rid
var rid = getParameter("rid");//2.发送请求请求 route/findOne$.get("route/findOne",{rid:rid},function (route) {//3.解析数据填充html$("#rname").html(route.rname);$("#routeIntroduce").html(route.routeIntroduce);$("#price").html("¥"+route.price);$("#sname").html(route.seller.sname);$("#consphone").html(route.seller.consphone);$("#address").html(route.seller.address);//图片展示var ddstr = '<a class="up_img up_img_disable"></a>';//遍历routeImgListfor (var i = 0; i < route.routeImgList.length; i++) {var astr ;if(i >= 4){astr = '<a title="" class="little_img" data-bigpic="'+route.routeImgList[i].bigPic+'" style="display:none;">\n' +' <img src="'+route.routeImgList[i].smallPic+'">\n' +' </a>';}else{astr = '<a title="" class="little_img" data-bigpic="'+route.routeImgList[i].bigPic+'">\n' +' <img src="'+route.routeImgList[i].smallPic+'">\n' +' </a>';}ddstr += astr;}ddstr+='<a class="down_img down_img_disable" style="margin-bottom: 0;"></a>';$("#dd").html(ddstr);//图片展示和切换代码调用goImg();});