zoukankan      html  css  js  c++  java
  • Spring Boot 相关

    1. SpringBoot工程
    2. 参数解析
    3. HTTP Method
    4. Request / Response / Session
    5. Error/重定向
    6. Logger
    7. IoC
    8. AOP/Aspect
     
    1:SpringBoot工程
     
    框架学习,首先接触看官方文档:(先看做什么,官方的文档细节先忽略,用到去查找)
    start.spring.io
     
    //controller演示
    public class IndexController {
    @RequestMapping(path = {"/","/index"})
    @ResponseBody
    public String Index( ) {
    return " name ";
    }
    }
     
    2:参数解析
    //controller携带参数的演示,路径里面的参数可以解析到函数里面
    @RequestMapping(value = "/profile/{groupId}/{userId}")
    @ResponseBody
    public String profile(@PathVariable("groupId") String groupId,
    @PathVariable("userId") int userId,
    @RequestParam(value = "type", defaultValue = "1") int type,
    @RequestParam(value = "key", defaultValue = "nowcoder") String key) {
    return String.format("{%s},{%d},{%d},{%s}", groupId, userId, type, key);
    }
     
    //设置 type =
    //设置 key =
    //controller携带参数,并且携带@requestparam
    @RequestMapping(value = "/profile/{groupId}/{userId}")
    @ResponseBody
    public String profile(@PathVariable("groupId") String groupId,
    @PathVariable("userId") int userId,
    @RequestParam(value = "type", defaultValue = "1") int type,
    @RequestParam(value = "key", defaultValue = "nowcoder") String key) {
    return String.format("{%s},{%d},{%d},{%s}", groupId, userId, type, key);
    }
     
     
     
    3:HTTP Method
    HTTP Method(代码演示)
    GET 获取接口信息
    HEAD 紧急查看接口HTTP的头
    POST 提交数据到服务器
    PUT 支持幂等性的POST //执行两次是一样的结果;
     
    DELETE 删除服务器上的资源
    OPITIONS 查看支持的方法
    可以设置get post
    Fidder web debugger工具
     
    4:Request / Response / Session
     
     
    request HttpServletResponse
    参数解析 response.addCookie(new
    Cookie(key, value));
    response.addHeader(key, value);
    cookie读取
    http请求字段
    文件上传
    HttpServletRequest
    request.getHeaderNames();
    request.getMethod()
    request.getPathInfo()
    request.getQueryString()
    response
    页面内容返回
    cookie下发
    http字段设置,headers
     
     
    5:Error/重定向
     
    //重定向
    //301:永久转移
    //302:临时转移
     
    //异常的统一处理
    @RequestMapping(path = {"/admin"}, method = {RequestMethod.GET})
    @ResponseBody
    public String admin(@RequestParam("key") String key) {
    if ("admin".equals( key )) {
    return "hello admin";
    }
    throw new IllegalArgumentException( "参数不对" );
    }
     
    @ExceptionHandler()
    @ResponseBody
    public String error(Exception e) {
    return "出现了错误error:" + e.getMessage();
    }
    6:IoC 控制反转:无需关注对象的初始化(享元模式)
    servicecs包下面:通过标记@Services来设置对象,
    controller包下面:通过@Autowired,直接引入对象无需初始化。不需要new Services中的对象;
     
    7:AOP/Aspect 面向切面
    @Aspect
    @Component
    public class LogAspect {
    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
     
    @Before("execution(* com.nowcoder.controller.*Controller.*(..))")
    public void beforeMethod(JoinPoint joinPoint) {
    StringBuilder sb = new StringBuilder();
    for (Object arg : joinPoint.getArgs()) {
    sb.append("arg:" + arg.toString() + "|");
    }//切点打印参数
    logger.info("before method:" + sb.toString());
    }
     
    @After("execution(* com.nowcoder.controller.IndexController.*(..))")
    public void afterMethod() {
    logger.info("after method" + new Date());
    }
    }
     
    南京站接实习归来的两位学长:
    两年前的九月一号第一次到南京站,
    今天来同样的地方接学长,
    与不同时空的自己来了个相遇
    分别从上海杭州互联网公司实习回来的学长们,
    他们比起去年九月七日第一次相遇都成熟不少。
     
     
    认识学长和java转眼一年了,
    三个人都互相了解明明白白了,
    java的技术没学明白,不断的被新技术迭代。
    六月二十八号jdk都迭代到11
    教程中velocity还没使用过就不被支持,thymleaf就来。meaven也逐步被 gradle颠覆,都还没好好接受这就要按照新的前行。九月继续加油哇。
     
     
    来南京两年,认识室友也刚好两年。一个月后眼宿舍就又空空,各奔前程。以前每次室友回来都会带菜带山东煎饼的在客厅里面搞事情的 今天也不例外哇!
     
     
     
     
     

  • 相关阅读:
    ubuntu 12.04(Precise Pangolin)启用休眠(Hibernate)功能的方案
    svn小技巧——重定向svn diff
    引用对象深度复制
    引用对象深度复制的简单实现方法
    vue Excel导出 [post请求+提示语]
    随手笔记-二进制的正负计算
    枚举类的扩展使用
    关于担心java import xxx.*对资源占用的一次小实践
    idea 自动添加注释 (方法+类 带参数/返回值)
    maven打包到本地仓库
  • 原文地址:https://www.cnblogs.com/liguo-wang/p/9568764.html
Copyright © 2011-2022 走看看