• SpringCloud


    1.在项目启动类中加上@EnableFeignClients的注解
    @FeignClient 发现注册服务中的其他服务 fallback回调
    @FeignClient(value = "repository-database-cas", fallback = CustomerCasUserServiceHystrix.class)

    2.method = RequestMethod.POST 参数修饰@RequestBody
    method = RequestMethod.GET 参数修饰@RequestParam 参数会加到URL中

    3.在项目启动类中加上@EnableAsync的注解
    在方法上加上@Async的注解,进行异步处理

    @RequestBody POST请求
    @RequestParam GET请求

    4.使用@Controller 注解,在对应的方法上,视图解析器可以解析return 的jsp,html页面,并且跳转到相应页面
    若返回json等内容到页面,则需要加@ResponseBody注解
    @RestController注解相当于@ResponseBody + @Controller合在一起的作用

    5.spring mvc 支持REST风格的请求方法,GET、POST、PUT和DELETE四种请求方法分别代表了数据库CRUD中的select、insert、update、delete,

    6.feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody。

      设置默认值很简单
      @Value("${NamesrvAddr:192.168.0.1}")
      private String namesrvAddr;

    7.FeignClient接口中,如果使用到@PathVariable ,必须指定其value
    如: @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)
    public User findById(@PathVariable(value="id") Long id);

    8.@ConfigurationProperties(prefix = "shiro.cas")的大致作用就是通过它可以把properties或者yml配置直接转成对象

    9.设置header请求头:
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.addZuulRequestHeader("userId", tokenModel.getUserId());

    Controller层
    获取请求头header中的数据
    @RequestHeader("userId") String userId
    等价于 HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    request.getHeader("userId");

     10.spring cloud StreamListener

  • 相关阅读:
    重构项目使用Spring+Hibernate+HibernateAnnotation+GenericDao技术
    java调用bat
    Redis快速入门
    PDF中添加页面/合并 PDF 内容
    eclipse+webservice开发实例
    MYSQL Migration Toolkit 安装
    从CSDN搬家到博客园
    The server does not support version 3.0 of the J2EE Web module specification
    HibernateAnnotation入门实例
    github使用总结
  • 原文地址:https://www.cnblogs.com/xxj-bigshow/p/9752630.html
Copyright © 2020-2023  润新知