14 集合项目

1,目录结构如下


I@96G0E_QE8C4082YKQYYIB.png

2,新建一个springcloud-2.0-parent项目
导入jar


            
                4.0.0
                pom
                
                    springcloud-2.0-api-order-service-impl
                    springcloud-2.0-api-member-service-impl
                    springcloud-2.0-api-service
                
                
                    org.springframework.boot
                    spring-boot-starter-parent
                    2.0.1.RELEASE
                     
                
                com.taotao
                springcloud
                0.0.1-SNAPSHOT
                springcloud
                Demo project for Spring Boot

                
                    1.8
                    Greenwich.RC2
                

    
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
      
            org.springframework.cloud
            spring-cloud-starter-openfeign
        
        
            org.projectlombok
            lombok
        


    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/milestone
        
    


3,新建model springcloud-2.0-api-service
4,在model里新建 springcloud-2.0-api-member-service , springcloud-2.0-api-order-service
5在 springcloud-2.0-api-member-service 里面新建entity, service包 ,分别建立2个class

package com.taotao.demo.entity;


public class UserEntity {
    private  String name;
    private  Integer age;

    public String getName() {
        return name;
    }

    public UserEntity setName(String name) {
        this.name = name;
        return this;
    }

    public Integer getAge() {
        return age;
    }

    public UserEntity setAge(Integer age) {
        this.age = age;
        return this;
    }
}
package com.taotao.demo.service;

import com.taotao.demo.entity.UserEntity;
import org.springframework.web.bind.annotation.RequestMapping;


public interface IMemberService {
    //实体类是存放接口项目还是存放在实现项目里
    //实体类和定义接口信息存放在接口项目
    //代码实现存放在接口实现项目里
@RequestMapping("/getMember")
public UserEntity getMember(String name);


}

6,在springcloud-2.0-parent 新建2个项目,

springcloud-2.0-api-member-service-impl , springcloud-2.0-api-order-service-impl

7, springcloud-2.0-api-member-service-impl 的jar包
pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.1.RELEASE
         
    
    com.taotao
    springcloudeurekamember31
    0.0.1-SNAPSHOT
    springcloudeurekamember31
    Demo project for Spring Boot

    
        1.8
        Greenwich.RC1
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            com.taotao
            springcloud-2.0-api-member-service
            0.0.1-SNAPSHOT
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.cloud
            spring-cloud-openfeign-core
            2.1.0.RC3
            compile
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/milestone
        
    


4,启动类

package com.taotao.demo;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;


@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
public class DemoApplication {

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

}

新建 com.taotao.demo.service.impl 包

package com.taotao.demo.service.impl;

import com.taotao.demo.entity.UserEntity;
import com.taotao.demo.service.IMemberService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemberServiceImpl  implements IMemberService {
    @Override
    @RequestMapping("/getMember")
    public UserEntity getMember(String name) {
        UserEntity userEntity =new UserEntity();
        userEntity.setName(name);
        userEntity.setAge(20);
          return userEntity;
    }
}

你可能感兴趣的:(14 集合项目)