实习期间零碎知识点

  1. InitializingBean接口说明
    InitializingBean接口为bean提供了属性初始化后的处理方法,它只包括afterPropertiesSet方法,凡是继承该接口的类,在bean的属性初始化后都会执行该方法。
package org.springframework.beans.factory;

/**
 * Interface to be implemented by beans that need to react once all their
 * properties have been set by a BeanFactory: for example, to perform custom
 * initialization, or merely to check that all mandatory properties have been set.
 *
 * <p>An alternative to implementing InitializingBean is specifying a custom
 * init-method, for example in an XML bean definition.
 * For a list of all bean lifecycle methods, see the BeanFactory javadocs.
 *
 * @author Rod Johnson
 * @see BeanNameAware
 * @see BeanFactoryAware
 * @see BeanFactory
 * @see org.springframework.beans.factory.support.RootBeanDefinition#getInitMethodName
 * @see org.springframework.context.ApplicationContextAware
 */
public interface InitializingBean {

    /**
     * Invoked by a BeanFactory after it has set all bean properties supplied
     * (and satisfied BeanFactoryAware and ApplicationContextAware).
     * <p>This method allows the bean instance to perform initialization only
     * possible when all bean properties have been set and to throw an
     * exception in the event of misconfiguration.
     * @throws Exception in the event of misconfiguration (such
     * as failure to set an essential property) or if initialization fails.
     */
    void afterPropertiesSet() throws Exception;

}

  1. file.listFiles()的lambda表达式来过滤dictory下不满足条件的file:
/*File[] files = dir.listFiles((File d, String name) ->{
                //过滤规则,封装成File(dir,name)对象是文件夹或者获取的文件/文件夹名称name是.java结尾的文件返回true
                return new File(d,name).isDirectory() || name.toLowerCase().endsWith(".java");
            }
        );
         */
        //举个例子
File[] files = dir.listFiles((d, name) -> new File(d,name).isDirectory() || name.toLowerCase().endsWith(".java"));
  1. velocity模板引擎
    可以用来生成java类文件。做法就是先给个模板,然后往模板里面填东西。
    见https://www.jianshu.com/p/bcba20eeab48
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * ==Velocity之Hello Wordld入门程序==
 * <p>
 * 首先,我们在代码中初始化了VelocityEngine这个模板引擎,对其设置参数进行初始化,
 * 指定使用ClasspathResourceLoader来加载vm文件。然后我们就可以往VelocityContext这个Velocity
 * 容器中存放对象了,在vm文件中我们可以取出这些变量,从而进行模板输出。
 */
public class VelocityTest {

    private static final String VM_PATH = "template/velocity/helloworld.vm";

    public static void main(String[] args) {
        // 初始化模板引擎
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();

        // 获取模板文件
        Template template = velocityEngine.getTemplate(VM_PATH);

        // 设置变量,velocityContext是一个类似map的结构
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("name", "world");
        List<String> list = new ArrayList<String>();
        list.add("jack");
        list.add("kitty");
        velocityContext.put("list", list);
        //或者可以直接
        //VelocityContext context = new VelocityContext(map); map是自己填的

        // 输出渲染后的结果
        StringWriter stringWriter = new StringWriter();
        template.merge(velocityContext, stringWriter);
        System.out.println(stringWriter.toString());
    }
}
  1. 注解@PropertySource和@ConfigurationProperties
    这两个注解联合使用可以对类进行初始化
@PropertySource(value = "classpath:Resource下的地址", factory = YamlPropertySourceFactory.class)指明初始化的文件的地址是Resource下的地址
@ConfigurationProperties(prefix = "miaomiao")表明上面资源文件中用于初始化该类的是以miaomiao开头的。
  1. java.util.TreeSet.floor()方法和java.util.TreeSet.ceiling()方法
    floor(E e) 方法返回在这个集合中小于或者等于给定元素的最大元素,如果不存在这样的元素,返回null.
    ceiling(E e) 方法返回在这个集合中大于或者等于给定元素的最小元素,如果不存在这样的元素,返回null.
  2. 查看电脑环境:dxdiag
  3. EasyExcel 的read(https://www.yuque.com/easyexcel/doc/read):
    Listener的写法:
    构造函数:
public DemoDataListener(DemoDAO demoDAO) {
        this.demoDAO = demoDAO;
    }

invoke函数:在每一条数据解析时都会来调用。
doAfterAllAnalysed函数:所有数据解析完成了会来调用。
9.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值