色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Spring Cloud入門系列服務(wù)提供者總結(jié)

瀏覽:46日期:2023-07-09 14:53:24

服務(wù)提供者使用Eureka Client組件創(chuàng)建首先在父項目中創(chuàng)建Eureka Client Server項目(Maven)創(chuàng)建完成以后,修改pom.xml文件

<?xml version='1.0' encoding='UTF-8'?><project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'> <parent><artifactId>com.wenqi.springcloud</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>EurekaClient</artifactId> <dependencies><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <version>2.0.2.RELEASE</version></dependency> </dependencies></project>

編寫application.yml文件

server: port: 8010 # 當前服務(wù)注冊在eureka server上的名稱spring: application: name: provider # 當前注冊中心的訪問地址eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ # 是否將當前服務(wù)的ip注冊到Eureka Server instance: prefer-ip-address: true

創(chuàng)建啟動類

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

啟動啟動類,這時候訪問http://localhost:8761/ 可以看到服務(wù)注冊進來了。接下來進行增刪改查的簡單業(yè)務(wù)服務(wù)操作

創(chuàng)建實體類

@Data@AllArgsConstructor@NoArgsConstructorpublic class Student { private long id; private String name; private int age;}

創(chuàng)建repository

public interface StudentRepository { public Collection<Student> findAll(); public Student findById(long id); public void saveOrUpdate(Student student); public void deleteById(long id);}

創(chuàng)建repository實現(xiàn)類

@Repositorypublic class StudentRepositoryimpl implements StudentRepository { private static Map<Long,Student> studentMap; static {studentMap = new HashMap<Long, Student>();studentMap.put(1L,new Student(1L,'張三',22));studentMap.put(2L,new Student(2L,'王五',20));studentMap.put(3L,new Student(3L,'李四',21)); } public Collection<Student> findAll() {return studentMap.values(); } public Student findById(long id) {return studentMap.get(id); } public void saveOrUpdate(Student student) {studentMap.put(student.getId(),student); } public void deleteById(long id) {studentMap.remove(id); }}

實現(xiàn)增刪改查操作 controller

@RestController@RequestMapping('/student')public class StudentController { @Autowired private StudentRepository studentRepository; @GetMapping('/findAll') public Collection<Student> findAll(){return studentRepository.findAll(); } @GetMapping('/findById/{id}') public Student findById(@PathVariable('id') long id){return studentRepository.findById(id); } @PostMapping('/save') public void save(@RequestBody Student student){studentRepository.saveOrUpdate(student); } @PutMapping('/update') public void update(@RequestBody Student student){studentRepository.saveOrUpdate(student); } @DeleteMapping('/delete/{id}') public void deleteById(@PathVariable('id') long id){studentRepository.deleteById(id); }}

啟動Eureka Client,并啟動Eureka Server。使用postman工具進行測試

Spring Cloud入門系列服務(wù)提供者總結(jié)Spring Cloud入門系列服務(wù)提供者總結(jié)

postman的使用自己下去進行了練習,不得不說測試還是很有必要的。

以上就是Spring Cloud入門服務(wù)提供者總結(jié)的詳細內(nèi)容,更多關(guān)于Spring Cloud服務(wù)提供者的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 一区国严二区亚洲三区 | 欧美性另类69xxxx极品 | 操操综合 | 欧美一区二区三区精品 | 亚洲黄色小视频 | 国产精品久久久久影视不卡 | 精品国产自在在线在线观看 | 99国产视频 | 色拍拍在精品视频69影院在线 | 亚洲国产成人久久一区久久 | 99re久久资源最新地址 | 亚洲看片网 | 狠狠色综合久久婷婷 | 中文字幕一区在线播放 | 毛片免费永久不卡视频观看 | 亚洲性影院 | 欧美性一区二区三区 | 狠狠色婷婷丁香综合久久韩国 | aaa色| 欧美牛逼aa | 免费在线亚洲 | 性刺激久久久久久久久 | 国产一级毛片夜一级毛片 | 国产亚洲精品久久久久久无 | 久久99九九精品免费 | 99免费观看视频 | 美女一丝不佳一级毛片香蕉 | 国产精品久久久久网站 | 免费国产一区二区在免费观看 | 99久久国产免费 - 99久久国产免费 | 久久久黄色大片 | 欧美激情免费观看一区 | 美女和男人免费网站视频 | 免费高清国产 | 久久综合久久精品 | 99精品小视频 | 亚洲免费在线 | 成人综合婷婷国产精品久久免费 | 亚洲b| 国产真实乱子伦xxxxchina | 一区 在线播放 |