Typescript之从零开始学习笔记,涵盖常用基本类型实操案例

本文主要是介绍Typescript之从零开始学习笔记,涵盖常用基本类型实操案例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Typescript之从零开始学习笔记

文章目录

  • Typescript之从零开始学习笔记
  • 1.环境搭建
    • 1. 安装node.js
    • 2. 安装typescript
    • 3. 使用tsc对ts进行编译
  • 2. TS 配置
    • 1 编译器配置
      • 1. 生成配置文件
      • 2. 自动编译
      • 3. 发生错误
  • 3. 基本语法
    • 1. 静态类型检查
    • 2.基本数据类型
    • 3. 数组类型
    • 4. any类型
    • 5. 函数的参数类型
    • 6.函数形参为对象类型
    • 7. 联合类型
    • 8 类型别名
    • 9. 类类型
    • 10.接口类型
    • 11. 类型断言
    • 12. 模板文字类型(Template Literal Types)
    • 13. TS特殊符号用法
  • 4. type与接口扩展字段类型区别

官网:https://www.typescriptlang.org/

官网文档:https://www.typescriptlang.org/docs/handbook/typescript-from-scratch.html

1.环境搭建

1. 安装node.js

官网下载直接安装即可(安装过程略)

2. 安装typescript

  1. 安装
# npm i -g typescript
C:\Users\infodba>npm i -g typescript
D:\Program Files\nodejs\node_global\tsc -> D:\Program Files\nodejs\node_global\node_modules\typescript\bin\tsc
D:\Program Files\nodejs\node_global\tsserver -> D:\Program Files\nodejs\node_global\node_modules\typescript\bin\tsserver
+ typescript@4.5.4
added 1 package from 1 contributor in 5.696s
  1. 查看typescript版本
# tsc -v
C:\Users\infodba>tsc -v
Version 4.5.4

3. 使用tsc对ts进行编译

tsc xxx.ts

2. TS 配置

1 编译器配置

1. 生成配置文件

