Spring MVC :URI not working -
i using below url send request,but getting 404 error. warning on server:no mapping found http request uri
the uri is
http://localhost:8080/webstore/products/tablet/price;low=200;high=400?manufacturer="google"
the method in controller used is
@requestmapping(value="/products/{category}/{bycriteria}",method=requestmethod.get) public string getspecificproductbyfilter(@pathvariable("category")string productcategory,@matrixvariable(pathvar= "bycriteria") map<string,list<long>> filterparams,@requestparam string manufacturer,model model){ model.addattribute("products",productservice.getfilterproducts(productcategory,filterparams, manufacturer)); return "products"; } the category signifies "tablet"in uri
criteria signifies"low" , "high"
manufacturer is"google"
for dont know, book "spring mvc begginers guide" amuthan g. question old give there solution in case going need that, me today.
first of @requestmapping wrong. should looks this:
@requestmapping(value="/{category}/{bycriteria}", method=requestmethod.get) and reason have @requestmapping("/products") on whole controller class (above class declaration). , because want map webstore/products/tablet , not webstore/products/products/tablet have leave "products" mapping method.
second thing uri. know in books there 1 , not big deal, if dont want have problems, leave quotation marks next word google. because dont want have value "google" google without these quation marks , if let them there, have problems comparing values. uri should looks this.
http://localhost:8080/webstore/products/tablet/price;low=200;high=400?manufacturer=google
for complete solution have following steps:
in repository , service interfaces , classes write method:
list<product> getproductsbymanufacturer(string manufacturer);and implement in same way wrote method
getproductsbycategory.in repository , service interfaces , classes write method:
set<product> getproductsbyprice(map<string, list<string>> priceparams);and implement in same way wrote method
getproductsbyfilter.finnaly write method in controller class:
@requestmapping("/{category}/{byprice}") public string filterproducts(@pathvariable("category") string productcategory, @matrixvariable(pathvar = "byprice") map<string, list<string>> filterparams, @requestparam string manufacturer, model model) { list<product> bycategory = productservice.getproductsbycategory(productcategory); list<product> bymanufacturer = productservice.getproductsbymanufacturer(manufacturer); set<product> byprice = productservice.getproductsbyprice(filterparams); bycategory.retainall(bymanufacturer); bycategory.retainall(byprice); model.addattribute("products", bycategory); return "products"; }in project method this, can in shorter way. after complete these steps, project should working. if not, feel free ask me there. if dont know how write methods in steps 1 , 2 comment there code you, same methods said. hope going somebody.
Comments
Post a Comment