SpringCloud微服务-生产者消费者

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/t1g2q3/article/details/85246425
import com.simons.cn.bean.User;
import com.simons.cn.service.UserServiceImpl;
import com.simons.cn.util.CommonEnum;
import com.simons.cn.util.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
 
@Slf4j
@RestController
public class UserController {
 
    @Autowired
    private UserServiceImpl userService;
 
    @GetMapping(value = "/getuserinfo")
    public CommonResult getUserInfo(@RequestParam(required = false,value = "name") String name){
        List<User> userList = userService.getUserByName(name);
        return CommonResult.success(CommonEnum.SUCESS.getCode(),CommonEnum.SUCESS.getMessage(),userList);
    }
}
import com.simons.cn.util.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
 
@Slf4j
@RestController
public class TicketController {
 
    @Autowired
    private RestTemplate restTemplate;
 
    @GetMapping("/ticketpurchase")
    public CommonResult purchaseTicket(@RequestParam(required = false,value = "name") String name){
        //模拟判断用户身份
        CommonResult result = restTemplate.getForObject("http://localhost:8000/getuserinfo?name=" + name, CommonResult.class);
        //买票下单逻辑略
        return result;
    }
 
}

猜你喜欢

转载自blog.csdn.net/t1g2q3/article/details/85246425