在我的SpringBoot应用程序中,我正在使用CrudRepo。我发现返回值有问题:必需!=找到
GitHub:https : //github.com/einhar/WebTaskManager/tree/findById-problem
无论将方法返回类型从“任务”更改为“对象”->“ IDE都停止显示错误”,但由于稍后验证数据类型而可能会出现问题。
你知道怎么解决吗?有什么提示吗?
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) 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)