com.example.demo.Post.setId()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中com.example.demo.Post.setId()方法的一些代码示例,展示了Post.setId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Post.setId()方法的具体详情如下:
包路径:com.example.demo.Post
类名称:Post
方法名:setId

Post.setId介绍

暂无

代码示例

代码示例来源:origin: hantsy/spring-reactive-sample

@PostMapping("")
public Mono<Post> create(@RequestBody Post post) {
  post.setId(UUID.randomUUID().toString());
  return this.posts.save(post);
}

代码示例来源:origin: hantsy/spring-reactive-sample

@PostMapping("")
public Mono<Post> create(@RequestBody Post post) {
  post.setId(UUID.randomUUID().toString());
  return this.posts.save(post);
}

代码示例来源:origin: hantsy/spring-reactive-sample

Mono<Post> save(Post post) {
  if (post.getId() != null) {
    String id = UUID.randomUUID().toString();
    post.setId(id);
  }
  return template.<String, Post>opsForHash().put("posts", post.getId(), post)
    .log()
    .map(p -> post);
}

代码示例来源:origin: hantsy/spring-reactive-sample

@Bean
public ReactiveRedisMessageListenerContainer redisMessageListenerContainer(PostRepository posts, ReactiveRedisConnectionFactory connectionFactory) {
  ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(connectionFactory);
  ObjectMapper objectMapper = new ObjectMapper();
  container.receive(ChannelTopic.of("posts"))
    .map(p->p.getMessage())
    .map(m -> {
      try {
        Post post= objectMapper.readValue(m, Post.class);
        post.setId(UUID.randomUUID().toString());
        return post;
      } catch (IOException e) {
        return null;
      }
    })
    .switchIfEmpty(Mono.error(new IllegalArgumentException()))
    .flatMap(p-> posts.save(p))
    .subscribe(c-> log.info(" count:" + c), null , () -> log.info("saving post."));
  return container;
}

相关文章