├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── phstudy │ │ └── sample │ │ ├── configuration │ │ └── ElasticsearchConfig.java │ │ ├── controller │ │ ├── HomeController.java │ │ └── rest │ │ │ └── BookRestController.java │ │ ├── model │ │ └── Book.java │ │ └── repository │ │ └── BookRepository.java ├── resources │ └── log4j.xml └── webapp │ ├── WEB-INF │ ├── spring │ │ ├── appServlet │ │ │ └── servlet-context.xml │ │ ├── elasticsearch-context.xml │ │ └── root-context.xml │ ├── views │ │ ├── book.jsp │ │ ├── home.jsp │ │ └── traditional.jsp │ └── web.xml │ └── resources │ └── js │ └── jquery.bootpag.js └── test └── resources └── log4j.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Eclipse Project 15 | .classpath 16 | .project 17 | .settings/ 18 | target/ 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Yuen-Kuei Hsueh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SpringMVC-SpringDataElasticsearch 2 | ================================= 3 | 4 | An Example for Spring MVC and Spring Data Elasticsearch 5 | 6 | ## Setup Elasticsearch IP 7 | ``` 8 | org.phstudy.sample.configuration.ElasticsearchConfig.java 9 | ``` 10 | 11 | ## Run Example 12 | ``` 13 | mvn tomcat:run 14 | ``` 15 | 16 | ## Browse the sample project 17 | ``` 18 | http://localhost:8080/sample 19 | ``` 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | org.phstudy 6 | sample 7 | spring-mvc-elasticsearch 8 | war 9 | 1.0.0-BUILD-SNAPSHOT 10 | 11 | 1.6 12 | 4.0.6.RELEASE 13 | 1.6.10 14 | 1.6.6 15 | 16 | 17 | 18 | 19 | org.springframework 20 | spring-context 21 | ${org.springframework-version} 22 | 23 | 24 | 25 | commons-logging 26 | commons-logging 27 | 28 | 29 | 30 | 31 | org.springframework 32 | spring-webmvc 33 | ${org.springframework-version} 34 | 35 | 36 | 37 | 38 | org.aspectj 39 | aspectjrt 40 | ${org.aspectj-version} 41 | 42 | 43 | 44 | 45 | org.slf4j 46 | slf4j-api 47 | ${org.slf4j-version} 48 | 49 | 50 | org.slf4j 51 | jcl-over-slf4j 52 | ${org.slf4j-version} 53 | runtime 54 | 55 | 56 | org.slf4j 57 | slf4j-log4j12 58 | ${org.slf4j-version} 59 | runtime 60 | 61 | 62 | log4j 63 | log4j 64 | 1.2.15 65 | 66 | 67 | javax.mail 68 | mail 69 | 70 | 71 | javax.jms 72 | jms 73 | 74 | 75 | com.sun.jdmk 76 | jmxtools 77 | 78 | 79 | com.sun.jmx 80 | jmxri 81 | 82 | 83 | runtime 84 | 85 | 86 | 87 | 88 | javax.inject 89 | javax.inject 90 | 1 91 | 92 | 93 | 94 | 95 | javax.servlet 96 | servlet-api 97 | 2.5 98 | provided 99 | 100 | 101 | javax.servlet.jsp 102 | jsp-api 103 | 2.1 104 | provided 105 | 106 | 107 | javax.servlet 108 | jstl 109 | 1.2 110 | 111 | 112 | 113 | 114 | junit 115 | junit 116 | 4.7 117 | test 118 | 119 | 120 | 121 | 122 | org.elasticsearch 123 | elasticsearch 124 | 1.3.1 125 | 126 | 127 | 128 | 129 | org.springframework.data 130 | spring-data-elasticsearch 131 | 1.0.0.RELEASE 132 | 133 | 134 | 135 | 136 | net._01001111 137 | jlorem 138 | 1.3 139 | 140 | 141 | 142 | 143 | 144 | maven-eclipse-plugin 145 | 2.9 146 | 147 | 148 | org.springframework.ide.eclipse.core.springnature 149 | 150 | 151 | org.springframework.ide.eclipse.core.springbuilder 152 | 153 | true 154 | true 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-compiler-plugin 160 | 2.5.1 161 | 162 | 1.6 163 | 1.6 164 | -Xlint:all 165 | true 166 | true 167 | 168 | 169 | 170 | org.codehaus.mojo 171 | exec-maven-plugin 172 | 1.2.1 173 | 174 | org.test.int1.Main 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /src/main/java/org/phstudy/sample/configuration/ElasticsearchConfig.java: -------------------------------------------------------------------------------- 1 | package org.phstudy.sample.configuration; 2 | 3 | import static org.elasticsearch.node.NodeBuilder.nodeBuilder; 4 | 5 | import java.io.IOException; 6 | 7 | import org.elasticsearch.client.Client; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.ImmutableSettings; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.InetSocketTransportAddress; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.data.elasticsearch.core.ElasticsearchOperations; 15 | import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 16 | import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; 17 | 18 | @Configuration 19 | @EnableElasticsearchRepositories(basePackages = "org.phstudy.sample.repository") 20 | public class ElasticsearchConfig { 21 | @Bean 22 | ElasticsearchOperations elasticsearchTemplate() throws IOException { 23 | 24 | // transport client 25 | Settings settings = ImmutableSettings.settingsBuilder() 26 | .put("cluster.name", "elasticsearch") 27 | .put("username","myname") 28 | .put("password","mypassword").build(); 29 | 30 | Client client = new TransportClient(settings) 31 | .addTransportAddress(new InetSocketTransportAddress("192.168.73.186", 9300)); 32 | 33 | return new ElasticsearchTemplate(client); 34 | 35 | // node client 36 | // return new ElasticsearchTemplate(nodeBuilder() 37 | // .local(true) 38 | // .settings( 39 | // ImmutableSettings.settingsBuilder() 40 | // .put("cluster.name", "elasticsearch") 41 | // .put("username", "myname") 42 | // .put("password", "mypassword").build()).node() 43 | // .client()); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/org/phstudy/sample/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package org.phstudy.sample.controller; 2 | 3 | import java.text.DateFormat; 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | import java.util.List; 7 | import java.util.Locale; 8 | import java.util.UUID; 9 | 10 | import javax.annotation.PostConstruct; 11 | import javax.annotation.Resource; 12 | 13 | import net._01001111.text.LoremIpsum; 14 | 15 | import org.apache.commons.lang.StringUtils; 16 | import org.apache.commons.lang.math.RandomUtils; 17 | import org.phstudy.sample.model.Book; 18 | import org.phstudy.sample.repository.BookRepository; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.data.domain.Page; 22 | import org.springframework.data.domain.PageRequest; 23 | import org.springframework.data.domain.Pageable; 24 | import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 25 | import org.springframework.data.elasticsearch.core.query.IndexQuery; 26 | import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder; 27 | import org.springframework.stereotype.Controller; 28 | import org.springframework.ui.Model; 29 | import org.springframework.web.bind.annotation.RequestMapping; 30 | import org.springframework.web.bind.annotation.RequestMethod; 31 | import org.springframework.web.bind.annotation.RequestParam; 32 | 33 | /** 34 | * Handles requests for the application home page. 35 | */ 36 | @Controller 37 | public class HomeController { 38 | @Resource 39 | private BookRepository bookRepository; 40 | 41 | private static final Logger logger = LoggerFactory 42 | .getLogger(HomeController.class); 43 | 44 | @Resource 45 | private ElasticsearchTemplate elasticsearchTemplate; 46 | 47 | private static final int MINCOUNT = 100; 48 | private static final int MAXCOUNT = 200; 49 | 50 | @PostConstruct 51 | private void initData() { 52 | List indexQueries = new ArrayList(); 53 | LoremIpsum lorem = new LoremIpsum(); 54 | for (int i = MINCOUNT; i < MAXCOUNT; i++) { 55 | String documentId = UUID.randomUUID().toString(); 56 | Book book = new Book(); 57 | book.setId(documentId); 58 | book.setName(lorem.randomWord()); 59 | book.setMessage(lorem.sentence()); 60 | book.setPrice(RandomUtils.nextDouble()); 61 | IndexQuery indexQuery = new IndexQueryBuilder() 62 | .withId(book.getId()).withObject(book).build(); 63 | indexQueries.add(indexQuery); 64 | } 65 | 66 | // bulk index 67 | elasticsearchTemplate.bulkIndex(indexQueries); 68 | } 69 | 70 | /** 71 | * Simply selects the home view to render by returning its name. 72 | */ 73 | @RequestMapping(value = "/", method = RequestMethod.GET) 74 | public String home(Locale locale, Model model) { 75 | logger.info("Welcome home! The client locale is {}.", locale); 76 | 77 | Date date = new Date(); 78 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, 79 | DateFormat.LONG, locale); 80 | 81 | String formattedDate = dateFormat.format(date); 82 | 83 | model.addAttribute("serverTime", formattedDate); 84 | 85 | return "home"; 86 | } 87 | 88 | @RequestMapping(value = "/search", method = RequestMethod.GET) 89 | public String traditional(Locale locale, Model model, 90 | @RequestParam(value = "query", required = false) String query, 91 | @RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "size", required = false, defaultValue = "10") int size) { 92 | 93 | page -= 1; 94 | 95 | Pageable pageable = new PageRequest(page, size); 96 | 97 | Page pageObj; 98 | if (StringUtils.isBlank(query)) { 99 | pageObj = bookRepository.findAll(pageable); 100 | } else { 101 | pageObj = bookRepository.findByMessage(query, pageable); 102 | } 103 | 104 | model.addAttribute("total", pageObj.getTotalPages()); 105 | model.addAttribute("books", pageObj.getContent()); 106 | model.addAttribute("page", page + 1); 107 | 108 | return "traditional"; 109 | } 110 | 111 | @RequestMapping(value = "/httpservletrequest", method = RequestMethod.GET) 112 | public String httpservletrequest(Locale locale, Model model) { 113 | model.addAttribute("url", "./rest/book2"); 114 | return "book"; 115 | } 116 | 117 | @RequestMapping(value = "/pageable", method = RequestMethod.GET) 118 | public String pageable(Locale locale, Model model) { 119 | model.addAttribute("url", "./rest/book1"); 120 | return "book"; 121 | } 122 | 123 | @RequestMapping(value = "/requestparam", method = RequestMethod.GET) 124 | public String requestparam(Locale locale, Model model) { 125 | model.addAttribute("url", "./rest/book3"); 126 | return "book"; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/phstudy/sample/controller/rest/BookRestController.java: -------------------------------------------------------------------------------- 1 | package org.phstudy.sample.controller.rest; 2 | 3 | import javax.annotation.Resource; 4 | import javax.servlet.http.HttpServletRequest; 5 | 6 | import org.apache.commons.lang.StringUtils; 7 | import org.phstudy.sample.model.Book; 8 | import org.phstudy.sample.repository.BookRepository; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.data.domain.Page; 12 | import org.springframework.data.domain.PageRequest; 13 | import org.springframework.data.domain.Pageable; 14 | import org.springframework.data.web.PageableDefault; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestMethod; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | @RestController 21 | public class BookRestController { 22 | @Resource 23 | private BookRepository bookRepository; 24 | 25 | private static final Logger logger = LoggerFactory 26 | .getLogger(BookRestController.class); 27 | 28 | @RequestMapping(value = "/rest/book1", method = RequestMethod.GET) 29 | public Page usePageable( 30 | @RequestParam(value = "query", required = false) String query, 31 | @PageableDefault(size = 10) Pageable pageable) { 32 | 33 | logger.info("/rest/book1 -> pageSize = {}, pageNumber = {}", 34 | pageable.getPageNumber(), pageable.getPageSize()); 35 | 36 | if (StringUtils.isBlank(query)) { 37 | return bookRepository.findAll(pageable); 38 | } 39 | return bookRepository.findByMessage(query, pageable); 40 | } 41 | 42 | @RequestMapping(value = "/rest/book2", method = RequestMethod.GET) 43 | public Page useHttpServletRequest( 44 | @RequestParam(value = "query", required = false) String query, 45 | HttpServletRequest request) { 46 | 47 | int size = 10; 48 | int page = Integer.parseInt(request.getParameter("page")); 49 | 50 | logger.info("/rest/book2 -> pageNumber = {}", page); 51 | 52 | Pageable pageable = new PageRequest(page, size); 53 | 54 | if (StringUtils.isBlank(query)) { 55 | return bookRepository.findAll(pageable); 56 | } 57 | return bookRepository.findByMessage(query, pageable); 58 | } 59 | 60 | @RequestMapping(value = "/rest/book3", method = RequestMethod.GET) 61 | public Page useRequestParam( 62 | @RequestParam(value = "query", required = false) String query, 63 | @RequestParam(value = "page") int page, @RequestParam(value = "size", required = false, defaultValue = "10") int size) { 64 | 65 | logger.info("/rest/book3 -> pageNumber = {}", page); 66 | 67 | Pageable pageable = new PageRequest(page, size); 68 | 69 | if (StringUtils.isBlank(query)) { 70 | return bookRepository.findAll(pageable); 71 | } 72 | return bookRepository.findByMessage(query, pageable); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/phstudy/sample/model/Book.java: -------------------------------------------------------------------------------- 1 | package org.phstudy.sample.model; 2 | 3 | import org.springframework.data.elasticsearch.annotations.Document; 4 | 5 | @Document(indexName="book") 6 | public class Book { 7 | private String id; 8 | private Double price; 9 | private String name; 10 | private String message; 11 | 12 | public String getMessage() { 13 | return message; 14 | } 15 | 16 | public void setMessage(String message) { 17 | this.message = message; 18 | } 19 | 20 | public Double getPrice() { 21 | return price; 22 | } 23 | 24 | public void setPrice(Double price) { 25 | this.price = price; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/phstudy/sample/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package org.phstudy.sample.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.phstudy.sample.model.Book; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.data.elasticsearch.annotations.Query; 9 | import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository; 10 | import org.springframework.stereotype.Repository; 11 | 12 | @Repository 13 | public interface BookRepository extends ElasticsearchCrudRepository { 14 | List findByNameAndPrice(String name, Integer price); 15 | 16 | List findByNameOrPrice(String name, Integer price); 17 | 18 | Page findByName(String name, Pageable page); 19 | 20 | Page findByNameNot(String name, Pageable page); 21 | 22 | Page findByPriceBetween(int price, Pageable page); 23 | 24 | Page findByNameLike(String name, Pageable page); 25 | 26 | @Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}") 27 | Page findByMessage(String message, Pageable pageable); 28 | } -------------------------------------------------------------------------------- /src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/spring/elasticsearch-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/book.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 2 | <%@ page session="false"%> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Use @RequestParam to fetch HTTP GET parameter 11 | 12 | 14 | 15 | 17 | 18 | 19 |
20 |
21 | 27 |
28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
IDNameMessagePrice
42 |
43 | 44 |
45 |
46 |
47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 2 | <%@ page session="false"%> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Home 11 | 12 | 14 | 15 | 17 | 18 | 19 | 30 | 31 | 32 | 34 | 35 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/traditional.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 2 | <%@ page session="false"%> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Traditional 11 | 12 | 14 | 15 | 17 | 18 | 19 |
20 |
21 | 27 |
28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
IDNameMessagePrice
${book.id}${book.name}${book.message}${book.price}
50 |
51 | 52 |
53 |
54 |
55 |
56 | 57 | 58 | 59 | 60 | 61 | 62 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | contextConfigLocation 9 | /WEB-INF/spring/root-context.xml 10 | 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | 18 | 19 | appServlet 20 | org.springframework.web.servlet.DispatcherServlet 21 | 22 | contextConfigLocation 23 | /WEB-INF/spring/appServlet/servlet-context.xml 24 | 25 | 1 26 | 27 | 28 | 29 | appServlet 30 | / 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/webapp/resources/js/jquery.bootpag.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve 3 | * bootpag - jQuery plugin for dynamic pagination 4 | * 5 | * Copyright (c) 2013 botmonster@7items.com 6 | * 7 | * Licensed under the MIT license: 8 | * http://www.opensource.org/licenses/mit-license.php 9 | * 10 | * Project home: 11 | * http://botmonster.com/jquery-bootpag/ 12 | * 13 | * Version: 1.0.5 14 | * 15 | */ 16 | (function($, window) { 17 | 18 | $.fn.bootpag = function(options){ 19 | 20 | var $owner = this, 21 | settings = $.extend({ 22 | total: 0, 23 | page: 1, 24 | maxVisible: null, 25 | leaps: true, 26 | href: 'javascript:void(0);', 27 | hrefVariable: '{{number}}', 28 | next: '»', 29 | prev: '«' 30 | }, 31 | $owner.data('settings') || {}, 32 | options || {}); 33 | 34 | if(settings.total <= 0) 35 | return this; 36 | 37 | if(!$.isNumeric(settings.maxVisible) && !settings.maxVisible){ 38 | settings.maxVisible = settings.total; 39 | } 40 | 41 | $owner.data('settings', settings); 42 | 43 | function renderPage($bootpag, page){ 44 | 45 | var lp, 46 | maxV = settings.maxVisible == 0 ? 1 : settings.maxVisible, 47 | step = settings.maxVisible == 1 ? 0 : 1, 48 | vis = Math.floor((page - 1) / maxV) * maxV, 49 | $page = $bootpag.find('li'); 50 | settings.page = page = page < 0 ? 0 : page > settings.total ? settings.total : page; 51 | $page.removeClass('disabled'); 52 | lp = page - 1 < 1 ? 1 : 53 | settings.leaps && page - 1 >= settings.maxVisible ? 54 | Math.floor((page - 1) / maxV) * maxV : page - 1; 55 | $page 56 | .first() 57 | .toggleClass('disabled', page === 1) 58 | .attr('data-lp', lp) 59 | .find('a').attr('href', href(lp)); 60 | 61 | var step = settings.maxVisible == 1 ? 0 : 1; 62 | 63 | lp = page + 1 > settings.total ? settings.total : 64 | settings.leaps && page + 1 < settings.total - settings.maxVisible ? 65 | vis + settings.maxVisible + step: page + 1; 66 | 67 | $page 68 | .last() 69 | .toggleClass('disabled', page === settings.total) 70 | .attr('data-lp', lp) 71 | .find('a').attr('href', href(lp));; 72 | 73 | var $currPage = $page.filter('[data-lp='+page+']'); 74 | if(!$currPage.not('.next,.prev').length){ 75 | var d = page <= vis ? -settings.maxVisible : 0; 76 | $page.not('.next,.prev').each(function(index){ 77 | lp = index + 1 + vis + d; 78 | $(this) 79 | .attr('data-lp', lp) 80 | .toggle(lp <= settings.total) 81 | .find('a').html(lp).attr('href', href(lp)); 82 | }); 83 | $currPage = $page.filter('[data-lp='+page+']'); 84 | } 85 | $currPage.addClass('disabled'); 86 | $owner.data('settings', settings); 87 | } 88 | 89 | function href(c){ 90 | 91 | return settings.href.replace(settings.hrefVariable, c); 92 | } 93 | 94 | return this.each(function(){ 95 | 96 | var $bootpag, lp, me = $(this), 97 | p = ['
    ']; 98 | 99 | if(settings.prev){ 100 | p.push(''); 101 | } 102 | for(var c = 1; c <= Math.min(settings.total, settings.maxVisible); c++){ 103 | p.push('
  • '+c+'
  • '); 104 | } 105 | if(settings.next){ 106 | lp = settings.leaps && settings.total > settings.maxVisible 107 | ? Math.min(settings.maxVisible + 1, settings.total) : 2; 108 | p.push(''); 109 | } 110 | p.push('
'); 111 | me.find('ul.bootpag').remove(); 112 | me.append(p.join('')); 113 | $bootpag = me.find('ul.bootpag'); 114 | me.find('li').click(function paginationClick(){ 115 | 116 | var me = $(this); 117 | if(me.hasClass('disabled')){ 118 | return; 119 | } 120 | var page = parseInt(me.attr('data-lp'), 10); 121 | renderPage($bootpag, page); 122 | $owner.trigger('page', page); 123 | }); 124 | renderPage($bootpag, settings.page); 125 | }); 126 | } 127 | 128 | })(jQuery, window); 129 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | --------------------------------------------------------------------------------