• springboot es


    import lombok.Data;
    import org.springframework.data.elasticsearch.annotations.Document;
    
    @Document(indexName = "users", type = "user",useServerConfiguration = true,createIndex = false)
    @Data
    public class UserEntity {
        private String id;
        private String name;
        private String sex;
        private String age;
    }
    

      2 

    import org.springframework.data.repository.CrudRepository;
    
    public interface UserReposiory extends CrudRepository<UserEntity, String> {
    }
    

      3 

    import java.util.Optional;
    
    @RestController
    public class EsController {
        @Autowired
        private UserReposiory userReposiory;
    
        @RequestMapping("/addUser")
        public UserEntity addUser(@RequestBody UserEntity user) {
            return userReposiory.save(user);
        }
    
        @RequestMapping("/findUser")
        public Optional<UserEntity> findUser(String id) {
            return userReposiory.findById(id);
        }
    
        @RequestMapping("/findAllUser")
        public Iterable<UserEntity> findAllUser() {
            return userReposiory.findAll();
        }
    
        @RequestMapping("/deleteUser")
        public String deltestr(String id){
          userReposiory.deleteById(id);
          return "1";
        }
    }
    

      4  

    server.port=8092
    spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
    5
    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.elasticsearch.client/transport -->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-elasticsearch</artifactId>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    

      

    @SpringBootApplication
    @EnableElasticsearchRepositories(basePackages = "com.sys.esdemo.es")
    public class EsdemoApplication {

    public static void main(String[] args) {
    SpringApplication.run(EsdemoApplication.class, args);
    }

    }
  • 相关阅读:
    关于链表的代码
    c++中的友元函数
    javaweb笔记全套
    包装类、object、单例模式、final、抽象类
    Linux变量内容的删除、代替与替换
    2014年工作中遇到的20个问题:181-200
    Qt中 QString 和int,double等的转换
    jsp学习笔记总结
    工作日志2014-07-04
    Maple入门使用教程
  • 原文地址:https://www.cnblogs.com/syscn/p/12170028.html
Copyright © 2020-2023  润新知