我现在有一个要求,就是当使用mybatis(特别是那些批处理执行sql)时,先检查参数,如果参数为null或为空,则只返回,不要继续,如果返回类型是List,例如.
List<User> getByIds(List<Long> idList)
Run Code Online (Sandbox Code Playgroud)
返回空ArrayList,如果返回类型为void:
void batchInsert(List<User>)
Run Code Online (Sandbox Code Playgroud)
返回null.目的是避免这种情况,例如.
select * from user where id in ()
insert into user(name,email) values ()
Run Code Online (Sandbox Code Playgroud)
但是从joinPoint我无法获得返回类型,只能得到args.
Object[] args = joinPoint.getArgs();
if(args!=null&&args.length=1){
if(args[0] instanceof List){
if(((List) obj).isEmpty()){
if(returnType.equals("java.util.List"))
return new ArrayList();
else if(returnType.equals("void"))
return null;
}
}
return joinPoint.proceed();
Run Code Online (Sandbox Code Playgroud)
那么如何在aop中得到返回类型:around?
现在因为下面的现象我觉得我完全不理解字符集。起初我认为只有 utf8mb4 支持 Emoji 字符,例如。见下文:
As of MySQL 5.5.3, the utf8mb4 character set uses a maximum of four bytes per character supports supplemental characters
Run Code Online (Sandbox Code Playgroud)
但无意中我发现了这个现象,如下:
mysql> show variables like 'character%';
+--------------------------+---------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /opt/mysql/server-5.6/share/charsets/ |
+--------------------------+---------------------------------------+
mysql> show …Run Code Online (Sandbox Code Playgroud) 这是Java Api的错误吗?
int i = 0xD3951892;
System.out.println(i); // -745203566
String binString = Integer.toBinaryString(i);
int radix = 2;
int j = Integer.valueOf(binString, radix );
Assertions.assertThat(j).isEqualTo(i);
Run Code Online (Sandbox Code Playgroud)
我希望它毫无疑问是真的.但它抛出异常:
java.lang.NumberFormatException: For input string: "11010011100101010001100010010010"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.valueOf(Integer.java:556)
at com.zhugw.temp.IntegerTest.test_valueof_binary_string(IntegerTest.java:14)
Run Code Online (Sandbox Code Playgroud)
所以如果我有一个二进制字符串,例如11010011100101010001100010010010,我怎样才能在Java中得到它的十进制数(-745203566)?DIY?编写代码来实现下面的等式?

如何使用Spring Data Jpa实现批量更新?我有商品实体,对于差异用户等级,有差价,例如
goodsId level price
1 1 10
1 2 9
1 3 8
Run Code Online (Sandbox Code Playgroud)
更新商品时我想批量更新这些价格,如下所示:
@Query(value = "update GoodsPrice set price = :price where goodsId=:goodsId and level=:level")
void batchUpdate(List<GoodsPrice> goodsPriceList);
Run Code Online (Sandbox Code Playgroud)
但它抛出异常,
Caused by: java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.
Run Code Online (Sandbox Code Playgroud)
那么如何正确使用Spring数据Jpa实现批量更新呢?
背景:Spring Boot项目,添加商品和商品价目表
Goods:
List<GoodsPrice> pricelist;
Run Code Online (Sandbox Code Playgroud)
在控制器中首先将货物形式转换为货物(通过推土机),然后保存货物,保存货物后迭代货物价目表以填充货物 ID。
goods.getPriceList().forEach(p -> p.setGoodsId(goods.getId()));
Run Code Online (Sandbox Code Playgroud)
迭代商品价目表时,抛出异常:
java.lang.ClassCastException: com.foo.goods.model.GoodsPrice cannot be cast to com.foo.goods.model.GoodsPrice
at com.foo.goods.service.GoodsService$$Lambda$11/310447431.accept(Unknown Source) ~[na:na]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_51]
at com.foo.goods.service.GoodsService.saveGoods(GoodsService.java:34) ~[classes/:na]
Run Code Online (Sandbox Code Playgroud)
有人提醒我这个与classloader有关的异常,在eclipse调试模式下,我输出了GoodsPrice的ClassLoader:
sun.misc.Launcher$AppClassLoader@14dad5dc
Run Code Online (Sandbox Code Playgroud)
和货物:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@591c6338
确实存在差异类加载器。然后我评论spring-boot-devtools然后再次尝试这次没关系。那么如果仍然保留spring-boot-devtools,如何解决这个问题?
起初我想要比较count(*)和count(id),它有更好的性能?
mysql版本
5.6.21-1~dotdeb.1-log
Run Code Online (Sandbox Code Playgroud)
表信息
PRIMARY KEY (`id`),
KEY `is_availability` (`is_availability`,`is_del`)
ENGINE=InnoDB AUTO_INCREMENT=48993819 DEFAULT CHARSET=utf8
Run Code Online (Sandbox Code Playgroud)
比较没有条件
select count(*) from op_log;
+----------+
| count(*) |
+----------+
| 48989975 |
+----------+
1 row in set (10.02 sec)
select count(id) from op_log ;
+-----------+
| count(id) |
+-----------+
| 48989990 |
+-----------+
1 row in set (12.05 sec)
Run Code Online (Sandbox Code Playgroud)count(*) 比...更好 count(id)
与条件相比较
select count(*) from op_log where is_availability=1;
+----------+
| count(*) |
+----------+
| 48990038 |
+----------+
1 row in set (15.86 sec)
select …Run Code Online (Sandbox Code Playgroud)这不是一个 web 项目,但我仍然spring-boot-starter-actuator在 pom 中添加,并指定management.port=8081,然后在运行方法的最后一个CommandLineRunner,有以下代码,
System.in.read();
Run Code Online (Sandbox Code Playgroud)
当这个项目开始时,它会坚持下去。然后我将访问http://localhost:8081/configprops,但显示以下消息:
This webpage is not available
Run Code Online (Sandbox Code Playgroud)
那么如何在非 Web 应用程序中访问执行器端点呢?顺便说一句,我为什么要这样做,因为在启动我的项目时,它无法成功加载 yml 数据并导致 NPE。所以我想访问/configprops以检查它。
我的 yml 是这样的:
spring:
profiles.active: default
---
spring:
profiles: default
user:
foo:
aaa: aaa@foo.com
---
spring:
profiles: test
user:
foo:
aaa: aaa@foo.com
bbb: bbb@foo.com
@ConfigurationProperties(prefix="user", locations="user.yml")
public class UserConfig {
private HashMap<String, String> foo;
}
Run Code Online (Sandbox Code Playgroud) Mac OS X El Capitan(版本10.11.5)想要连接到服务器以访问一些共享图像。
Finder -> Go -> Connect to Server,然后输入地址
smb://172.16.X.X/
Run Code Online (Sandbox Code Playgroud)
然后下一步输入用户名和密码,然后就会提示
Check the server name or IP address, and then try again. If you continue to have problems, contact your system administrator.
Run Code Online (Sandbox Code Playgroud)
但是我的同事都可以连接成功,只有我自己连接不上。
中的错误消息Console是
6/16/16 21:14:24.000 kernel[0]: smb_ntstatus_error_to_errno: Couldn't map ntstatus (0xc000019c) to errno returning EIO
6/16/16 21:14:25.000 kernel[0]: smb_ntstatus_error_to_errno: Couldn't map ntstatus (0xc000019c) to errno returning EIO
6/16/16 21:14:26.000 kernel[0]: smb_ntstatus_error_to_errno: Couldn't map ntstatus (0xc000019c) to errno returning EIO
6/16/16 21:14:26.465 NetAuthSysAgent[1218]: checkForDfsReferral: …Run Code Online (Sandbox Code Playgroud) 当审查同事的代码时,发现下面的代码
BufferedReader br = new BufferedReader(new FileReader(PATH + fileName));
//...
Run Code Online (Sandbox Code Playgroud)
只是读取一个文件并将这些行连接成一行,但我没有发现任何密切的代码,所以我认为它应该导致资源泄漏,最后导致too many open files error,所以为了证明这一点,我写了一个测试
for (int i = 0; i < 7168; i++) { // ulimit -n ==> 7168
BufferedReader br = new BufferedReader(new FileReader("src/main/resources/privateKey/foo.pem"));
System.out.println(br.readLine());
}
System.in.read();
Run Code Online (Sandbox Code Playgroud)
很奇怪,一切都好,不会抛出预期的异常.
并在命令行中检查实际打开的文件
? ~ lsof -p 16276 | grep 'foo.pem' | wc -l
2538
Run Code Online (Sandbox Code Playgroud)
为什么只有2538,而不是7168?
那有什么不对?怎么引起的too many open files error?
正如@GhostCat建议的那样,更改7168 - > Integer.MAX_VALUE,这次造成的
java.io.FileNotFoundException: src/main/resources/privateKey/foo.pem (Too many open files in system)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195) …Run Code Online (Sandbox Code Playgroud) Nginx 缓存配置:
proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g
inactive=60m use_temp_path=off;
server {
# ...
location / {
proxy_cache my_cache;
proxy_cache_valid 5m;
proxy_pass http://my_upstream;
}
}
Run Code Online (Sandbox Code Playgroud)
不活跃
inactive 指定一个项目可以在缓存中保留多久不被访问。在这个例子中,一个在 60 分钟内没有被请求的文件会被缓存管理器进程自动从缓存中删除,不管它是否已经过期。
proxy_cache_valid
为不同的响应代码设置缓存时间。如果仅指定缓存时间,则仅缓存 200、301 和 302 响应。
是否proxy_cache_valid覆盖动静吗?5m 后缓存文件是否存在?
java ×3
mysql ×2
spring-boot ×2
classloader ×1
dozer ×1
emoji ×1
macos ×1
nginx ×1
smb ×1
spring ×1
spring-aop ×1
ulimit ×1