小编Nik*_*nko的帖子

将 WHERE IN 子句添加到 JPA 规范

我正在尝试实现受 IN 子句限制的搜索功能:

我想实现带有过滤器限制的搜索实现:

    @GetMapping("find")
    public Page<MerchantUserDTO> getAllBySpecification(
            @And({
                @Spec(path = "name", spec = LikeIgnoreCase.class),
                @Spec(path = "login", spec = LikeIgnoreCase.class),
                @Spec(path = "email", spec = LikeIgnoreCase.class),
            }) Specification<Users> specification,
            @SortDefault(sort = "login", direction = Sort.Direction.DESC) Pageable pageable
    ) {        
        return merchantUserService.getAllBySpecification(specification, pageable)
                .map(g -> MerchantUserDTO.builder()                   
                        .id(g.getId())
                        .login(g.getLogin())                        
                        .build()
                );
    }

    @Override
    public Page<Users> getAllBySpecification(Specification<Users> specification, Pageable pageable) {
        return dao.findAllByTypeIn(specification, pageable, "MerchantUser");
    }
Run Code Online (Sandbox Code Playgroud)

存储库:

@Repository
public interface MerchantUserRepository extends JpaRepository<Users, Integer>, JpaSpecificationExecutor<Users> {

    Page<Users> findAllByTypeIn(Pageable page, String... types);

    Page<Users> …
Run Code Online (Sandbox Code Playgroud)

jpa jpa-2.0 spring-data-jpa jpa-2.1 spring-boot

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

更改 Drone 中 Exec Runner 的用户

Drone我已经在我的远程主机上设置了Ubuntu 18.04 Linux。为了方便起见,我安装了drone-runner-exec. 我已经成功地将它连接到我的GitHub等。所以现在它工作正常,即它克隆存储库并开始运行我的管道。步骤之一是简单的 bash 脚本,它必须更新存储库中的子文件夹。

steps:
- name: Getting subfolders
  commands:
  - ./my_script
Run Code Online (Sandbox Code Playgroud)

运行程序执行脚本,但在某些点上失败。搜索后,我发现在用户下执行的脚本我已经安装了Drone. 我在ps aux输出中看到 和dockerdroneroot.

所以我的问题 - 如何更改运行程序运行的系统用户?

linux docker drone.io ubuntu-18.04

6
推荐指数
1
解决办法
1093
查看次数

具有条件和 nullValuePropertyMappingStrategy 的 Mapstruct 映射

如果标题不清楚,我很抱歉,让我通过给出示例代码来澄清:

更新配置文件Dto

public class UpdateProfileDto {

    @NotEmpty
    private String firstName;

    @NotEmpty
    private String lastName;

    @Size(max = 20)
    private String currentPassword;

    @Size(max = 20)
    private String newPassword;

    @Size(max = 20)
    private String confirmNewPassword;

    // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

编码映射

@Qualifier
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface EncodedMapping {
}
Run Code Online (Sandbox Code Playgroud)

密码编码器映射器

public class PasswordEncoderMapper {
    protected final PasswordEncoder passwordEncoder;

    public PasswordEncoderMapper(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    @EncodedMapping
    public String encode(String value) {
        return passwordEncoder.encode(value);
    }
}
Run Code Online (Sandbox Code Playgroud)

用户映射器

@Mapper(config = MapperConfig.class, componentModel = "spring", …
Run Code Online (Sandbox Code Playgroud)

spring-boot mapstruct

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

Spring Boot:异步方法未在单独的线程中运行

我想在单独的线程中运行一个方法。因此我尝试使用@Async但它不起作用。打印输出始终引用相同的线程 ID。

我的应用程序.java

@SpringBootApplication
@EnableAsync
@EnableConfigurationProperties(ConfigProperties.class)
public class MyApp {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(MyApp.class, args);
    }

    @Bean("threadPoolTaskExecutor")
    public TaskExecutor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.setMaxPoolSize(1000);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("Async-");
        return executor;
    }

}
Run Code Online (Sandbox Code Playgroud)

MyService.java

@Slf4j
@Service
public class MyService implements ISichtServiceBroker {

@Inject
public MyService(Helper helper) {
    this.helper = helper;
}

@Transactional
public void handle(Message message) {
    System.out.println("Execute method synchronously - " + Thread.currentThread().getName());
    handleAsync(message);
}

@Async("threadPoolTaskExecutor")
public void handleAsync(Message message) {
    System.out.println("Execute method …
Run Code Online (Sandbox Code Playgroud)

asynchronous spring-boot

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

Hibernate 不使用 JPA 实体创建 PostgreSQL 模式对象

我正在尝试使用 JPA 实体来创建数据库架构。但是 hibernate 没有创建我尝试创建表的指定架构。以下是我的代码

package io.spring.models;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "brands", schema = "production")
public class Brand implements Serializable {

    private static final long serialVersionUID = -7234173905789565680L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "brand_id")
    private Integer brandId;

    @Column(name = "brandName")
    private String brandName;


    public Integer getBrandId() {
        return brandId;
    }

    public void setBrandId(Integer brandId) {
        this.brandId = brandId;
    }

    public String getBrandName() {
        return brandName;
    } …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa hibernate-mapping spring-data postgresql-9.4

1
推荐指数
1
解决办法
1995
查看次数

重构以获得最佳 Kotlin

我有这段验证代码,并且认为它不符合 Kotlin 的精神,

在这段代码中,我与数据类内容网络人员进行了比较:网络人员工作人员:网络人员

    if (networker.name != worker.name && networker.name != null) {
        worker.name = networker.name
    }
    if (networker.lastName != worker.lastName && networker.lastName != null) {
        worker.lastName = networker.lastName
    }
    if (networker.phone != worker.phone && networker.phone != null) {
        worker.phone = networker.phone
    }
    if (networker.email != worker.email && networker.email != null) {
        worker.email = networker.email
    }
Run Code Online (Sandbox Code Playgroud)

请问如何用更好更优雅的 Kotlin 代码来改进这个

kotlin

0
推荐指数
1
解决办法
67
查看次数