Mybatis头文件
Mybatis Config和Mybatis Mapper头文件,一直奇怪这么常用的配置文件模板,idea至今还不支持,每次都是自己手动添加文件模板
Mybatis Config
1 2 3 4 5 6
| <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> </configuration>
|
Mybatis Mapper
1 2 3 4 5
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper> </mapper>
|
Git清除提交记录
思路是创建一个新分支提交,然后将会旧分支删除。
创建一个临时分支tmp
1
| git checkout --orphan tmp
|
该命令会创建一个名为tmp的分支,并且该分支会包含父分支的所有文件。但新的分支不会指向任何以前的提交,也就是没有提交历史,如果你提交当前内容,那么这次提交就是这个分支的首次提交。如果不提交东西,这个分支实际上没有创建。
最后删除原分支,将tmp分支重命名为原分支名称即可。
MySQL创建时间和更新时间设置
使用MySQL内置函数,数据创建时自动设置创建时间,更新时自动设置更新时间,DateGrip没有或者选项,所以每次是手动添加这两个字段,希望以后会更新这个功能。
1 2 3 4 5
| ALTER TABLE 表名 ADD ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' );
|
MySQL不存在则插入,存在则忽略或者更新
建立name唯一索引,根据name是否存在,执行忽略或者更新
表结构如下:
1 2 3 4 5 6 7 8 9
| create table demo ( id bigint auto_increment primary key, name varchar(16) default '' not null, age int default 0 not null, constraint demo_name_uindex unique (name) );
|
不存在则插入,存在则忽略
避免重复插入
1 2
| INSERT IGNORE INTO demo(name, age) VALUES ('Jonsson', 19);
|
不存在则插入,存在则更新
ON DUPLICATE KEY UPDATE
如果插入的数据会导致UNIQUE索引或PRIMARY KEY发生冲突/重复,则执行UPDATE语句
1 2
| INSERT INTO demo(name, age) VALUES ('Jonsson', 19) ON DUPLICATE KEY UPDATE age = VALUES(age);
|
REPLACE INTO
如果插入的数据会导致UNIQUE索引或PRIMARY KEY发生冲突/重复,则先删除旧数据再插入最新的数据
1
| REPLACE INTO demo(name, age) VALUES('Jonsson', 19);
|
1 2 3 4 5
| <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.16</version> </dependency>
|
参考文档:https://doc.hutool.cn/pages/Date/#%E4%BB%8B%E7%BB%8D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil;
public class Main { public static void main(String[] args) { System.out.println("当前时间字符串 yyyy-MM-dd HH:mm:ss " + DateUtil.now()); System.out.println("当前日期字符串 yyyy-MM-dd " + DateUtil.today()); System.out.println("当前时间 " + DateUtil.date()); System.out.println("当前时间格式化 yyyy-MM-dd HH:mm:ss " + DateUtil.format(DateUtil.date(), DatePattern.NORM_DATETIME_PATTERN)); System.out.println("当天开始时间 " + DateUtil.beginOfDay(DateUtil.date())); System.out.println("当天结束时间 " + DateUtil.endOfDay(DateUtil.date())); System.out.println("字符串转Date " + DateUtil.parse("2023-11-15 15:48:22", DatePattern.NORM_DATETIME_PATTERN)); System.out.println("时间比较 " + DateUtil.compare(DateUtil.date(), DateUtil.beginOfDay(DateUtil.date()))); } }
|
Axios网络请求库封装
TypeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import axios, {AxiosResponse, InternalAxiosRequestConfig} from "axios";
const service = axios.create({ baseURL: "/api", timeout: 50000, headers: {"Content-Type": "application/json;charset=utf-8"}, });
service.interceptors.request.use( (config: InternalAxiosRequestConfig) => { config.headers.Authorization = "Bearer xxxxx"; return config; }, (error: any) => { return Promise.reject(error); } );
service.interceptors.response.use( (response: AxiosResponse) => { const {code, msg} = response.data; if (+code === 20000) { return response.data; } if (response.data instanceof ArrayBuffer) { return response; } console.log(msg || "系统出错") return Promise.reject(new Error(msg || "Error")); }, (error: any) => { if (error.response.data) { const {msg} = error.response.data; console.log(msg || "系统出错") } return Promise.reject(new Error(msg || "Error")); } );
export default service;
|
去除页面上下左右边距
1 2 3 4 5 6
| html, body { height: 100%; margin: 0; padding: 0; box-sizing: border-box; }
|