Skip to main content
huhx

huhx

——「」

github
welcome to huhx's github
project name
project detailed description
link name
link detailed description
book name
Detailed description of the book
article name
Detailed description of the article
friend name
Detailed description of friend
Java小技巧

如何编写更健壮更好的java代码?这里面整理收集一些在java开发过程中我们需要注意的一些点或者说是技巧,从而提高代码的质量以及我们的工作效率。

Springboot

Ignore Null Fields with Jackson

springboot中默认序列化Json的框架就是jackson了,这里面介绍在springboot项目中如何忽略null字段

  • 全局

springboot配置和java代码都可以实现全局忽略null的功能

  • 类级别

huhxAbout 5 minjavaTips
时间类型的选取

Java中提供的时间类型可谓五花八门,从最开始的Date类型,再后面引入LocalDateLocalDateTime这些类型,再有ZonedDateTimeOffsetDateTime等等粉墨登场,半路还杀出个Instant。乱花渐欲迷人眼,开发多了选择,却纠结于选择。今天,我们就来看看这些百花争艳的时间类型中,谁能够在项目中取得宠爱。

起始

后端

数据库的时间字段:


huhxAbout 1 min
adb命令的使用

卸载应用

有时候手机上面debug时的应用没能删除干净,导致后续的安装会出错。这时可以通过adb命令来删除手机上的应用

## get device id
adb devices | tail -n +2 | cut -sf 1

## uninstall apk
adb -s <device ID> uninstall <package name>

## example
adb -s 4c0e5ef8 uninstall com.huhx.love_family
adb -s 192.168.31.53:39873 uninstall com.huhx.lifetool

huhxLess than 1 minute
本地使用ES

本地启动ES

修改max_map_count

docker network create elastic

docker pull docker.elastic.co/elasticsearch/elasticsearch:8.10.3

docker run --name es01 --net elastic \
    -p 9200:9200 \
    -e discovery.type=single-node \
    -e "xpack.security.enabled=false" \
    -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.10.3 

huhxAbout 1 mindbDBElasticSearch
幂等性

用户在系统中有操作,不管重复多少次,都应该产生一样的效果或返回一样的结果的。

1. 前端重复提交选中的数据,后台也只会产生对应这个数据的一个反应结果。

2. 用户发起一笔付款请求,就应该只扣用户一次钱,即使遇到网络重发或系统 bug 重发请求,也应该之扣一次钱。

3. 发送验证短息也应该只发一次,同样的验证短信不应该发送多次。

4. 创建业务订单,一个业务请求只能创建一个业务订单,创建多个就会出大问题。

huhxLess than 1 minute
2
3
4
5
...
15