【转载】sql-builder介绍
原文链接:sql-builder介绍
关于sql-builder
sql-builder尝试使用java对象,通过类SQL
的拼接方式,动态快速的生成SQL。它可作为稍后的开源项目ibit-mybatis的核心类库。
sql-builder提供了对象拼接的构造类Sql
和字符串拼接的构造类StringSql
。
Sql构造示例
详细测试用例查看:tech.ibit.sqlbuilder.SqlTest
select
// 传入列
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE);
assertParamsEquals("SELECT u.user_id, u.name FROM user u", sql.getSqlParams());
// 支持聚合函数
sql = new Sql().select(Arrays.asList(new SumColumn(UserProperties.userId, "user_id_sum")
, new AvgColumn(UserProperties.userId, "user_id_avg")))
.from(UserProperties.TABLE).groupBy(UserProperties.userId);
assertParamsEquals("SELECT SUM(u.user_id) AS user_id_sum, AVG(u.user_id) AS user_id_avg FROM user u GROUP BY u.user_id"
, sql.getSqlParams());
selectDistinct
Sql sql = new Sql()
.selectDistinct(UserProperties.email)
.from(UserProperties.TABLE);
assertParamsEquals("SELECT DISTINCT u.email FROM user u", Collections.emptyList(), sql.getSqlParams());
selectPo(解析传入类)
Sql sql = new Sql()
.selectPo(UserPo.class)
.from(UserProperties.TABLE);
assertParamsEquals("SELECT u.user_id, u.login_id, u.email, u.mobile_phone, u.type FROM user u",
Collections.emptyList(), sql.getSqlParams());
selectDistinctPo
Sql sql = new Sql()
.selectDistinctPo(UserPo.class)
.from(UserProperties.TABLE).limit(1000);
assertParamsEquals("SELECT DISTINCT u.user_id, u.login_id, u.email, u.mobile_phone, u.type FROM user u LIMIT ?, ?",
Arrays.asList("$start", 0, "$limit", 1000), sql.getSqlParams());
count
Sql sql = new Sql()
.count()
.from(UserProperties.TABLE);
assertParamsEquals("SELECT COUNT(*) FROM user u", sql.getSqlParams());
countDistinct
// 传入单列
Sql sql = new Sql()
.countDistinct(UserProperties.userId)
.from(UserProperties.TABLE);
assertParamsEquals("SELECT COUNT(DISTINCT u.user_id) FROM user u", sql.getSqlParams());
// 传入多列
sql = new Sql()
.countDistinct(Arrays.asList(UserProperties.name, UserProperties.email))
.from(UserProperties.TABLE);
assertParamsEquals("SELECT COUNT(DISTINCT u.name, u.email) FROM user u", sql.getSqlParams());
deleteFrom
// 删除操作必须包含where语句,不然这个操作很危险
Sql sql = new Sql().deleteFrom(UserProperties.TABLE);
thrown.expect(RuntimeException.class);
thrown.expectMessage("Where cannot be empty when do deleting!");
sql.getSqlParams();
// 正常删除
Sql sql = new Sql()
.deleteFrom(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("DELETE FROM user WHERE user_id = ?",
Arrays.asList("user_id", 1), sql.getSqlParams());
deleteTableFrom(支持别名)
// 正常删除
Sql sql = new Sql()
.deleteTableFrom(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("DELETE u.* FROM user u WHERE u.user_id = ?",
Arrays.asList("u.user_id", 1), sql.getSqlParams());
// 支持join的删除
sql = new Sql()
.deleteTableFrom(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1))
.leftJoinOn(OrganizationProperties.TABLE, Arrays.asList(UserProperties.orgId, OrganizationProperties.orgId));
assertParamsEquals("DELETE u.* FROM user u LEFT JOIN organization o ON u.org_id = o.org_id WHERE u.user_id = ?",
Arrays.asList("u.user_id", 1), sql.getSqlParams());
update
// update操作必须包含where语句,不然这操作很危险
Sql sql = new Sql()
.update(UserProperties.TABLE)
.set(new ColumnValue(UserProperties.name, "IBIT"));
thrown.expect(RuntimeException.class);
thrown.expectMessage("Where cannot be empty when do updating!");
sql.getSqlParams();
// 正常删除
sql = new Sql()
.update(UserProperties.TABLE)
.set(new ColumnValue(UserProperties.name, "IBIT"))
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("UPDATE user u SET u.name = ? WHERE u.user_id = ?",
Arrays.asList("u.name", "IBIT", "u.user_id", 1), sql.getSqlParams());
insertInto & values
Sql sql = new Sql()
.insertInto(UserProperties.TABLE)
.values(Arrays.asList(new ColumnValue(UserProperties.name, "IBIT")
, new ColumnValue(UserProperties.loginId, "188")
, new ColumnValue(UserProperties.avatarId, null)));
assertParamsEquals("INSERT INTO user(name, login_id, avatar_id) VALUES(?, ?, ?)",
Arrays.asList("name", "IBIT", "login_id", "188", "avatar_id", null), sql.getSqlParams());
set
Sql sql = new Sql()
.update(UserProperties.TABLE)
.set(Arrays.asList(new ColumnValue(UserProperties.name, "IBIT")
, new ColumnValue(UserProperties.loginId, "188")
, new ColumnValue(UserProperties.avatarId, null)))
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("UPDATE user u SET u.name = ?, u.login_id = ?, u.avatar_id = ? WHERE u.user_id = ?",
Arrays.asList("u.name", "IBIT", "u.login_id", "188", "u.avatar_id", null, "u.user_id", 1), sql.getSqlParams());
increaseSet(字段增长)
Sql sql = new Sql()
.update(UserProperties.TABLE)
.increaseSet(new ColumnValue(UserProperties.loginTimes, 2))
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("UPDATE user u SET u.login_times = u.login_times + ? WHERE u.user_id = ?",
Arrays.asList("u.login_times", 2, "u.user_id", 1), sql.getSqlParams());
decreaseSet(字段递减)
Sql sql = new Sql()
.update(UserProperties.TABLE)
.decreaseSet(new ColumnValue(UserProperties.loginTimes, 2))
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.userId, 1));
assertParamsEquals("UPDATE user u SET u.login_times = u.login_times - ? WHERE u.user_id = ?"
, Arrays.asList("u.login_times", 2, "u.user_id", 1), sql.getSqlParams());
from
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.from(ProjectProperties.TABLE)
.andWhere(CriteriaItemMaker.equalsTo(UserProperties.currentProjectId, ProjectProperties.projectId));
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u, project p WHERE u.current_project_id = p.project_id",
Collections.emptyList(), sql.getSqlParams());
sql = new Sql()
.select(Arrays.asList(ProjectProperties.projectId, ProjectProperties.name))
.from(ProjectProperties.TABLE);
assertParamsEquals("SELECT p.project_id, p.name FROM project p",
Collections.emptyList(), sql.getSqlParams());
joinOn(left, right, full, inner)
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.joinOn(ProjectProperties.TABLE, Arrays.asList(UserProperties.currentProjectId, ProjectProperties.projectId));
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u JOIN sz_project p ON u.current_project_id = p.project_id", sql.getSqlParams());
// left join on
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.leftJoinOn(ProjectProperties.TABLE, Arrays.asList(UserProperties.currentProjectId, ProjectProperties.projectId));
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN sz_project p ON u.current_project_id = p.project_id", sql.getSqlParams());
// 省略其他join
complexJoinOn(支持on后面增加条件,left, right, full, inner)
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.complexLeftJoinOn(ProjectProperties.TABLE, Collections.singletonList(CriteriaItemMaker.equalsTo(UserProperties.currentProjectId, ProjectProperties.projectId)));
SqlParams sqlParams = sql.getSqlParams();
assertEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN project p ON u.current_project_id = p.project_id", sqlParams.getSql());
assertTrue(sqlParams.getParamDetails().isEmpty());
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.complexLeftJoinOn(ProjectProperties.TABLE, Arrays.asList(
CriteriaItemMaker.equalsTo(UserProperties.currentProjectId, ProjectProperties.projectId),
CriteriaItemMaker.like(ProjectProperties.name, "小%")));
sqlParams = sql.getSqlParams();
assertEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN project p "
+ "ON u.current_project_id = p.project_id AND p.name LIKE ?", sqlParams.getSql());
assertList(sqlParams.getParamDetails(), 1, Arrays.asList("p.name", "小%"));
// 省略其他join
where(支持构造复杂的where语句)
List<CriteriaItem> xiaoLikeItems = Arrays.asList(
CriteriaItemMaker.like(UserProperties.name, "小%"),
CriteriaItemMaker.like(UserProperties.email, "xiao%"));
CriteriaItem userIdItem = CriteriaItemMaker.greaterThan(UserProperties.userId, 100);
CriteriaItem type1Item = CriteriaItemMaker.equalsTo(UserProperties.type, 1);
CriteriaItem type2Item = CriteriaItemMaker.equalsTo(UserProperties.type, 2);
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.where(Criteria.ands(Arrays.asList(Criteria.ors(xiaoLikeItems), userIdItem)));
SqlParams sqlParams = sql.getSqlParams();
assertList(sqlParams.getParams(), 3, Arrays.asList("小%", "xiao%", 100));
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.where(
Criteria.ands(
Arrays.asList(Criteria.ors(xiaoLikeItems),
Criteria.ors(Collections.singletonList(userIdItem)))
)
);
sqlParams = sql.getSqlParams();
assertParamsEquals("SELECT u.user_id, u.name FROM user u WHERE (u.name LIKE ? OR u.email LIKE ?) AND u.user_id > ?",
Arrays.asList("小%", "xiao%", 100), sqlParams);
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.where(
Criteria.ors(Arrays.asList(
Criteria.ands(
Arrays.asList(Criteria.ands(
Arrays.asList(Criteria.ors(xiaoLikeItems),
Criteria.ors(Collections.singletonList(userIdItem)))),
type1Item)
), type2Item))
);
sqlParams = sql.getSqlParams();
assertParamsEquals("SELECT u.user_id, u.name FROM user u WHERE (((u.name LIKE ? OR u.email LIKE ?) AND u.user_id > ?) AND u.type = ?) OR u.type = ?",
Arrays.asList("小%", "xiao%", 100, 1, 2), sqlParams);
andWhere & orWhere & flag(支持标记位条件)
// and
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.andWhere(Criteria.ors(
Arrays.asList(CriteriaItemMaker.like(UserProperties.name, "小%"), CriteriaItemMaker.like(UserProperties.email, "xiao%"))))
.limit(1);
assertParamsEquals("SELECT u.user_id, u.name FROM user u WHERE (u.name LIKE ? OR u.email LIKE ?) LIMIT ?, ?"
, Arrays.asList("u.name", "小%", "u.email", "xiao%", "$start", 0, "$limit", 1), sql.getSqlParams());
// or
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.orWhere(Criteria.ands(
Arrays.asList(CriteriaItemMaker.like(UserProperties.name, "小%"), CriteriaItemMaker.like(UserProperties.email, "xiao%"))))
.orWhere(CriteriaItemMaker.equalsTo(UserProperties.type, 1))
.limit(1);
assertParamsEquals("SELECT u.user_id, u.name FROM user u WHERE (u.name LIKE ? AND u.email LIKE ?) OR u.type = ? LIMIT ?, ?",
Arrays.asList("u.name", "小%", "u.email", "xiao%", "u.type", 1, "$start", 0, "$limit", 1), sql.getSqlParams());
// CriteriaItemMaker支持构造flag有:containsNoneFlags, containsAllFlags, containsAnyFlags
sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name))
.from(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.containsNoneFlags(UserProperties.userId, 1));
assertParamsEquals("SELECT u.user_id, u.name FROM user u WHERE u.user_id & ? = 0",
Arrays.asList("u.user_id", 1), sql.getSqlParams());
orderBy
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.leftJoinOn(ProjectProperties.TABLE, Arrays.asList(UserProperties.currentProjectId, ProjectProperties.projectId))
.orderBy(Arrays.asList(new OrderBy(ProjectProperties.projectId), new OrderBy(UserProperties.userId, true)))
.limit(1000);
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN project p ON u.current_project_id = p.project_id ORDER BY p.project_id, u.user_id DESC LIMIT ?, ?",
Arrays.asList("$start", 0, "$limit", 1000), sql.getSqlParams());
customerOrderBy(自定义排序:mysql语法)
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.leftJoinOn(ProjectProperties.TABLE, Arrays.asList(UserProperties.currentProjectId, ProjectProperties.projectId))
.orderBy(Arrays.asList(new OrderBy(ProjectProperties.projectId), new CustomOrderBy(UserProperties.userId, Arrays.asList(1, 2, 3), true)));
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN project p ON u.current_project_id = p.project_id ORDER BY p.project_id"
+ ", FIELD(u.user_id, ?, ?, ?) DESC", Arrays.asList("u.user_id", 1, "u.user_id", 2, "u.user_id", 3), sql.getSqlParams());
nameOrderBy(自定义字段排序)
Sql sql = new Sql()
.select(
Arrays.asList(
new MinColumn(UserProperties.age, "min_age"),
new MaxColumn(UserProperties.age, "max_age"),
UserProperties.gender
))
.from(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.greaterThanOrEqualsTo(UserProperties.age, 0))
.groupBy(UserProperties.gender)
.having(Having.and(HavingItemMaker.greaterThanOrEqualsTo("min_age", 1)))
.orderBy(Arrays.asList(
new OrderBy(UserProperties.gender),
new NameOrderBy("min_age", true)));
assertParamsEquals("SELECT MIN(u.age) AS min_age, MAX(u.age) AS max_age, u.gender FROM user u WHERE u.age >= ? " +
"GROUP BY u.gender HAVING min_age >= ? ORDER BY u.gender, min_age DESC", Arrays.asList("u.age", 0, "min_age", 1), sql.getSqlParams());
groupBy & having
Sql sql = new Sql()
.select(
Arrays.asList(
new MinColumn(UserProperties.age, "min_age"),
new MaxColumn(UserProperties.age, "max_age"),
UserProperties.gender
))
.from(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.greaterThanOrEqualsTo(UserProperties.age, 0))
.groupBy(UserProperties.gender)
.having(Having.and(HavingItemMaker.greaterThanOrEqualsTo("min_age", 1)));
assertParamsEquals("SELECT MIN(u.age) AS min_age, MAX(u.age) AS max_age, u.gender FROM user u WHERE u.age >= ? GROUP BY u.gender HAVING min_age >= ?",
Arrays.asList("u.age", 0, "min_age", 1), sql.getSqlParams());
andHaving & orHaving
// andHaving
sql = new Sql()
.select(
Arrays.asList(
new MinColumn(UserProperties.age, "min_age"),
new MaxColumn(UserProperties.age, "max_age"),
UserProperties.gender
))
.from(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.greaterThanOrEqualsTo(UserProperties.age, 0))
.groupBy(UserProperties.gender)
.andHaving(
Having.ors(
Arrays.asList(
HavingItemMaker.greaterThanOrEqualsTo("min_age", 1),
HavingItemMaker.greaterThanOrEqualsTo("max_age", 2))
))
.andHaving(
Having.ors(
Arrays.asList(
HavingItemMaker.greaterThanOrEqualsTo("min_age", 3),
HavingItemMaker.greaterThanOrEqualsTo("max_age", 4)
))
);
assertParamsEquals("SELECT MIN(u.age) AS min_age, MAX(u.age) AS max_age, u.gender FROM user u WHERE u.age >= ? GROUP BY u.gender "
+ "HAVING (min_age >= ? OR max_age >= ?) AND (min_age >= ? OR max_age >= ?)",
Arrays.asList("u.age", 0, "min_age", 1, "max_age", 2, "min_age", 3, "max_age", 4), sql.getSqlParams());
// orHaving
sql = new Sql()
.select(
Arrays.asList(
new MinColumn(UserProperties.age, "min_age"),
new MaxColumn(UserProperties.age, "max_age"),
UserProperties.gender
))
.from(UserProperties.TABLE)
.andWhere(CriteriaItemMaker.greaterThanOrEqualsTo(UserProperties.age, 0))
.groupBy(UserProperties.gender)
.orHaving(
Having.ands(
Arrays.asList(
HavingItemMaker.greaterThanOrEqualsTo("min_age", 1),
HavingItemMaker.greaterThanOrEqualsTo("max_age", 2))
))
.orHaving(
Having.ands(
Arrays.asList(
HavingItemMaker.greaterThanOrEqualsTo("min_age", 3),
HavingItemMaker.greaterThanOrEqualsTo("max_age", 4)
))
);
assertParamsEquals("SELECT MIN(u.age) AS min_age, MAX(u.age) AS max_age, u.gender FROM user u WHERE u.age >= ? GROUP BY u.gender "
+ "HAVING (min_age >= ? AND max_age >= ?) OR (min_age >= ? AND max_age >= ?)",
Arrays.asList("u.age", 0, "min_age", 1, "max_age", 2, "min_age", 3, "max_age", 4), sql.getSqlParams());
limit
Sql sql = new Sql()
.select(Arrays.asList(UserProperties.userId, UserProperties.name, ProjectProperties.name))
.from(UserProperties.TABLE)
.leftJoinOn(ProjectProperties.TABLE, Arrays.asList(UserProperties.currentProjectId, ProjectProperties.projectId))
.orderBy(Arrays.asList(new OrderBy(ProjectProperties.projectId), new OrderBy(UserProperties.userId, true)))
.limit(10);
assertParamsEquals("SELECT u.user_id, u.name, p.name FROM user u LEFT JOIN project p ON u.current_project_id = p.project_id ORDER BY p.project_id"
+ ", u.user_id DESC LIMIT ?, ?", Arrays.asList("$start", 0, "$limit", 10), sql.getSqlParams());
StringSql构造
构造方式与Sql相似,可以查看:tech.ibit.sqlbuilder.StringSqlTest
相关maven依赖包
<dependency>
<groupId>tech.ibit</groupId>
<artifactId>sql-builder</artifactId>
<version>1.1</version>
</dependency>
版权声明: Apache 2
【转载】sql-builder介绍的更多相关文章
- SQL Mon 介绍
原文:SQL Mon 介绍 这是一个相当高级的SQL Server监控工具,全面监控SQL Server的活动与性能,分析性能瓶颈,给出优化建议. red-gate有一个在线的数据库监控工具,不过那个 ...
- 初学者SQL语句介绍
初学者SQL语句介绍 1.用 Select 子句检索记录 Select 子句是每一个检索数据的查询核心.它告诉数据库引擎返回什么字段. Select 子句的常见形式是: S ...
- pl/sql的介绍
为什么需要pl/sql编程? 因为使用纯的sql语句来操作数据库,有先天性的技术缺陷: 1.不能模块编程: 2.执行速度慢: 3.安全性有问题: 4.浪费带宽. pl/sql是什么? pl/sql(p ...
- SQL的介绍及MySQL的安装
基础篇 - SQL 介绍及 MySQL 安装 SQL的介绍及MySQL的安装 课程介绍 本课程为实验楼提供的 MySQL 实验教程,所有的步骤都在实验楼在线实验环境中完成, ...
- [转载]sql 盲注之正则表达式攻击
[转载]sql 盲注之正则表达式攻击 -----------------------------------------MYSQL 5+-------------------------------- ...
- oracle PL/SQL的介绍
转自:http://blog.sina.com.cn/s/blog_4c302f060101i4o1.html 一 PL/SQL的介绍 1 PL/SQL是什么? PL/SQL(procedural l ...
- xorm的sql builder
最近在使用xorm,并使用了sql builder来构建sql查询没想到升级后原来可以使用的代码居然报错了. 0x00 代码 sql, args, _ := builder.Select(" ...
- 四:SQL语句介绍
前言:介绍SQL语句及其大致的分类 一:SQL语句介绍(Structured SQL Lanage) 结构化的查询语言 是一种特殊的编程语言 是一种数据库查询和程序设计语言 用于存取数据及查询.更新和 ...
- SQL Builder 1.04
解析效果: select id,code,name,utime,src,ctime from stock where id<20 and code like '%6%' order by id, ...
- 转载--SQL Server 2005的XQuery介绍
原文地址: http://bbs.51cto.com/thread-458009-1-1.html 引用: 摘要 本文介绍了SQL Server 2005能够支持的XQuery的各方面特性如FLW ...
随机推荐
- 网络io模型总结
操作系统基本概念 首先来来说下操作系统,嗯,操作系统是计算机硬件的管理软件,是对计算机硬件的抽象,操作系统将应用程序分为用户态和内核态,例如驱动程序就位于内核态,而我们写的一般程序都是用户态,包括we ...
- Kdenlive-开始
版权声明:原创文章,未经博主允许不得转载 这是 Kdenlive 系列文章的第一篇 说明 在 Linux 下的视频编辑的软件并不多,作为其中之一的 kdenlive 在网上的教程就更少了.于是自己琢磨 ...
- Dynamics CRM CE 怎样从 UCI 改为 classic UI
dynamics 现在大力推UCI. 但是对于大部分人来说还是使用不习惯. 怎样从UCI改为classic UI呢 1. 快速的方法 https://xxx.crm.dynamics.com/main ...
- HDU 3839 Ancient Messages(DFS)
In order to understand early civilizations, archaeologists often study texts written in ancient lang ...
- python基础[1]——python运算符&python数据类型之数值型
python常用运算符&数字&布尔值 上节回顾 一.变量名和标识符 变量名的命名规范 (1)只能包含数字,字母和下划线 (2)只能以字母和下划线开头(不能以数字开头) (3)标识符是区 ...
- LeetCode 381. Insert Delete GetRandom O(1) - Duplicates allowed O(1) 时间插入、删除和获取随机元素 - 允许重复(C++/Java)
题目: Design a data structure that supports all following operations in averageO(1) time. Note: Duplic ...
- 死磕java(4)
数组 public void int4() { int[] int2 = {1,2,3,4}; System.out.print(int2[2]); } 输出:3 另一种数组的初始化 public ...
- 如何查看dll或者exe是X86还是X64架构
使用VS里面的dumpbin.exe 用法:dumpbin /headers *.exe(需要运行vcvarsall.bat) C32 or Winhex PE L为x86.PE d†为x64 P ...
- 每日一练PAT_B_PRAC_1005斐波那契凤尾
NowCoder号称自己已经记住了1-100000之间所有的斐波那契数.为了考验他,我们随便出一个数n,让他说出第n个斐波那契数.当然,斐波那契数会很大.因此,如果第n个斐波那契数不到6位,则说出该数 ...
- Python 语言规范(Google)
Python语言规范 Lint tip 对你的代码运行pylint 定义: pylint是一个在Python源代码中查找bug的工具. 对于C和C++这样的不那么动态的(译者注: 原文是less dy ...