• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Mike London

Spring MVC PathVariable for products and categories implementation

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys ! I develop eCommerce platform but i don't know how to implement the scenario below. I want to have friendly URLs (for SEO stuff..). I have the correct slug in the database for categories and products for example:


wwww.domain.com/category-laptops/ - which are categories

but i and products which are:



How to implement this logic in to the handler below ? How to know when it is product or category ? Do i need to make two separate queries (one for products and one for categories) to the database ?

Saloon Keeper
Posts: 14711
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slugs should only be an after-thought. Don't use them to identify a resource. First design your URLs so they unambiguously locate a resource:



If you still need the slug, for instance when you're using integers for ids rather than unique names, you add them to the URL *after* the URL contains enough information to identify the resource:



In the above code, the index() action will map the {id} part of the URL to the id method parameter, and ignore everything that comes afterwards.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic