基础版本完成
This commit is contained in:
		@@ -2,6 +2,8 @@ package com.test;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 | 
			
		||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BorrowApplication
 | 
			
		||||
@@ -11,6 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 * @Create 2023/8/14 16:25
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
@EnableEurekaClient
 | 
			
		||||
public class BorrowApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(BorrowApplication.class, args);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import com.test.entity.UserBorrowDetail;
 | 
			
		||||
import com.test.service.BorrowService;
 | 
			
		||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
 
 | 
			
		||||
@@ -33,12 +33,10 @@ public class BorrowServiceImpl implements BorrowService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public UserBorrowDetail getUserBorrowDetailByUid(int uid) {
 | 
			
		||||
        List<Borrow> borrow = mapper.getBorrowsByUid(uid);
 | 
			
		||||
//        //RestTemplate支持多种方式的远程调用
 | 
			
		||||
//        RestTemplate template = new RestTemplate();
 | 
			
		||||
//        这里通过调用getForObject来请求其他服务,并将结果自动进行封装
 | 
			
		||||
        //获取User信息
 | 
			
		||||
 | 
			
		||||
        //这里不用再写IP,直接写服务名称userservice
 | 
			
		||||
        User user = template.getForObject("http://userservice/user/" + uid, User.class);
 | 
			
		||||
        //获取每一本书的详细信息
 | 
			
		||||
        //这里不用再写IP,直接写服务名称bookservice
 | 
			
		||||
        List<Book> bookList = borrow.stream().map(b -> template.getForObject("http://bookservice/book/" + b.getBid(), Book.class)).collect(Collectors.toList());
 | 
			
		||||
        return new UserBorrowDetail(user, bookList);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,8 @@ spring:
 | 
			
		||||
    password: mactest
 | 
			
		||||
eureka:
 | 
			
		||||
  client:
 | 
			
		||||
    # 跟上面一样,需要指向Eureka服务端地址,这样才能进行注册
 | 
			
		||||
    service-url:
 | 
			
		||||
    serviceUrl:
 | 
			
		||||
      defaultZone: http://localhost:8888/eureka
 | 
			
		||||
  instance:
 | 
			
		||||
    prefer-ip-address: true
 | 
			
		||||
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user