Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Using the MVC Architecture Wrappin' It Up

how to implement search pointing to same results page from various request mapping methods? ex: /favorites?q=compiler

I was able to implement seperate uri: "http://localhost:8080/search?q=compiler" but how to make search form in various html thymeleaf template point to same search page view from various controllers.

Navjeet Bansal
Navjeet Bansal
349 Points

<form action="/search" method="get"> <div class="input-field"> <input name="q" type="search" placeholder="Search all gifs..." required="required" autocomplete="off"/> <i class="material-icons">search</i> </div> </form> This is what i used in all my html pages, kind of hard coded the search request mapping on all the Pages. Now I am looking for a more dynamic way will let you know if I come up with something. I have an Idea just need to implement that.

1 Answer

The best way I can think of is to add a @RequestParam("q") String searchTerm in every function that returns a list of gifs in every page, making the search very contextual; this is technically possible because submitting the <form> in every page simply adds a ?q="" to the url.