Monday 15 September 2014

java - Spring - Multiple PathVariable values for generic request mapping handler -



java - Spring - Multiple PathVariable values for generic request mapping handler -

i'm trying implement hierarchical taxonomy tree, follows structure

term 1 / \ term 2 term 3 / | \ term 4 term 5 term 6

where each term object contains set containing terms below it.

traditionally, access 3rd level of terms, url

/term/chapter/section/paragraph

a spring requestmapping consist of

@requestmapping(value = "/term/{term1}/{term2}/{term3}", method = requestmethod.get) public term getterm(@pathvariable("term1") term rootterm, @pathvariable("term2") term childterm, @pathvariable("term3") term leafterm) { /* processing code here */ homecoming term; }

the downside limits height of taxonomy tree number of specified handlers requested urls. in case, i'm limited tree of height 3.

is there built in way pass in term url identifiers method no regard number of kid terms? or have work on processing url within controller?

maybe utilize 1 parameter parsing.

instead of specifying url this:

/term/depth1/depth2/.../dephtn

you specify format convention , query term this:

/term/depth1-depth2-...-depthn

in controller can parse url:

@requestmapping(value = "/term/{query}", method = requestmethod.get) public term getterm(@pathvariable string query) { // illustration access string[] parts = query.split("-"); string chapterid = parts[0]; string sectionid = parts[1]; string paragraphid = parts[2]; // ... continued /* processing code here */ homecoming term; }

java spring rest

No comments:

Post a Comment