在从对象解析为json和反之亦然时,我已经有了最可想象的工作时间纳秒.我创造了最简单的杰克逊使用方法,我无法获得纳秒.以下是我的演示.在fastxml FAQ中有三个与我的案例相关的重要声明.前两个给我制作工作的技巧,第三个告诉我不要使用sql.Date但是sql.timestamp是"儿子" sql.Date.
问题是:
首先,
mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS,true)并@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSSSS")采取没有任何影响.我可以放置false,true甚至不使用mapper.configure,使用或不使用,@JsonFormat结果将是相同的,
其次,如果我只尝试反序列化,我的意思是,输入值2015-01-07 11:37:52.390452中user.json,只跑mapper.readValue我将获得价值2015-01-07 11:44:22.452,所以我错过了准确的数值,因为Jacskon围捕.
来自http://wiki.fasterxml.com/JacksonFAQDateHandling
1 - Feature.WRITE_DATES_AS_TIMESTAMPS,false); 禁用时间戳(数字)的使用,而是使用符合[ISO-8601]的符号,输出如下:"1970-01-01T00:00:00.000 + 0000".
2 - 您可以通过传递java.text.DateFormat来配置格式
3 - 请不要使用java.sql.Date!
// pojo
package com.jim.core;
import java.sql.Timestamp;
import com.fasterxml.jackson.annotation.JsonFormat;
public class User {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSSSS")
private Timestamp tsFirstTry;
private Timestamp tsSecondTry;
@Override
public String toString() {
return "User [tsFirstTry=" + tsFirstTry + ", …Run Code Online (Sandbox Code Playgroud) 我正在开发一个基于Spring Batch,Spring Boot,slf4j和Java 8的简单应用程序.我想尽可能多地使用lambda用于学习目的."myPojos.stream()forEach((myPojo) - > {log.info(myPojo);});"是什么问题 下面?该消息抱怨"......不适用于论点<? extends MyPojo".请注意,所有其他三个日志行都正常工作.
public class CustomItemWriter implements ItemWriter<MyPojo> {
private static final Logger log = LoggerFactory.getLogger(CustomItemWriter.class);
@Override
public void write(List<? extends MyPojo> myPojos) throws Exception{
myPojos.stream().forEach((myPojo)-> {log.info(myPojo);});//error
myPojos.forEach(System.out::println);//it works
myPojos.stream().forEach((myPojo) -> {System.out.println(myPojo);}); //it works
log.info("finish"); //it works
}
}
Run Code Online (Sandbox Code Playgroud) 我的 Bower.json 中有这两个依赖项:Polymer/polymer#^2.6.0 和 webcomponents/webcomponentsjs#^v1.1.0。
在我的 index.html 中,如果我添加,我看不到任何区别
<script src="bower_components/webcomponentsjs/webcomponents-lite.js">
or
<script src="bower_components/webcomponentsjs/webcomponents-loader.js">.
Run Code Online (Sandbox Code Playgroud)
从https://www.npmjs.com/package/webcomponents-lite我读到“webcomponents-lite.js 包括除影子 DOM 之外的所有 polyfill”,并从https://www.npmjs.com/package/web-components-我读到“将 HTML 文件及其所有依赖项复制到公共/输出目录中的命名空间位置”。我可以假设 web-components-loader 执行 webcomponents-lite 默认执行的操作以及其他一些加载功能吗?有什么理由使用其中一种而不是另一种吗?看来 webcomponents-lite 的加载过程较少,所以如果它符合我的需求,它会比 webcomponents-loader 更好吗?
我正在尝试使用Spring Cloud + Kafka Streams + Spring Boot 2创建最简单的问候世界。
我意识到我错过了基本概念。基本上,我了解到:
1-我需要定义一个出站流以将消息写到Kafka主题,并定义一个入站流以从Kafka主题中读取消息
public interface LoansStreams {
String INPUT = "loans-in";
String OUTPUT = "loans-out";
@Input(INPUT)
SubscribableChannel inboundLoans();
@Output(OUTPUT)
MessageChannel outboundLoans();
}
Run Code Online (Sandbox Code Playgroud)
2-配置Spring Cloud Stream绑定到我的流
@EnableBinding(LoansStreams.class)
public class StreamsConfig {
}
Run Code Online (Sandbox Code Playgroud)
3-配置Kafka属性
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:9092
bindings:
loans-in:
destination: loans
contentType: application/json
loans-out:
destination: loans
contentType: application/json
Run Code Online (Sandbox Code Playgroud)
4-创建交换消息模型
@Getter @Setter @ToString @Builder
public class Loans {
private long timestamp;
private String result;
}
Run Code Online (Sandbox Code Playgroud)
5-写给卡夫卡
@Service
@Slf4j
public class LoansService …Run Code Online (Sandbox Code Playgroud) apache-kafka spring-boot spring-cloud-stream apache-kafka-streams
我想请求一个令牌,以便我可以让我的 Postman 登录我的 Gmail 帐户,然后我可以调用 Google Cloud API。
我正在尝试输入我的 Gmail 电子邮件地址及其密码,正如您从这张图片中看到的
最终目标是获得这样的 API
https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards
Run Code Online (Sandbox Code Playgroud)
我可以通过从 gcloud 登录我的 Gmail 帐户(“gcloud auth 应用程序默认登录”)来完成,然后使用 gcloud auth 应用程序默认打印访问令牌打印令牌,复制打印的令牌并将其粘贴到访问令牌中(邮差)。好吧,它工作正常,但我有义务启动 gcloud 并安装它。我很确定我可以通过与我在 gcloud 中登录的同一用户签名来达成相同的想法。我只是不知道如何用 Postman 做到这一点。上几个小时我读到的所有内容都让我看到了上面粘贴的图像,但由于这个问题的错误而失败。
如果相关,这是我获取令牌的 gcloud 控制台
C:\Program Files (x86)\Google\Cloud SDK>gcloud auth application-default print-access-token
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\lib\third_party\google\auth\_default.py:69: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you …Run Code Online (Sandbox Code Playgroud) google-api google-oauth google-cloud-platform postman gcloud
简而言之,我启动了 Kafka,成功创建了一个主题,启动了一个启用了密钥的生产者。到目前为止,一切都很好。我发送一条简单的消息,然后我得到
root@kafka:/# kafka-console-producer --broker-list localhost:9092 --topic testkey --property "parse.key=true" propert
y "key.separator=:"
>1:fisrtmessage
org.apache.kafka.common.KafkaException: No key found on line 1: 1:fisrtmessage
at kafka.tools.ConsoleProducer$LineMessageReader.readMessage(ConsoleProducer.scala:275)
at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:55)
at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
root@kafka:/#
Run Code Online (Sandbox Code Playgroud)
这里既是生产者又是消费者。正如你所看到的,消费者没有收到消息,生产者崩溃了。
docker-compose.yml
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.4.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-server:5.4.0
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: …Run Code Online (Sandbox Code Playgroud) apache-kafka docker kafka-producer-api apache-zookeeper confluent-platform
我想使用 protoc-gen-grpc-kotlin 中的protoc-gen-grpc-kotlin -1.0.0并且我得到了
\nExecution failed for task \':generateProto\'.\n> Could not resolve all files for configuration \':protobufToolsLocator_grpckt\'.\n > Could not find protoc-gen-grpc-kotlin-1.0.0-windows-x86_64.exe (io.grpc:protoc-gen-grpc-kotlin:1.0.0).\n Searched in the following locations:\n https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-kotlin/1.0.0/protoc-gen-grpc-kotlin-1.0.0-windows-x86_64.exe\n\nPossible solution:\n - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html\nRun Code Online (Sandbox Code Playgroud)\n整个堆栈跟踪是
\nC:\\_d\\toLearn\\demo-grpc-jaeger>gradle clean build --stacktrace\n> Task :generateProto FAILED\n\nFAILURE: Build failed with an exception.\n\n* What went wrong:\nExecution failed for task \':generateProto\'.\n> Could not resolve all files for configuration \':protobufToolsLocator_grpckt\'.\n > Could not find protoc-gen-grpc-kotlin-1.0.0-windows-x86_64.exe (io.grpc:protoc-gen-grpc-kotlin:1.0.0).\n Searched …Run Code Online (Sandbox Code Playgroud) I have two simple entities: user and account. Account can be related to one or many users. For instance: a bank account belongs to a single person or belong to a couple.
I am getting the error mentioned in the topic when I tried to post an account. I guess the issue is how I am formatting the json in postman. I don't see errors in my entities.
user:
@Entity
@Table(name = "bankuser")
public class User implements java.io.Serializable {
/** …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的页面,其中有两个填充了相同数据(银行账户)的选择。一个目标是源,另一个目标是为了创建交易。在这个简单的场景中,交易只是从一个账户转移到另一个账户的金额。
我在将交易发送到我的休息服务时遇到问题。从下图很容易看出交易变量没有正确填充,但我不知道出了什么问题。
我看到交易中的第一个帐户(源)部分填充,第二个(目标)带有 [object Object]。为什么没有填充相同,因为它们是完全相同类型的对象,为什么在第一个名称中没有填充?
新交易.html:
<div>
<div>
<label>Source Account</label>
<select [(ngModel)]="transaction.sourceAccount">
<option *ngFor="let a of accounts" [value]="a" >{{a.name}}</option>
</select>
</div>
<div>
<label>Target Account</label>
<select [(ngModel)]="transaction.targetAccount" >
<option *ngFor="let a of accounts" [value]="a">{{a.name}}</option>
</select>
</div>
<div>
<input type="text" [(ngModel)]="transaction.amount">
</div>
<div>
<button (click)="addTransaction()">Add</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
new-transaction.component.ts
...
export class NewTransactionComponent implements OnInit {
accounts: Account[];
transaction: Transaction = new Transaction();
constructor(private accountService: AccountService, private transactionService: TransactionService) { }
ngOnInit(): void {
this.transaction.targetAccount = new Account();
this.transaction.sourceAccount = new Account();
this.accountService …Run Code Online (Sandbox Code Playgroud) 我找不到能够在 master 以外的任何分支中推送更改的原因。我的意思是,我通过将代码推送到 gitlab 来创建主分支。然后,任何将更改推送到主分支的尝试都失败了。尽管如此,我用另一个名为 develop 的分支复制了我的 master 分支,我可以在它上面推送我的更改。为了简单起见,让我把我在谷歌搜索一段时间后所做的一切:
C:\dev\test>git fetch --all
Fetching origin
C:\dev\test>git reset --hard origin/master
HEAD is now at 64031f0 just created by generator
... some changes via my editor ....
C:\dev\test>git commit -a -m "changed project name"
[master 5abf2f2] changed project name
1 file changed, 5 insertions(+), 5 deletions(-)
C:\dev\test>git push -u origin/master
fatal: 'origin/master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the …Run Code Online (Sandbox Code Playgroud) apache-kafka ×2
java ×2
json ×2
spring-boot ×2
angular ×1
datetime ×1
docker ×1
fasterxml ×1
gcloud ×1
git ×1
gitlab ×1
google-api ×1
google-oauth ×1
gradle ×1
grpc ×1
hibernate ×1
jackson ×1
java-8 ×1
jpa ×1
kotlin ×1
lambda ×1
log4j ×1
micronaut ×1
polyfills ×1
polymer-2.x ×1
postman ×1
protoc ×1
slf4j ×1