个人基础知识累计ing~

0.值传递和引用传递

  • 值传递:是指在调用函数时将实际参数复制一份传递到函数中(会创建副本),这样在函数中如果对参数进行修改,将不会影响到实际参数。
  • 引用传递:是指在调用函数时将实际参数的地址传递到函数中(不会创建副本),那么在函数中对参数所进行的修改,将影响到实际参数。
  • java在基本数据类型传递时,是值传递;在引用数据类型传递时,并没有将地址进行传递,会复制一个新的地址,实际的参数时没有影响的,因此还是值传递。
  • C++中,是值传递。

1.时区的转换

package com.sanmina.test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class TestTime {
    
    
	public static void main(String[] args) throws ParseException {
    
    
		test1();
	}
	private static void test1() throws ParseException {
    
    
		//上海时间
		String UTC8_timeZone = "GMT+8:00";
		String UTC8_strTime = "20200114080000";
		//伦敦时间
		String UTC0_timeZone = "UTC";
		String UTC0_strTime = "20200114000000";
		
		//TODO 测试伦敦时间
		TimeEntity timeEntity_UTC8 = new TimeEntity(UTC8_strTime,UTC8_timeZone);
		TimeEntity timeEntity_UTC0 = new TimeEntity(UTC0_strTime,UTC0_timeZone);
		testTime(timeEntity_UTC0);
		testTime(timeEntity_UTC8);
		
	}

	public static void testTime(TimeEntity timeTEntity) throws ParseException {
    
    
		String timeZone = timeTEntity.getTimeZoneString();
		String strTime = timeTEntity.getTimeString();
		DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
		Date date = formatter.parse(strTime);
		System.out.println(date);
		long time = date.getTime();
		System.out.println(time);
	}

}

class TimeEntity{
    
    
	private String timeString;
	private String timeZoneString;
	public TimeEntity(String timeString, String timeZoneString) {
    
    
		super();
		this.timeString = timeString;
		this.timeZoneString = timeZoneString;
	}
	public String getTimeString() {
    
    
		return timeString;
	}
	public void setTimeString(String timeString) {
    
    
		this.timeString = timeString;
	}
	public String getTimeZoneString() {
    
    
		return timeZoneString;
	}
	public void setTimeZoneString(String timeZoneString) {
    
    
		this.timeZoneString = timeZoneString;
	}
}

说明:
1.只要是同一时间发生的事件,他们的时间戳相同,时间戳和时区无关。时间=时间戳+时区。
2.使用TimeZone.getTimeZone(timeZone)的时候,timeZone可以是Asia/Shanghai,或者UTC、GMT,或者GMT+8,或者GMT+8:00。尽量不要使用时区的缩写,如使用CST的时候,指的不是北京时间,而是默认美国时间。

2.RecursiveTask线程的使用

RecursiveTask<Object> task = new RecursiveTask<Object>() {
    
    
	private static final long serialVersionUID = 4945784102699878509L;
	@Override
	protected Object compute() {
    
    
		//执行有返回值的方法
		return function();
	}
};
ForkJoinPool pool = new ForkJoinPool(1); //线程池中线程数
pool.execute(task); // 执行线程,多个线程,多次调用该方法
Object object = task.join(); // 获取线程返回值

3.Java和Angular文件下载/上传(blob)

3.1.下载

3.1.1.java输出设置

public static void exportFile(HttpServletResponse response, String filename){
    
    
	response.setContentType("application/x-msdownload"); //输出格式
	response.setCharacterEncoding("UTF-8");
	response.setHeader("Content-Disposition", "attachment; filename=" + filename);
	OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
	toClient.write(fileStream);
	toClient.flush();
	toClient.close();
}

3.1.2.Angular请求下载

3.1.2.1.ts文件

import {
    
     saveAs } from 'file-saver';
import {
    
     HttpClient, HttpParams } from '@angular/common/http';
