Estoy trabajando en un proyecto con Spring Web MVCSpring Web MVC
y HibernateHibernate
, () en el cual quiero obtener una lista de productos por categoría.
Products.javaProducts.java
Products.hbm.xmlProducts.hbm.xml
ProductDao.javaProductDao.java
CatalogController.java
package controller;
import dao.CategoryDao; import dao.ProductDao; import dao.ProductTypeDao; import java.util.List; import javax.servlet.http.HttpServletRequest; import model.pojo.Categories; import model.pojo.ProductTypes; import model.pojo.Products; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView;
@Controller public class MenuController {CatalogController.java
package controller;
import dao.CategoryDao;
import dao.ProductDao;
import dao.ProductTypeDao;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import model.pojo.Categories;
import model.pojo.ProductTypes;
import model.pojo.Products;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class MenuController {
ModelAndView mav = new ModelAndView();
@RequestMapping(value="/catalog/{category}", method = RequestMethod.GET)
public ModelAndView ListProductByCat(HttpServletRequest request) {
int id = Integer.parseInt(request.getParameter("id"));
List<Products> products = ProductDao.ListProductByCat(id);
mav.addObject("products", products);
mav.setViewName("catalog");
return mav;
}
}
}
catalog.jspcatalog.jsp