SpringCloud-Alibaba
Nacos
做为项目的注册中心、配置中心
OpenFeign
远程调用
声明式的HTTP访问
1.引入依赖OpenFeign
2.新增coupon项目被调的collection接口@RequestMapping("/member/list")
3.新增member项目下feign/CouponFeignService调用的service接口
4.主函数开启feign远程调用,basePackage要填feign文件夹的路径
5.member项目下的collection接口调用CouponFeignService的接口
1.引入依赖OpenFeign
。。。
2.新增coupon项目被调的collection接口@RequestMapping("/member/list")
@RequestMapping("/member/list")
public R membercoupons()
{CouponEntity couponEntity = new CouponEntity();couponEntity.setCouponName("满100减10");return R.ok().put("coupons",Arrays.asList(couponEntity));
}
3.新增member项目下feign/CouponFeignService调用的service接口
@FeignClient("coupon")
public interface CouponFeignService{@Requestmapping("/coupon/coupon/member/list")public R membercoupons();
}
4.主函数开启feign远程调用,basePackage要填feign文件夹的路径,就会自动扫描feign有哪些远程调用。
@EnableFeignClients(basePageages = "com.memebr.feign")
@SpringBootApplication
public class Application{publi static void main(String[] args){SpringApplication.run(application.class,args);}
}
5.member项目下的collection接口调用CouponFeignService的接口
@RestController
@RequestMapping("member/member")
public class MemberControllecr
{@AutowiredCouponFeignService couponFeignService;@RequestMappin("/coupon"){R membercoupons = couponFeignService.membercoupons();return R.ok().put("member",membercoupons.get("coupons"));}
}
JSR303
要controller给入参标明@Valid,才会按照规矩校验有效,校验有很多:
1、NotNull、NotEmpty、NotBlank
2、Size、Min、Max
3、Email、Futrue