Created
April 10, 2018 15:04
-
-
Save asvignesh/911ff1b6dd4b96a5368e9d113a6591d0 to your computer and use it in GitHub Desktop.
PaginationParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package viewmodel; | |
import play.mvc.QueryStringBindable; | |
import java.util.Map; | |
import java.util.Optional; | |
public class PaginationParams implements QueryStringBindable<PaginationParams> { | |
private int page; | |
private int offset; | |
private int limit; | |
public int getPage() { | |
return page; | |
} | |
public void setPage(int page) { | |
this.page = page; | |
} | |
public int getOffset() { | |
return offset; | |
} | |
public void setOffset(int offset) { | |
this.offset = offset; | |
} | |
public int getLimit() { | |
return limit; | |
} | |
public void setLimit(int limit) { | |
this.limit = limit; | |
} | |
@Override | |
public Optional<PaginationParams> bind(String key, Map<String, String[]> parameters) { | |
final String page = parameters.get("page")[0]; | |
final String offset = parameters.get("offset")[0]; | |
final String limit = parameters.get("limit")[0]; | |
this.page = Integer.parseInt(page); | |
this.offset = Integer.parseInt(offset); | |
this.limit = Integer.parseInt(limit); | |
return Optional.of(this); | |
} | |
@Override | |
public String unbind(String key) { | |
return null; | |
} | |
@Override | |
public String javascriptUnbind() { | |
return null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.mvc.Controller; | |
import play.mvc.Result; | |
import viewmodel.PaginationParams; | |
public class PaginationParamsTest extends Controller { | |
public Result test(PaginationParams paginationParams) { | |
final int limit = paginationParams.getLimit(); | |
final int offset = paginationParams.getOffset(); | |
final int page = paginationParams.getPage(); | |
return ok(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment