我Redis用作我的Spring Web应用程序的数据存储,并Spring Data-Redis用作我的客户端进行交互Redis.
我HashMap用来存储一个有多个字段的对象.我可以Redis使用DefaultRedisMap.putAll()方法立即将所有字段放入,但我无法立即获取整个对象,而是BoundHashOperations使用get()方法获取每个字段.
我想知道有什么方法可以做到就像HGETALL支持的操作一样Redis吗?
我有点困惑.在填充循环的第一次迭代中,我在使用initial capacityfor ArrayListvs而不使用初始容量时看到填充时间的一些回归.
根据常识和这个问题:为什么要启动具有初始容量的ArrayList?
它必须完全相反.
它不是很好的基准测试,我想知道:为什么在第一次迭代时它总是在使用初始容量时消耗更多的时间和CPU ArrayList?
这是测试:
public class TestListGen {
public static final int TEST = 100_000_000;
public static void main(String[] args) {
test(false);
}
private static void test(boolean withInitCapacity) {
System.out.println("Init with capacity? " + withInitCapacity);
for (int i = 0; i < 5; i++)
av += fillAndTest(TEST, withInitCapacity ? new ArrayList<Integer>(TEST) : new ArrayList<Integer>());
System.out.println("Average: " + (av / 5));
}
private static long fillAndTest(int capacity, …Run Code Online (Sandbox Code Playgroud) 我已经整理了一个java测试.它将消息放入队列并将其作为字符串返回.我想要实现的是它转换为java对象SignUpDto.我已经尽可能地删除了代码.
问题:
如何修改下面的测试以转换为对象?
SignUpClass
public class SignUpDto {
private String customerName;
private String isoCountryCode;
... etc
}
Run Code Online (Sandbox Code Playgroud)
应用程序 - 配置类
@Configuration
public class Application {
@Bean
public ConnectionFactory connectionFactory() {
return new CachingConnectionFactory("localhost");
}
@Bean
public AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory());
}
@Bean
public RabbitTemplate rabbitTemplate() {
// updated with @GaryRussels feedback
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
return rabbitTemplate;
}
@Bean
public Queue myQueue() {
return new Queue("myqueue");
}
}
Run Code Online (Sandbox Code Playgroud)
考试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Application.class})
public class …Run Code Online (Sandbox Code Playgroud) 可以AdditionalBound在JLS8中描述的演员表达式用于除了 lambda表达式或方法引用之外的任何东西吗?
据说,它可能是:
( ReferenceType {AdditionalBound} ) UnaryExpressionNotPlusMinus
Run Code Online (Sandbox Code Playgroud)
然后:
由强制转换表达式引入的强制转换上下文(第5.5节)的目标类型是(...)由出现在强制转换运算符中的ReferenceType和AdditionalBound术语表示的交集类型.
但我找不到非 -lambda 或非 -method-reference示例的可行示例,例如:
X x = (I1&I2) some_UnaryExpressionNotPlusMinus
Run Code Online (Sandbox Code Playgroud)
UPD:
特别是,它允许类似的东西
X x = (I1&I2) ~ UnaryExpression,~一元运算符在哪里.
我不知道应该是什么X,I1,I2而且UnaryExpression在这种情况下.
UPD-2:感谢@Jimmy T.,他展示了可行的例子
Object x = (Number&Serializable)~0;.
但是很高兴看到非冗余的例子,这种铸造有意义.
UPD-3:根据以上所有这些表达式都已编译,但所有这些表达式都没有任何意义:
Object l1 = (Collection & Iterable) new ArrayList<>();
List l2 = (ByteList & Iterable) new ArrayList<>();
Collection l3 = (List & Iterable) …Run Code Online (Sandbox Code Playgroud) 当使用Spring和Thymeleaf时,我所有的西里尔字符都显示?????在页面上.
运用
@RequestMapping(value = "/login", method = RequestMethod.GET, produces = "text/html; charset=utf-8")
正如在此建议的那样:https://stackoverflow.com/a/11866822/1479414,此处:https://stackoverflow.com/a/12023816/1479414没有帮助.
如何解决这个问题?
我经常有这样的代码:
protected @Nullable Value value;
public boolean hasValue() { return value != null; }
Run Code Online (Sandbox Code Playgroud)
这个问题是,当我做这样的空检查时:
if (!hasValue()) throw...
return value.toString();
Run Code Online (Sandbox Code Playgroud)
然后IntelliJ会警告我可能的NPE
而
if (value != null) throw...
return value.toString();
Run Code Online (Sandbox Code Playgroud)
避免这个警告.
有没有办法装饰我的hasValue()方法,以便IntelliJ知道它进行空检查?并且不会显示警告?
我正在学习Java,我发现有许多标准化的功能:
让我们看一下Sl4j示例:要正确使用log4j,我们必须导入sl4j api,sl4j/log4j桥和log4j实现.
问题:在我的课堂上,我只与Slf4j API进行通信.
我的应用程序如何知道log4j实现?有人可以解释一下究竟发生了什么吗?
问候
我想知道我是否只能实例化javax.crypto.KeyGenerator一次,然后在多线程环境中使用此实例.
它的JavaDoc文档没有说明它的线程安全性.或者使用ThreadLocal<KeyGenerator>方法会更好?
更新:一个相关的问题是SecureRandom线程是否安全? 虽然JavaDoc没有声明该类是线程安全的,但是社区仍然认为它是线程安全的,从实际的角度来看这是非常重要的.我想知道KeyProvider的相同内容.
类作为LocalDateTime从封装java.time是基于值类.如果我有一个实体使用这样的对象作为字段,我会遇到以下"问题":不应序列化基于值的类.但是,JPA实体必须实现Serializable接口.这个悖论的解决方案是什么?不应该有人使用LocalDateTime作为JPA实体的字段吗?使用日期代替?这将是不满意的.
这个问题是一个声纳规则squid:S3437,因此项目中存在很多错误,因为我们从Date更改为LocalDateTime ...
基于价值的课程使用导致的不合规解决方案:
@Entity
public class MyEntity implements Serializable{
@Column
private String id; // This is fine
@Column
private LocalDateTime updated; // This is not ok, as LocalDateTime is a value based class
@Column
private Date created; // This however is fine..
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 openapi 生成器生成 API,当我运行 mvncompile 时,似乎没有找到任何像 jacks httprequest 这样的依赖关系,因此,我添加了详细信息,然后添加了插件:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>4.3.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/player.yml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
使用此文件player.yml:
openapi: 3.0.1
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server. You can find out more about Swagger
at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For
this sample, you can use the api key `special-key` to test the authorization filters.'
termsOfService: http://swagger.io/terms/
contact: …Run Code Online (Sandbox Code Playgroud) java ×9
spring ×3
java-8 ×2
annotations ×1
arraylist ×1
casting ×1
cryptography ×1
jedis ×1
jpa ×1
logging ×1
maven ×1
performance ×1
rabbitmq ×1
redis ×1
slf4j ×1
sonarqube ×1
spring-amqp ×1
spring-data ×1
spring-mvc ×1
thymeleaf ×1
utf-8 ×1