How to make a component of pagination in hibernate jpa,
<p><strong>This is my Controller that fetches city table from database..is there any way to create a component of pagination to use it again and again in my other JSPs..so that i just call the component and pass parameters...</strong></p>

<pre><code>@RequestMapping(value = "/city")
    public ModelAndView getCityPaginatedPage(@RequestParam(value="pageNumber",required = false) Integer pageNumber,@ModelAttribute ("model") AdminCityModel CityModel, BindingResult result, ModelAndView model) {

        if(pageNumber==null){
            pageNumber=1;
        }

        Page&lt;AdminCityModel&gt; page = service.getCityListFrom1To10(pageNumber);
        List&lt;AdminCityModel&gt; CityList =page.getContent();

        int current = page.getNumber() + 1;
        int begin = Math.max(1, current - 5);
        int end = Math.min(begin + 10, page.getTotalPages());
        model.addObject("page", page);
        model.addObject("CityList", CityList);
        model.addObject("beginIndex", begin);
        model.addObject("endIndex", end);
        model.addObject("currentIndex", current);
        model.setViewName("admin/city");
        return model;
    }
</code></pre>

<p><strong>This is my service..</strong></p>

<pre><code>public interface AdminCityService {

public Page&lt;AdminCityModel&gt; getCityListFrom1To10(Integer pageNumber);

}
</code></pre>

<p><strong>This is my Service Implementation</strong></p>

<pre><code>@Transactional
public Page&lt;AdminCityModel&gt; getCityListFrom1To10(Integer pageNumber) {
    PageRequest request =
            new PageRequest(pageNumber - 1,Constants.PAGE_SIZE, Sort.Direction.ASC, "id");
    Page&lt;AdminCityModel&gt; res= repository.findAll(request);
    return res;
}
</code></pre>

<p><strong>This is my Jsp</strong></p>

<pre><code>&lt;form id="updatecity"&gt;
                    &lt;table id="cityTable" class="table table-responsive table-hover" style="width: 50%"&gt;
                        &lt;thead&gt;
                              &lt;tr&gt;
                                &lt;th style = "text-align: center;"&gt;Id&lt;/th&gt;
                                &lt;th style = "text-align: center;"&gt;City Name&lt;/th&gt;
                                &lt;th style = "text-align: center;"&gt;Change City&lt;/th&gt;
                              &lt;/tr&gt;
                        &lt;/thead&gt;
                        &lt;tbody&gt;
                            &lt;c:forEach items="${CityList}" var = "ctable" &gt;
                                &lt;tr&gt;
                                    &lt;td id="id" style = "text-align: center;"&gt;
                                        &lt;c:out value="${ctable.id}"&gt;&lt;/c:out&gt;
                                    &lt;/td&gt;
                                    &lt;td id="city" style = "text-align: center;"&gt;
                                        &lt;c:out value="${ctable.city}"&gt;&lt;/c:out&gt;
                                    &lt;/td&gt;
                                    &lt;td style = "text-align: center;"&gt;
                                        &lt;button type="button"  class="btn btn-default editbtn"&gt;Edit&lt;/button&gt;
                                    &lt;/td&gt;
                                 &lt;/tr&gt;
                            &lt;/c:forEach&gt;
                        &lt;/tbody&gt;
                    &lt;/table&gt;
    &lt;c:url var="firstUrl" value="/admin/city?pageNumber=1" /&gt;
                    &lt;c:url var="lastUrl" value="/admin/city?pageNumber=${page.totalPages}" /&gt;
                    &lt;c:url var="prevUrl" value="/admin/city?pageNumber=${currentIndex - 1}" /&gt;
                    &lt;c:url var="nextUrl" value="/admin/city?pageNumber=${currentIndex + 1}" /&gt;

&lt;div class="pagination" id="pagination"&gt;
                        &lt;ul&gt;
                            &lt;c:choose&gt;
                                &lt;c:when test="${currentIndex == 1}"&gt;
                                    &lt;li class="disabled"&gt;&lt;a href="#"&gt;&amp;lt;&amp;lt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;li class="disabled"&gt;&lt;a href="#"&gt;&amp;lt;&lt;/a&gt;&lt;/li&gt;
                                &lt;/c:when&gt;
                                &lt;c:otherwise&gt;
                                    &lt;li&gt;&lt;a href="${firstUrl}"&gt;&amp;lt;&amp;lt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;li&gt;&lt;a href="${prevUrl}"&gt;&amp;lt;&lt;/a&gt;&lt;/li&gt;
                                &lt;/c:otherwise&gt;
                            &lt;/c:choose&gt;
                            &lt;c:forEach var="i" begin="${beginIndex}" end="${endIndex}"&gt;
                                &lt;c:url var="pageUrl" value="/admin/city?pageNumber=${i}" /&gt;
                                &lt;c:choose&gt;
                                    &lt;c:when test="${i == currentIndex}"&gt;
                                        &lt;li class="active"&gt;&lt;a href="${pageUrl}"&gt;&lt;c:out value="${i}" /&gt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;/c:when&gt;
                                    &lt;c:otherwise&gt;
                                        &lt;li&gt;&lt;a href="${pageUrl}"&gt;&lt;c:out value="${i}" /&gt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;/c:otherwise&gt;
                                &lt;/c:choose&gt;
                            &lt;/c:forEach&gt;
                            &lt;c:choose&gt;
                                &lt;c:when test="${currentIndex == page.totalPages}"&gt;
                                    &lt;li class="disabled"&gt;&lt;a href="#"&gt;&amp;gt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;li class="disabled"&gt;&lt;a href="#"&gt;&amp;gt;&amp;gt;&lt;/a&gt;&lt;/li&gt;
                                &lt;/c:when&gt;
                                &lt;c:otherwise&gt;
                                    &lt;li&gt;&lt;a href="${nextUrl}"&gt;&amp;gt;&lt;/a&gt;&lt;/li&gt;
                                    &lt;li&gt;&lt;a href="${lastUrl}"&gt;&amp;gt;&amp;gt;&lt;/a&gt; &lt;/li&gt;
                                &lt;/c:otherwise&gt;
                            &lt;/c:choose&gt;
                        &lt;/ul&gt;
                    &lt;/div&gt;
                &lt;/form&gt;
</code></pre>