# 1. 生成配置文件
tsc --init 
PS F:\2022WebStudy\yuan-ts-study\yuan-ts-study> tsc --init
Created a new tsconfig.json with:                                                                                  TS target: es2016module: commonjsstrict: trueesModuleInterop: trueskipLibCheck: trueforceConsistentCasingInFileNames: true
You can learn more at https://aka.ms/tsconfig.json
#tsc --init 命令执行完后默认会在当前目录下生成tsconfig.json文件
  • tsconfig.json配置文件内容如下:
{"compilerOptions": {/* Visit https://aka.ms/tsconfig.json to read more about this file *//* Projects */// "incremental": true,                              /* Enable incremental compilation */// "composite": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */// "tsBuildInfoFile": "./",                          /* Specify the folder for .tsbuildinfo incremental compilation files. */// "disableSourceOfProjectReferenceRedirect": true,  /* Disable preferring source files instead of declaration files when referencing composite projects */// "disableSolutionSearching": true,                 /* Opt a project out of multi-project reference checking when editing. */// "disableReferencedProjectLoad": true,             /* Reduce the number of projects loaded automatically by TypeScript. *//* Language and Environment 默认加载的是es2016也即es7,可以配置es3|es5|es6|es7等来兼容低版本浏览器的js支持 */"target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */// "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */// "jsx": "preserve",                                /* Specify what JSX code is generated. */// "experimentalDecorators": true,                   /* Enable experimental support for TC39 stage 2 draft decorators. */// "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */// "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */// "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */// "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */// "reactNamespace": "",                             /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */// "noLib": true,                                    /* Disable including any library files, including the default lib.d.ts. */// "useDefineForClassFields": true,                  /* Emit ECMAScript-standard-compliant class fields. *//* Modules */"module": "commonjs",                                /* Specify what module code is generated. */// "rootDir": "./",                                  /* Specify the root folder within your source files. *///指定ts源文件目录"rootDir":"./src",// "moduleResolution": "node",                       /* Specify how TypeScript looks up a file from a given module specifier. */// "baseUrl": "./",                                  /* Specify the base directory to resolve non-relative module names. */// "paths": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */// "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */// "typeRoots": [],                                  /* Specify multiple folders that act like `./node_modules/@types`. */// "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */// "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */// "resolveJsonModule": true,                        /* Enable importing .json files */// "noResolve": true,                                /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. *//* JavaScript Support */// "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */// "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */// "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. *//* Emit */// "declaration": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */// "declarationMap": true,                           /* Create sourcemaps for d.ts files. */// "emitDeclarationOnly": true,                      /* Only output d.ts files and not JavaScript files. */// "sourceMap": true,                                /* Create source map files for emitted JavaScript files. *///指定编译后的ts输出目录"outFile": "./dist",     // "outFile": "./",                                  /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */// "outDir": "./",                                   /* Specify an output folder for all emitted files. */// "removeComments": true,                           /* Disable emitting comments. */// "noEmit": true,                                   /* Disable emitting files from a compilation. */// "importHelpers": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */// "importsNotUsedAsValues": "remove",               /* Specify emit/checking behavior for imports that are only used for types */// "downlevelIteration": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */// "sourceRoot": "",                                 /* Specify the root path for debuggers to find the reference source code. */// "mapRoot": "",                                    /* Specify the location where debugger should locate map files instead of generated locations. */// "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */// "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */// "emitBOM": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */// "newLine": "crlf",                                /* Set the newline character for emitting files. */// "stripInternal": true,                            /* Disable emitting declarations that have `@internal` in their JSDoc comments. */// "noEmitHelpers": true,                            /* Disable generating custom helper functions like `__extends` in compiled output. */// "noEmitOnError": true,                            /* Disable emitting files if any type checking errors are reported. */// "preserveConstEnums": true,                       /* Disable erasing `const enum` declarations in generated code. */// "declarationDir": "./",                           /* Specify the output directory for generated declaration files. */// "preserveValueImports": true,                     /* Preserve unused imported values in the JavaScript output that would otherwise be removed. *//* Interop Constraints */// "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */// "allowSyntheticDefaultImports": true,             /* Allow 'import x from y' when a module doesn't have a default export. */"esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */// "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */"forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. *//* Type Checking 强制语法检查, */"strict": true,                                      /* Enable all strict type-checking options. */// "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied `any` type.. */// "strictNullChecks": true,                         /* When type checking, take into account `null` and `undefined`. */// "strictFunctionTypes": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */// "strictBindCallApply": true,                      /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */// "strictPropertyInitialization": true,             /* Check for class properties that are declared but not set in the constructor. */// "noImplicitThis": true,                           /* Enable error reporting when `this` is given the type `any`. */// "useUnknownInCatchVariables": true,               /* Type catch clause variables as 'unknown' instead of 'any'. */// "alwaysStrict": true,                             /* Ensure 'use strict' is always emitted. */// "noUnusedLocals": true,                           /* Enable error reporting when a local variables aren't read. */// "noUnusedParameters": true,                       /* Raise an error when a function parameter isn't read */// "exactOptionalPropertyTypes": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */// "noImplicitReturns": true,                        /* Enable error reporting for codepaths that do not explicitly return in a function. */// "noFallthroughCasesInSwitch": true,               /* Enable error reporting for fallthrough cases in switch statements. */// "noUncheckedIndexedAccess": true,                 /* Include 'undefined' in index signature results */// "noImplicitOverride": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */// "noPropertyAccessFromIndexSignature": true,       /* Enforces using indexed accessors for keys declared using an indexed type */// "allowUnusedLabels": true,                        /* Disable error reporting for unused labels. */// "allowUnreachableCode": true,                     /* Disable error reporting for unreachable code. *//* Completeness */// "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */"skipLibCheck": true                                 /* Skip type checking all .d.ts files. */}
}

2. 自动编译

在vscode工具中使用下面命令会开启自动编译监听,当xxx.ts编写完成后会自动触发编译器并编译成xxx.js文件

# 2. 自动编译
tsc --watch

3. 发生错误

如果ts中写了编译成js文件运行时异常的代码,ts在编译成js时默认会编译通过,而执行js时才会报错,如果想要再编译时直接抛出异常,则使用下面命令

# 3. 发出错误
tsc -onEmitOnError hello.ts

3. 基本语法

1. 静态类型检查

2static-typecheck.ts内容如下:

/**静态类型检查 */
const msg = "hello"
msg()
/**
编译会出现如下错误:
2.static-typecheck.ts:4:1 - error TS2349: This expression is not callable.Type 'String' has no call signatures.
4 msg()
*/

2.基本数据类型

3datatype-base.ts内容如下

/** 数据类型—基本数据类型*/
let age: number = 20;
let userName: string = 'jinshengyuan'
let gender: boolean = true
let person: any = { "name":"jinshengyuan","code":"001"
}
let date: Date = new Date()console.log(`${age} type is ${typeof age}`)
console.log(`${userName} type is ${typeof userName}`)
console.log(`${gender} type is ${typeof gender}`)
console.log(`${person} type is ${typeof person}`)
console.log(person.name,"=============="+person.code)
console.log(`${date} type is ${typeof date}`)
# 执行结果如下:
PS F:\2022WebStudy\yuan-ts-study\yuan-ts-study\dist> node .\3datatype-base.js
20 type is number
jinshengyuan type is string
true type is boolean
[object Object] type is object
jinshengyuan ==============001
Sat Jan 15 2022 16:18:50 GMT+0800 (中国标准时间) type is object

3. 数组类型

数组定义有两种方式:

  • 普通方式:let v:dataType [] = []
  • 泛型方式:let v:Array = []
/** * 数据类型-数组* 有两种方式:* 1.普通方式* let v:dataType [] = []* 2.泛型方式* let v:Array<dataType> = []*  *///1. variable:dataType []
let numArr: number[] = [1, 3, 34, 904]numArr.forEach(num => {console.log(num);
});
console.log("=======================")
// 2.泛型方式
let strArr: Array<string> = ['a', 'b', 'c']strArr.forEach(str => {console.log(str)
})
/*** 执行结果如下:1
3
34
34
=======================
a
b
c
*/

4. any类型

不希望某个特定值导致类型检查错误时可以使用any类型

/** 数据类型-any */
let obj: any = {userName: 'jinshengyuan',gender: true,age: 27,birthday: 'xxxx-xx-xx'
}console.log(obj.userName)
//jinshengyuan/** 数据类型-any */
let obj: any = {userName: 'jinshengyuan',gender: true,age: 27,birthday: 'xxxx-xx-xx'
}console.log(obj.userName)
//jinshengyuan//objOne后面不跟数据类型,ts会根据属性的值自动推断具体的类型
let objOne = {userName: 'jinshengyuan',gender: true,age: 27,birthday: 'xxxx-xx-xx'
}

5. 函数的参数类型

6datatype-funcation.ts如下

/** 数据类型-函数形参类型定义 */
// 1.函数形参指定类型
let f1 = (name: string, age: number) => {console.log(`${name}已经${age}岁了`);}
f1('jinshengyuan', 22)//2.函数无返回值类型指定
function f2(a: number, b: number): void {console.log(`${a}+${b}=${a + b}`)
}
f2(2, 33)//3.函数有返回值类型指定
function f3(a: number, b: number): number {return a + b;
}
let f3_result = f3(3, 4)
console.log("f3_result:" + f3_result)//4.类型推断const names = ['zhangsan', 'lisi', '王五']
names.forEach(function (name) {//这里虽然name没有显示的指定类型,但ts将names中每一个元素自动推断为string类型,就可以直接调用string类型的方法console.log(name.toUpperCase())
})
//或使用箭头函数
names.forEach(name => {console.log(name.toUpperCase())
})

6.函数形参为对象类型

  1. 函数形参中是一个对象,则对象的每个属性的类型后用分割;

  2. 若对象参数中某个属性的值可选,则属性后需要跟表示此属性值可指定也可不指定,否则必须指定值

  3. 若对象参数中某个属性的值可选且为string类型,则此时调用spring类型的方式时必须也跟上?,否则ts编译报错

/**数据类型-对象类型指定 *///1.函数形参中是一个对象,则对象的每个属性的类型后用,或;分割
// , 分割
function myAxisA(pt: { x: number, y: number }) {console.log("坐标A:" + pt.x, pt.y)
}// ; 分割
function myAxisB(pt: { x: number; y: number }) {console.log("坐标B:" + pt.x, pt.y)
}const pointDataA = {x: 22,y: 33
}
myAxisA(pointDataA);const pointDataB = {x: 100,y: 300
}
myAxisB(pointDataB);/***
坐标A:22 33
坐标B:100 300*///2.若对象参数中某个属性的值可选,则属性后需要跟`?`表示此属性值可指定也可不指定,否则必须指定值
function printName(person: { name: string, age?: number }) {console.log(person.name)
}
//不传age属性也能编译通过及正常打印
printName({name: 'jinshengyuan'
})
//传age属性能编译通过及正常打印
printName({name: 'jinshengyuan',age: 33
})//3. 若对象参数中某个属性的值可选且为string类型,则此时调用spring类型的方式时必须也跟上`?`,否则ts编译报错
function printName1(obj: { name: string, code?: string }) {//新式优雅写法,在对象的属性名后加入`?`console.log(obj.code?.toUpperCase())//原始写法if (obj.code != undefined) {console.log(obj.code.toUpperCase())}
}
printName1({name: '张三',code: 'zangSan'
})

7. 联合类型

联合类型中间使用管道符|进行分割

/** 数据类型-联合类型  let v:numver|string|boolean */
// 联合类型中间使用管道符`|`进行分割
//1.printInfo函数的id属性类型可以为数值、字符串、数组三种类型
function printInfo(id: number | string | Array<string>) {console.log("只为:" + id + "类型为:" + typeof id)
}
printInfo(222)
printInfo('aaa')
printInfo(['a', 'b', 'c'])
/*
222类型为:number
aaa类型为:string
a,b,c类型为:object
*///2.如果v传入的是数组,则在后面追加z,否则输出hello
function hello(v: string[] | string) {if (Array.isArray(v)) {console.log(v.join("z"))} else {console.log("hello")}
}
hello(['x', 'y'])
hello("hi")
/*
xzy
hello
*/
//3. 多种类型共有的方法,如数字素组与字符窜都有截取元素的方法`slice()`
function publicM(x: number[] | string) {//截取前三个元素console.log(x.slice(0, 3))
}publicM([1, 3, 34, 46, 4, 67, 90, 7, 5])
publicM('helloword')
/*
[ 1, 3, 34 ]
hel
*/

8 类型别名

  1. ts中定义参数类型时都是变量名在前而数据类型在后,类型别名就是将类型放在变量名称前边,类似与Java中声明变量的方式

  2. 类型别名使用 type关键字指定,且给变量赋值的是具体的数据类型,如type id = string|number,可以是时任何类型;

  3. type 关键字后边如果如果是一个对象类型,则对象的属性指定类型有三种写法,区别在于属性之间用 ,|;|\n进行分割

  4. 作用目的:可以时同一类型多次重复使用

/** 数据类型-类型别名 语法: type x = string|number */
// 类型别名为pointType的类型为string 或 number
type pointType = string | number// 类型为 point 的类型是对象,对象中的属性类型=别名为pointType的类型  
//[注意:下面指定类型别名的方式等价,即:point=pointA=pointB,区别在于 `,`|`;`|`\n`]
//1.属性指定用`,`隔开
type point = {x: pointType,y: pointType
}
// 2. 属性之间用`;`隔开
type pointA = {x: pointType;y: pointType
}
// 3. 属性之间换行,写在一行是不行的
type pointB = {x: pointTypey: pointType
}function getPoint(pt: point) {console.log("坐标:" + pt.x + "," + pt.y)
}
getPoint({x: '220',y: 333
})getPoint({x: 100,y: 200
})
/*
坐标:220,333
坐标:100,200
*/

9. 类类型

class Demo {a: number;b: number;constructor(a: number, b: number) {this.a = a;this.b = b;}getDemo() {return `(${this.a}, ${this.b})`;}
}const demo = new Point(5, 7);
demo.getDemo()   // (5, 7)

10.接口类型

  1. 接口以interface关键字开头,且变量名大写;
  2. 接口可以继承接口
/** 数据类型-接口 */
//1. 定义一个动物接口
interface Animals {name: string;age: number;
}
//dog函数形参指定为接口类型
function dog(dog: Animals) {console.log(dog.name, dog.age);
}
dog({ name: '小狗', age: 4 })//2. 接口继承接口类型,Ant继承Animals
interface Ant extends Animals {like: string;day: number;
}function ant(ant: Ant) {console.log(`小蚂蚁${ant.name} ${ant.age}岁了,${ant.like}${ant.day}天搬家一次`)
}
// 继承自父接口的属性必须指定全,否则编译不通过
ant({ name: '土豆', age: 4, like: "喜欢", day: 5 })// 3. 向现有类型中添加字段,可以多次声明后直接将属性合并到一起
interface MyInfo {name: string;
}
interface MyInfo {age: number;
}
interface MyInfo {gender: boolean;
}const myinfo: MyInfo = {name: "张三",age: 33,gender: true
}
//===========type 扩展字段类型==============
// 1. 声明对象类型
type Animal = {name: string;
}
//2.扩展字段类型
type Tigger = Animal & {hobby: string
}
const tigger: Tigger = {name: "老虎",hobby: "吃肉"
}//3. type声明的类型对象是不可更改的,所以不能添加类型字段

11. 类型断言

语法:就是在获得的某个DOM元素后,在元素前面加泛型或在元素之后通过as 关键字指定元素的具体类型

有两种写法:

  • const myCanvas = document.getElementById(“main_canvas”) as HTMLCanvasElement
  • const myCanvas = document.getElementById(“main_canvas”)
/** 数据类型-类型断言 */
const myCanvas1 = document.getElementById("main_canvas") as HTMLCanvasElement
const myCanvas2 = <HTMLCanvasElement>document.getElementById("main_canvas") 
// 
const x = ('hello' as any) as string
// unknow 未知类型
const y = ('22' as unknown) as number

12. 模板文字类型(Template Literal Types)

13. TS特殊符号用法

  1. 属性或参数中使用 ?:表示该属性或参数为可选项
  2. 属性或参数中使用 !:表示强制解析(告诉typescript编译器,这里一定有值),常用于vue-decorator中的@Prop
  3. 变量后使用 !:表示类型推断排除null、undefined

4. type与接口扩展字段类型区别

相同点:

  1. 都可以定义对象属性的类型
  2. 都可以扩展字段类型,type 通过 & 符合扩展字段类型,interface通过extends关键字来扩展字段类型

不同点:

接口支持向已有类型对象中添加属性,而type不支持

  1. 扩展字段方式不同
//1. 接口-通过`extends`关键字继承父接口来扩展字段
interface Animals {name: string;age: number;
}
//接口继承接口类型,Ant继承Animals
interface Ant extends Animals {like: string;day: number;
}
//dog函数形参指定为接口类型
function dog(dog: Animals) {console.log(dog.name, dog.age);
}
dog({ name: '小狗', age: 4 })//2. type-通过 `&` 符合来扩展字段
type Animal = {name: string;
}
// type 扩展字段类型
type Tigger = Animal & {hobby: string
}
const tigger: Tigger = {name: "老虎",hobby: "吃肉"
}
  1. 向现有的对象类型中添加字段
  • 接口通过多次声明同名的接口方式来添加字段,使用时会将属性合并到一起;
  • type一旦声明了字段类型是不可更改的,所以不支持添加字段
// 1.interface-向现有类型中添加字段,可以多次声明同名的接口后直接将属性合并到一起
interface MyInfo {name: string;
}
interface MyInfo {age: number;
}
interface MyInfo {gender: boolean;
}const myinfo: MyInfo = {name: "张三",age: 33,gender: true
}
// 2.type-不支持向现有类型对象中添加字段

这篇关于Typescript之从零开始学习笔记,涵盖常用基本类型实操案例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/666674

相关文章

使用Navicat工具比对两个数据库所有表结构的差异案例详解

《使用Navicat工具比对两个数据库所有表结构的差异案例详解》:本文主要介绍如何使用Navicat工具对比两个数据库test_old和test_new,并生成相应的DDLSQL语句,以便将te... 目录概要案例一、如图两个数据库test_old和test_new进行比较:二、开始比较总结概要公司存在多

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

Python中操作Redis的常用方法小结

《Python中操作Redis的常用方法小结》这篇文章主要为大家详细介绍了Python中操作Redis的常用方法,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解一下... 目录安装Redis开启、关闭Redisredis数据结构redis-cli操作安装redis-py数据库连接和释放增

Redis的Zset类型及相关命令详细讲解

《Redis的Zset类型及相关命令详细讲解》:本文主要介绍Redis的Zset类型及相关命令的相关资料,有序集合Zset是一种Redis数据结构,它类似于集合Set,但每个元素都有一个关联的分数... 目录Zset简介ZADDZCARDZCOUNTZRANGEZREVRANGEZRANGEBYSCOREZ

C++中使用vector存储并遍历数据的基本步骤

《C++中使用vector存储并遍历数据的基本步骤》C++标准模板库(STL)提供了多种容器类型,包括顺序容器、关联容器、无序关联容器和容器适配器,每种容器都有其特定的用途和特性,:本文主要介绍C... 目录(1)容器及简要描述‌php顺序容器‌‌关联容器‌‌无序关联容器‌(基于哈希表):‌容器适配器‌:(

一文详解Python中数据清洗与处理的常用方法

《一文详解Python中数据清洗与处理的常用方法》在数据处理与分析过程中,缺失值、重复值、异常值等问题是常见的挑战,本文总结了多种数据清洗与处理方法,文中的示例代码简洁易懂,有需要的小伙伴可以参考下... 目录缺失值处理重复值处理异常值处理数据类型转换文本清洗数据分组统计数据分箱数据标准化在数据处理与分析过

Java中Object类的常用方法小结

《Java中Object类的常用方法小结》JavaObject类是所有类的父类,位于java.lang包中,本文为大家整理了一些Object类的常用方法,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. public boolean equals(Object obj)2. public int ha

SpringBoot实现动态插拔的AOP的完整案例

《SpringBoot实现动态插拔的AOP的完整案例》在现代软件开发中,面向切面编程(AOP)是一种非常重要的技术,能够有效实现日志记录、安全控制、性能监控等横切关注点的分离,在传统的AOP实现中,切... 目录引言一、AOP 概述1.1 什么是 AOP1.2 AOP 的典型应用场景1.3 为什么需要动态插

Golang操作DuckDB实战案例分享

《Golang操作DuckDB实战案例分享》DuckDB是一个嵌入式SQL数据库引擎,它与众所周知的SQLite非常相似,但它是为olap风格的工作负载设计的,DuckDB支持各种数据类型和SQL特性... 目录DuckDB的主要优点环境准备初始化表和数据查询单行或多行错误处理和事务完整代码最后总结Duck

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu