本文共 2071 字,大约阅读时间需要 6 分钟。
package cn.netkiller;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ComponentScan;import org.springframework.data.jpa.repository.config.EnableJpaRepositories;import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;import org.springframework.scheduling.annotation.EnableScheduling;@SpringBootApplication@EnableAutoConfiguration@ComponentScan@EnableMongoRepositories@EnableJpaRepositories@EnableSchedulingpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
spring.data.elasticsearch.repositories.enabled=truespring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
@Document(indexName = "province", type = "city")public class City implements Serializable { private static final long serialVersionUID = -1L; private Long id; private String name; private String description; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; }}
public interface CityRepository extends ElasticsearchRepository{ List findByNameLike(String name); Page findByDescription(String description, Pageable page); Page findByDescriptionNot(String description, Pageable page); Page findByDescriptionLike(String description, Pageable page);}