小编ehr*_*ehr的帖子

CRUD存储库findById()不同的返回值

在我的SpringBoot应用程序中,我正在使用CrudRepo。我发现返回值有问题:必需!=找到

GitHub:https : //github.com/einhar/WebTaskManager/tree/findById-problem

无论将方法返回类型从“任务”更改为“对象”->“ IDE都停止显示错误”,但由于稍后验证数据类型而可能会出现问题。

你知道怎么解决吗?有什么提示吗?

CrudRepo

public interface TaskRepository extends CrudRepository<Task, Integer> {}
Run Code Online (Sandbox Code Playgroud)

服务

@Service
@Transactional
public class TaskService {

    @Autowired
    private final TaskRepository taskRepository;

    public TaskService(TaskRepository taskRepository) {
        this.taskRepository = taskRepository;
    }

    public List<Task> findAll() {
        List<Task> tasks = new ArrayList<>();
        for (Task task : taskRepository.findAll()) {
                tasks.add(task);
        }
        return tasks; // Work properly :)
    }
    /* ... */
    public Task findTask(Integer id) {
        return taskRepository.findById(id); // Find:Task | Required: java.util.Optional :(
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring crud

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

How to grep regex1 OR regex2?

I would like to grep (on ubuntu18.04) a every line that fits the pattern that "at least one of two number is greater than 0".

I found infomation about '|' usage in regex but I see it does not work here.

One of tried option:

grep -E "Foo:[1-9]+ | Bar:[1-9]+" input
Run Code Online (Sandbox Code Playgroud)

which returns:

grep -E "Foo:[1-9]+ | Bar:[1-9]+" input
Run Code Online (Sandbox Code Playgroud)

and that is invalid cause it matches only Bar:[1-9]+

Input data:

Foo:1, Bar:1
Foo:0, Bar:1
Run Code Online (Sandbox Code Playgroud)

Expected result in a solution:

Foo:1, …
Run Code Online (Sandbox Code Playgroud)

regex bash grep

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

标签 统计

bash ×1

crud ×1

grep ×1

java ×1

regex ×1

spring ×1