QueryStringBindable in PlayFramework

To fetch the querystring parameters in Controller we usually use request().queryString()

Map<String, String[]> queryString = request().queryString();

If we have multiple query-string keys and want to use a POJO to use query-string instead of parsing everything in Controller we can use QueryStringBindable
If you have take a look in your project you will see just simple parameters as argument ( Path argument ) in your GET method controller, In order to use Java POJO as input for query string i implements QueryStringBindable<T> in my POJO

Here is my sample POJO and my controller method

Added a entry in routes,

GET /test controllers.PaginationParamsTest.test(testViewModel: viewmodel.PaginationParams)

When you configure this action in your routes file, an error will be printed in your console. No QueryString binder found for type

Its required to add the below line in build.sbt

routesImport += “viewmodel.PaginationParams”

or we can simply add routesImport += “viewmodel._” to include all the Classes in the package



Default image
Vignesh A Sathiyanantham
AWS Certified developer with 8 years of extensive experience working for Cloud and Datacenter solutions and leading a small team in a lean startup based on Bangalore, India

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.