exportData(url: string){
    
    
	let params = new HttpParams(); //设置参数
	this.http.get(url, {
    
     params,responseType: 'blob' }).subscribe((data)=>{
    
    
		this.downloadFile(data,'text.csv');
	});
}
downloadFile(data, fileName) {
    
    
    const blob = new Blob([data], {
    
     type: 'application/vnd.ms-excel' });
    saveAs(blob, fileName);
}

4.关于Eclipse

4.1.打不开某一空间

删除workspace/.metadata.plugins/org.eclipse.e4.workbench/workbench.xmi文件即可;

4.2.设置是否跳转到debug页面

在这里插入图片描述

5.css细节问题

5.1.偏移

使用css3 transform:translate(X,Y)来偏移元素

使用css相对定位来偏移元素

.parent-class{
    
    
position: relative;
}
.my-class {
    
    
  position: absolute;
  left: 30px;
  top: 20px;
}

5.2.高度宽度在CSS中进行计算

height: calc(100% - 70px)

5.3. div内显示对角线

html

<div class="div-slash-line" ></div>

css

.div-slash-line{
    
    
	 height: 100px;
      width: 100px;
}
.div-slash-line:before{
    
    
      position: absolute;
      content:' ';
      height: 100%;
      width: 100%;
      background: linear-gradient(to top right,transparent,transparent 48%, #c8cbce , transparent 51%,transparent);
      left: 0;
      top: 0;
    }

5.4.div背景颜色渐变和突变

使用linear-gradient函数

5.4.1.渐变

background-image: linear-gradient(to right, red, green);

从左至右进行渐变,使用to right,还可以使用90deg(角度);
从右至左进行渐变,使用to left,还可以使用270deg(角度);
从上至下进行渐变,使用to bottom,还可以使用180deg(角度);
从下至上进行渐变,使用to top,还可以使用0deg(角度);
对角线渐变,使用to bottom right;

5.4.2.突变

在某个位置进行突变

background-image: linear-gradient(to right, red 20%, green 20%);

5.4.div按比例排成一行

html

<div class="item-row">
    <div class="left-item"></div>
    <div class="right-item"></div>
</div>

css

.item-row{
    
    
   display: flex;
    flex-direction: row;
    .right-item{
    
    
        flex: 1;
    }
    .right-item{
    
    
        flex: 1;
    }
}

6.JS知识积累

6.1.计算两个时间的天数差

function dateDay(start, end){
    
    
	let  startDate = Date.parse(start);
	let  endDate = Date.parse(end);
	let days=Math.ceil((endDate - startDate)/(1*24*60*60*1000));
}

6.2.数组位置向前或向后挪一位

changEnd2Frist(array: Array<any>) {
    
    
    let end = array[array.length-1];
    for (let index = array.length-1; index > 0; index--) {
    
    
      array[index] = array[index-1];
    }
    array[0]  = end;
    return array;
  }

  changFrist2End(array: Array<any>) {
    
    
    let frist = array[0];
    for (let index = 1; index < array.length; index++) {
    
    
      array[index-1] = array[index];
    }
    array[array.length-1]  = frist;
    return array;
  }

6.3.数组的排序

let backList = new Array<number>();
let backList = backList.sort((a,b)=>a-b);

6.4.使用document.querySelector时,将Element转为HTMLElement

let aaClass = document.querySelector('.aa')  as HTMLElement;

6.5.Angular点击其他地方,进行监控

<div class="item-bt-setting" #dropDown>
<div>
isShowDropDown: boolean;
@ViewChildren('dropDown') dropDown: QueryList<ElementRef>;

@HostListener('document:click', ['$event']) bodyClick(e) {
    
    
    if(getTrigger(this.dropDown)){
    
    
      this.isShowDropDown = false;
    }
    function getTrigger(queryList) {
    
    
      let flag=  true;
      (<HTMLElement[]>e.path).forEach(i=>{
    
    
        flag && queryList.forEach(el => {
    
    
          i.isEqualNode && i.isEqualNode(el.nativeElement) && (flag = false)
        });
      });
      return flag;
    }
  }

猜你喜欢

转载自blog.csdn.net/m0_37356874/article/details/104049236