- Spring Boot
- mybatis-plus代码生成器和自带CRUD接口
- lombok
- 库: Apache Commons & guava
- AOP
- Java8: stream & lambda
- 反射
- 日志取代debug
- IDEA:使用恰当的开发工具并熟悉、熟练使用其功能
- 单元测试:不必运行整个项目,减少项目运行时间(好处之一)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StreamUtil { | |
private StreamUtil() { | |
} | |
/** | |
* stream Distinct by property | |
* | |
* @param keyExtractor keyExtractor | |
* @return java.util.function.Predicate<T> | |
* @author yanganyu |
<select id="selectBlogsLike" resultType="Blog">
<bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
SELECT * FROM BLOG
WHERE title LIKE #{pattern}
</select>
模糊查询一般有三种方式:
- Java代码里拼接匹配符: 代码和SQL耦合度高;查看xml不能直接看出查询条件,降低开 发效率;有可能在service层多次加%_
perfer count(*)
- 官方文档:
InnoDB handles SELECT COUNT(*) and SELECT COUNT(1) operations in the same way. There is no performance difference.
- 阿里手册:
【强制】不要使用 count( 列名 ) 或 count( 常量 ) 来替代 count( * ) , count( * ) 是 SQL 92 定义的 标准统计行数的语法,跟数据库无关,跟 NULL 和非 NULL 无关。 说明: count( * ) 会统计值为 NULL 的行,而 count( 列名 ) 不会统计此列为 NULL 值的行。
- Timer
- ScheduledExecutorService
- spring @Scheduled
- Quartz
- Linux定时任务
- 定时任务管理系统(e.g. gocron, xxl-job,功能包括监控、告警、执行日志、报表等)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
我们使用开源软件大部分情况是为了不重复造轮子,使用一些别人写好的具有通用性的代码来减少我们的代码量,提高开发效率,减少开发成本。而且使用一些优秀的开源软件会比我们自己开发的好,毕竟它们被很多人使用,经受了很多人很多次的检验。 | |
但是,有些开源软件却很坑,用它们到最后发现有不断的坑,到头来发现不如直接用底层的、未封装的API,或者自己开发。下面说些应该避免的坑: | |
1. 社区小(比如GitHub的star少)的开源软件 | |
对于社区小的开源软件,当你遇到问题,很难快速解决。而那些社区大的开源软件,Google搜下很容易搜到你遇到的常见的问题。大小是相对的,那么谈谈如何比较两个开源软件的社区大小,可以比较它们在开源平台的收藏数量、issues数量、PR数量,也可以用Google trends对比下,也可以对比下Google搜索结果数目,也可以对比下它们在stackoverflow等平台搜索结果数目。 | |
2. 国产开源软件 | |
不是看不起国产开源软件,国产优秀的开源软件其实也有一些。但整体上看,国产开源软件文档质量不行。社区小,一般很少有外国人使用,而国外的开发者数量和质量明显高于国内。举个例子,fastjson和jackson,虽然fastjson应该比jackson性能好一点,但fastjson的功能和代码质量不如jackson,而且fastjson社区也不如jackson,当用jackson遇到问题时,用Google英文搜索下,一般很容易搜到解决办法,而用fastjson遇到问题一般只能去看看fastjson那一点点文档。顺便提一下,用中文搜索问题,一般比较难很快找到解决办法。我想原因大概如下:1、Google的中文搜索能力不如英文(baidu啥的更别谈)2、国内开发者鱼龙混杂,由于编程入门门槛低,有好多水平欠缺的开发者写了大量低质量博客,中文博客的信噪比非常糟糕,很少有我感觉还可以的博主。举个例子,CSDN博客质量简直不堪入目,我现在直接用扩展屏蔽了CSDN。 | |
3. 不再维护的或代码贡献频率低的开源软件 | |
在我开来,软件开发者应该要对自己的软件负责,就是一直对自己开源的软件质量负责,close所有issues,解决软件bug。做到这点很难,连我自己一些玩具开源项目都不再维护,但我会在README中标注不再维护,减少浪费有些人的时间,我也会及时close每一个issues。如果实在不想 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jackson deserialization json to generic java object | |
* | |
* @param jsonStr json string | |
* @param typeReference typeReference | |
* @return generic object | |
* @author yanganyu | |
* @date 2019/2/21 13:37 | |
*/ | |
public static <T> T parse(String jsonStr, TypeReference<T> typeReference) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* String Utility | |
* | |
* @author yanganyu | |
* @date 2019/3/18 14:31 | |
*/ | |
public class StringUtil { | |
private StringUtil() { | |
} |