分析
后台代码
RouteServlet类:
/** * 根据id查询一个旅游线路的详细信息 * @param request * @param response * @throws ServletException * @throws IOException */ public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1、接收id String rid = request.getParameter("rid"); // 2、调用service查询route对象 Route route = routeService.findOne(rid); // 3、转为json写回客户端 writeValue(route,response); }
RouteService接口:
Route findOne(String rid);
RouteServiceImpl实现类:
@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()); // 将集合设置到route对象 route.setRouteImgList(routeImgList); // 3、根据route的sid(商家id)查询商家对象 Seller seller = sellerDao.findById(route.getSid()); route.setSeller(seller); return route; }
RouteDao接口:
/** * 根据id查询 * @param rid * @return */ public Route findOne(int rid);
RouteDaoImpl实现类:
@Override public Route findOne(int rid) { String sql = "select * from tab_route where rid = ?"; return template.queryForObject(sql,new BeanPropertyRowMapper<>(Route.class),rid); }
RouteImgDao接口:
public interface RouteImgDao { /** * 根据route的id查询图片 * @param rid * @return */ public List<RouteImg> findByRid(int rid); }
RouteImgDaoImpl实现类:
public class RouteImgDaoImpl implements RouteImgDao { private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource()); @Override public List<RouteImg> findByRid(int rid) { String sql = "select * from tab_route_img where rid = ?"; return template.query(sql,new BeanPropertyRowMapper<>(RouteImg.class),rid); } }
SellerDao接口:
public interface SellerDao { /** * 根据id查询 * @param id * @return */ public Seller findById(int id); }
SellerDaoImpl实现类:
public class SellerDaoImpl implements SellerDao { private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource()); @Override public Seller findById(int id) { String sql = "select * from tab_seller where sid = ?"; return template.queryForObject(sql,new BeanPropertyRowMapper<>(Seller.class),id); } }
标签:return,route,id,线路,详情,后台,findOne,rid,public From: https://www.cnblogs.com/shenziyi/p/17110091.html