小编nav*_*_gh的帖子

hibernate注释中的@UniqueConstraint和@Column(unique = true)

@UniqueConstraint@Column(unique = true)有什么区别?

例如:

@Table(
   name = "product_serial_group_mask", 
   uniqueConstraints = {@UniqueConstraint(columnNames = {"mask", "group"})}
)
Run Code Online (Sandbox Code Playgroud)

@Column(unique = true)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private ProductSerialMask mask;

@Column(unique = true)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Group group;
Run Code Online (Sandbox Code Playgroud)

java hibernate hibernate-annotations

88
推荐指数
4
解决办法
11万
查看次数

解决 Webflux 中的可分页问题

我花了很多时间在Webflux中寻找有关Pageable的解决方案,不幸的是,在撰写本文时,Webflux不支持Pageable,所以我想出了一个解决方案,这就是我所实现的。这是一个解决 Spring Boot 中 Webflux 控制器/资源中的 Pageable 和 Sort 类型的 hacky 解决方案。

这是解决方案:(我知道它可能很难看,但你可以使用它直到 Spring 团队解决问题,我们正在为此努力。Spring Jira

另外,要点在这里:Github

更新1:你也可以在medium中找到这篇文章

版本:

Spring Boot: 2.0.2.RELEASE
Gradle Kotlin: 1.2.41
Run Code Online (Sandbox Code Playgroud)

请随时给我提示以改进它。(代码是Kotlin)

@Configuration
class PageableSerializer {

@Bean
@ConditionalOnMissingBean
fun pageableCustomizer(properties: SpringDataWebProperties): PageableHandlerMethodArgumentResolverCustomizer {
    return PageableHandlerMethodArgumentResolverCustomizer { resolver ->
        val pageable = properties.pageable

        resolver.setPageParameterName(pageable.pageParameter)
        resolver.setSizeParameterName(pageable.sizeParameter)
        resolver.setOneIndexedParameters(pageable.isOneIndexedParameters)
        resolver.setPrefix(pageable.prefix)
        resolver.setQualifierDelimiter(pageable.qualifierDelimiter)
        resolver.setFallbackPageable(PageRequest.of(0, pageable.defaultPageSize))
        resolver.setMaxPageSize(pageable.maxPageSize)

    }
}

@Bean
@ConditionalOnMissingBean
fun sortCustomizer(properties: SpringDataWebProperties): SortHandlerMethodArgumentResolverCustomizer {
    return SortHandlerMethodArgumentResolverCustomizer { resolver ->
        resolver.setSortParameter(properties.sort.sortParameter)
    }
}

@Bean
fun pageableHandler(pageableResolver: Optional<PageableHandlerMethodArgumentResolverCustomizer>, sortHandler: SortHandlerMethodArgumentResolver, …
Run Code Online (Sandbox Code Playgroud)

java rest spring kotlin spring-boot

6
推荐指数
2
解决办法
3970
查看次数

mongodb 查询带有键值的弹簧数据

我已经开始了一个使用 mongodb 和 spring boot 以及 spring JPA 数据的项目,我意识到我无法将我的数据模型映射到实体并轻松进行查询,所以我有两个问题,

我的数据模型就是这样(仅用于一个集合)

{
   name: "Name",
   lastName: "Last Name",
   attributes: {
      age: 25
      eye: {
         color: "RED",
         size: "BIG"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我的实体是

@Entity // or @Document
public class User{
   private String name;
   private String lastName;
   private Map<String, ?> attributes = new HashMap<>();

   // id or the setter getter are omitted
}
Run Code Online (Sandbox Code Playgroud)
  1. 我可以像我一样在我的 mongodb 集合中映射属性属性吗 ( Map )
  2. 如何查询以查找属性?

    我可以这样做吗? List<User> findAllByAttributesAge(Integer age);

java spring mongodb spring-data-mongodb spring-boot

5
推荐指数
2
解决办法
1万
查看次数