初学Elasticsearch,如果有错误的地方,感谢各位大牛帮我指出~谢谢
首先新建一个maven工程,在pom中引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency>
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
然后在application.properties文件中设置各种配置信息
spring.mvc.static-path-pattern=/static/**
设置静态资源的位置
注:网上查资料说,这里spring boot应该自动映射到resources下去查找资源,但是我的工程中貌似无法加载js,css,所以只有自己指定静态资源的路径,静态资源加载问题解决!
spring.elasticsearch.jest.uris=http://192.168.152.129:9200
spring.elasticsearch.jest.read-timeout=5200
jest客户端连接设置
注意:这里jest客户端使用9200端口,是es默认的http形式管理端口
spring.freemarker.suffix=.html
spring.freemarker.templateEncoding=UTF-8
spring.freemarker.templateLoaderPath=classpath:/templates/
FreeMarker设置
然后是Controller类
@Controller
@RequestMapping("/bank")
public class BankController {
@Autowired
private BankService bankService;
@RequestMapping("/index")
public String index(HttpServletRequest request){
request.setAttribute("base", request.getContextPath());
return "bank/index";
}
@RequestMapping("/query")
public void query(HttpServletRequest request,HttpServletResponse response){
int draw = Integer.valueOf(request.getParameter("draw")