1. 所有的相同类型的包装类对象之间值的比较,全部使用equals方法比较。

    1. 说明:对于Integer var = ?在-1218 至127之间的赋值,Integer 对象是在
      integerCache . cache产生,会复用已有对象,这个区间内的Integer值可以直接使用==进行
      判断,但是这个区间之外的所有数据,都会在堆上产生,并不会复用已有对象,这是一个大坑,
      推荐使用equals方法进行判断。

    2. 大坑:AtomicStampedReference包装类,注意,如果泛型是一个包装类,注意对象的引用问题 integer使用了对象缓存机制,默认的范围是-128 - 127,推荐使用静态工厂模式的方法valueOf获取对象,而不是new ,因为valueOf使用了缓存 ,而new 一定会创建新的对象分配新的内存空间

  2. list 中通过指定的 值删除集合中的 int 类型的值
    1. 当我们想删除Java List对象中的某一个的时候,可以选择根据索引删除,也可以根据对象删除,调用的方法都是remove。但是当我们对一个List<Integer>对象删除某个元素的,remove(i) 是删除索引为i的元素,还是删除值为i的元素。

    2. 答案是,当我们使用remove(int i),时他默认的时删除了指定索引的元素,而不是数值为 i 的元素,因为当我们 使用 add(i)传入的时候,默认会将我们的 i 传换位 Integer类型的,所以 list集合中存放的 Integer 类型的 i对象,所以不存在  int 型的i。
    3. 即想要使用指定元素删除,要制定出 存入什么类型的,就指定什么类型的
  3. idea中的debuger模式时,step into功能失效,无法进入进入到源码中,方法直接执行过去了,不会进入方法。

    1. 解决办法:

  4. idea在debug模式中,会将数据进行简化,我们看到数据是不完整的,(如arraylist扩容后,扩容的空间在没有数据是,默认是null,但是又是我们会看不到扩容后的数据)
    1. 这就是因为idea将我们的数据进行了简化我们不能看到null,
    2. 问题解决

  5. iea的debug模式中设置显示Arraylist中的null完整查看初始数组大小,扩容过程

     

  6.  SpringBoot配置国际化时,将 MyLocaleResolver 类放入容器时,要注意方法名

    //    要么方法名是 localeResolver,要么   @Bean("localeResolver")
    // 否则容器会无法识别这个类

     

    1. package com.model.config;
      
      
      import org.springframework.web.servlet.LocaleResolver;
      
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import java.util.Locale;
      /**
       * @Description:测试类
       * @Author: 张紫韩
       * @Crete 2021/8/1 17:35
       * 国际化配置
       */
      public class MyLocaleResolver implements LocaleResolver {
          @Override
          public Locale resolveLocale(HttpServletRequest httpServletRequest) {
      //        获取到请求中的语言参数
              String language = httpServletRequest.getParameter("lang");
      //        如果请求参数的连接携带国际化的参数
              Locale locale = Locale.getDefault();
              if (language!=null){
                  String[] split = language.split("_");
                  locale=new Locale(split[0], split[1]);
              }
              return locale;
          }
      
          @Override
          public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
      
          }
      }

       

    2. package com.model.config;

      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.servlet.LocaleResolver;
      import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
      import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

      /**
      * @Description:测试类
      * @Author: 张紫韩
      * @Crete 2021/8/1 15:44
      */
      @Configuration
      public class MyMvcConfig implements WebMvcConfigurer {
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController("/").setViewName("login");
      registry.addViewController("/login").setViewName("login");
      }

      // 要么方法名是 localeResolver,要么 @Bean("localeResolver")
      // 否则容器会无法识别这个类
      @Bean("localeResolver")
      public LocaleResolver localeResolver(){
      return new MyLocaleResolver();
      }

      }

       

        

       

         

       

       

       

       

        
posted @ 2021-06-10 16:03  张紫韩  阅读(59)  评论(0编辑  收藏  举报