午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

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

服務(wù)提供者使用Eureka Client組件創(chuàng)建首先在父項(xiàng)目中創(chuàng)建Eureka Client Server項(xiàng)目(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 # 當(dāng)前服務(wù)注冊(cè)在eureka server上的名稱spring: application: name: provider # 當(dāng)前注冊(cè)中心的訪問地址eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ # 是否將當(dāng)前服務(wù)的ip注冊(cè)到Eureka Server instance: prefer-ip-address: true

創(chuàng)建啟動(dòng)類

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

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

創(chuàng)建實(shí)體類

@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實(shí)現(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); }}

實(shí)現(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); }}

啟動(dòng)Eureka Client,并啟動(dòng)Eureka Server。使用postman工具進(jìn)行測(cè)試

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

postman的使用自己下去進(jìn)行了練習(xí),不得不說測(cè)試還是很有必要的。

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 一级特黄aa大片 | 国产网址在线 | 国产又粗又长又硬 | √8天堂资源地址中文在线 亚洲成人黄色片 | 国产自偷 | 午夜精品影视 | 欧美成人三级在线 | 日韩欧美日本 | 国产精品不卡视频 | 四虎在线免费观看视频 | 国内久久久 | 在线久久| a级黄色片免费看 | 丁香花五月 | 色吧av色av| 中文字幕第27页 | 黄色的视频网站 | 日韩免费在线播放 | 久久一二三四 | 国产xxxxxx| 操人视频在线观看 | 超碰在线99 | 久久亚洲在线 | 制服丝袜一区二区三区 | 日批在线视频 | 91视频成人免费 | 欧美视频在线观看免费 | 亚洲精品视 | 亚洲高清中文字幕 | 四虎国产精品永久在线国在线 | 亚洲天堂网在线视频 | 亚洲大胆人体 | 波多野结衣家庭教师在线观看 | 亚州春色 | 亚洲啪啪网 | 男人的天堂2019 | 人人干美女 | 国产第六页 | 黄色蜜桃视频 | 欧美视频中文字幕 | 欧美精品免费在线观看 |