java - unable to use matrix variable in spring -
i learning springmvc
, encountered problem not able use matrix variables when call url
neither hitting controller
nor showing exception not triggering code expected have following classes:
controller class
@autowired productrepositiry productrepositiry; @requestmapping("/filter/{path}") public string getfiltered(@matrixvariable(pathvar = "path") map<string, list<string>> filterparms, model model) { model.addattribute("items", productrepositiry.getfilteredproducts(filterparms)); return "viewall"; }
repositiry class
private list<item> list = new arraylist<>(); public list<item> getlist() { item first = new item(); first.setitemone("firstone"); first.setitemtwo("firsttwo"); first.setitemthree("firstthree"); item second = new item(); second.setitemone("seconeone"); second.setitemtwo("firsttwo"); second.setitemthree("secondthree"); item third = new item(); third.setitemone("thirdone"); third.setitemtwo("thirdtwo"); third.setitemthree("thirdthree"); item 4 = new item(); four.setitemone("fourone"); four.setitemtwo("fourtwo"); four.setitemthree("thirdthree"); list.add(first); list.add(second); list.add(third); list.add(four); return list; } public set<item> getfilteredproducts(map<string, list<string>> filterparms) { set<string> keys = filterparms.keyset(); set<item> itemone = new hashset<>(); set<item> itemtwo = new hashset<>(); if (keys.contains("item")) { (string 1 : filterparms.get("item")) { (item : list) { if (one.equalsignorecase(i.getitemtwo())) itemone.add(i); } } } else throw new nullpointerexception("value not found"); if (keys.contains("one")) { (string 2 : filterparms.get("one")) { (item : list) { if (two.equalsignorecase(i.getitemthree())) { itemtwo.add(i); } } } } itemone.addall(itemtwo); (item : itemone) { system.out.println(i.getitemone()); } return itemone; } }
url
http://localhost:8080/matrix_variables/filter;item=firsttwo
while hitting url
viewall
(jsp page) supposed show data of first
, second
repositiry
class returning error
error
http status 404 - type status report message description requested resource not available. apache tomcat/8.0.36
the thing mention when i'm running project ("/")
working fine when introduced matrix variable not working.
and dispatcherservlet-servlet.xml
<mvc:annotation-driven enable-matrix-variables="true" /> <context:component-scan base-package="com" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="suffix" value=".jsp" /> <property name="prefix" value="/view/" /> </bean>
all want fetch values repositiry using matrix variable view not happening,i wrong there, not able find it,can me problem.
best regards
you using ";" in request url. use "/" instead.
Comments
Post a Comment