在其他类似的关于如何捕获EntityNotFoundException主要提示的问题中,主要提示是使用返回 null 的更简单的方法,例如getOne
从 spring-boot v 2.7 + 开始,两者getOne()都getById()被标记为已弃用,并且文档说可以使用getReferenceById。
正如其他问题中提到的问题,您不能简单地捕获javax.persistence.EntityNotFoundException.
这永远不会被抓住:
fun getDonation(donationId: Long): DonationDto? {
return try {
val entity: DonationEntity = donationJpaRepository.getById(donationId)
mapper.toDonationDto(entity)
} catch (e : EntityNotFoundException) {
null
}
}
Run Code Online (Sandbox Code Playgroud)
除了降级版本并继续我的生活之外,我如何捕获异常或处理未找到的实体?
我刚刚在 flutter 中开始一个新项目,并且对它完全陌生。
Flutter 中定义主题的惯例是什么?
我想要一个带有主题的单独文件以保持简单main.dart。有没有好的/正确的/经典的方法来做到这一点?
目前我的main.dart样子是这样的:
void main() => runApp(MaterialApp(
initialRoute: '/',
theme: ThemeData(
appBarTheme: AppBarTheme(
color: Colors.teal,
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.teal,
)),
scaffoldBackgroundColor: Colors.grey[200],
textTheme: TextTheme(
bodyText1: TextStyle(),
bodyText2: TextStyle(),
).apply(
bodyColor: Colors.teal[800],
)),
routes: {
'/': (context) => Loading(),
'/home': (context) => Home(),
'/alarms': (context) => SetUpAlarm(),
},
));
Run Code Online (Sandbox Code Playgroud) 我得到了一组元素。任务是获取唯一元素的数量。我写了以下内容:
import numpy as np
tokens1 = set(["a", "b", "c", "c"])
print(np.unique(tokens1))
print(np.unique(tokens1).size)
Run Code Online (Sandbox Code Playgroud)
结果是
[{'c', 'b', 'a'}]
1
Run Code Online (Sandbox Code Playgroud)
我如何获得正确的数字 - 3?我应该首先使用 np.unique 以外的东西吗?可能有更好的方法来获得我想要的帽子。