문제

Within the @Controller of a search engine:

@RequestMapping(value = "/search/{query}", method = RequestMethod.GET)
public String search(@PathVariable String query) {}

If a user wants to search /search/w?rld (which should match world, warld, whrld, etc.), the variable query equals w, because of the question mark which indicated a GET var.

I tried "/search/{query:.+}", but still doesn't work.

Any idea how to solve that problem?

도움이 되었습니까?

해결책

The problem is not in the Spring configuration. It's in the URL. The question mark is the symbol indicating the start of the query String. If it's part of the URL, it must be encoded:

/search/w%3Frld

다른 팁

if it is just for one method :

Spring MVC - How to get all request params in a map in Spring controller?

add WebRequest req to your signature method then Map parameters = req.getParameterMap();

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top