小编Dia*_*ana的帖子

JPA 和已弃用的 getOne() 和 getById() -> 如何在 getReferenceById 中捕获 EntityNotFoundException

在其他类似的关于如何捕获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)

除了降级版本并继续我的生活之外,我如何捕获异常或处理未找到的实体?

jpa kotlin spring-boot

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

Flutter:将主题(ThemeData)移动到单独的文件

我刚刚在 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)

themes styles dart flutter

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

使用 np.unique Python 后获取元素数

我得到了一组元素。任务是获取唯一元素的数量。我写了以下内容:

 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 以外的东西吗?可能有更好的方法来获得我想要的帽子。

python size numpy unique

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

标签 统计

dart ×1

flutter ×1

jpa ×1

kotlin ×1

numpy ×1

python ×1

size ×1

spring-boot ×1

styles ×1

themes ×1

unique ×1