AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-3935035

four-eyes's questions

Martin Hope
four-eyes
Asked: 2024-12-31 19:19:23 +0800 CST

Spring data JPA 使用基于滚动的查询和操作优先级返回意外结果

  • 6

我有这些实体

@Entity
@Table(name = "Item")
class Item(
    @Column(name = "name", nullable = false)
    var name: String,

    @Column(name = "added_date", columnDefinition = "TIMESTAMP WITH TIME ZONE", nullable = true)
    var addedDate: ZonedDateTime? = null,

    @Column(name = "duration", nullable = true)
    var duration: Int? = null,

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "head_of_id", nullable = false)
    val headOf: HeadOf,
) {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long = 0
}


@Entity
@Table(name = "head_of")
class HeadOf(
    @Column(name = "company", nullable = false)
    var company: String,

    @Column(name = "city", nullable = false)
    var city: String,

    @Column(name = "age", nullable = true)
    var age: Int?
) { 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long = 0
}

这是相应的存储库

interface ItemRepository : JpaRepository<Item, Long> {
    fun findByHeadOfIdAndAddedDateNotNullOrDurationNotNull(
        headOfId: Long,
        position: ScrollPosition,
        pageable: Pageable,
    ): Window<Item>
}

这是当前表格中的内容Item。它是一行(它是的结果dump)

INSERT INTO public.item VALUES (1, 'Some fancy title', '2024-12-31 07:14:42.955789+00', NULL, 1000);

如你所见,headOf是1000L。

现在,当我findByHeadOfIdAndAddedDateNotNullOrDurationNotNull使用以下值调用此函数时

headOfId: 0 scrollPosition: ScrollPosition.of(…) PageRequest.of(0, 10)

它返回其中的一行。我没有想到这一点,因为headOfId我传递的是0L而不是1000L。

我无法使用@Query注释,然后我得到了这个

无法为公共抽象 org.springframework.data.domain.Window org...jpa.repository.ItemRepository.findByHeadOfIdAndAddedDateNotNullOrDurationNotNull(long,org.springframework.data.domain.ScrollPosition,org.springframework.data.domain.Pageable); 创建查询 原因:使用基于字符串的查询不支持滚动查询

有办法解决这个问题吗?

java
  • 1 个回答
  • 99 Views
Martin Hope
four-eyes
Asked: 2024-12-06 15:24:05 +0800 CST

动态向接口添加具有类型的属性

  • 5

我有这个界面

interface Base {
    common: {
        foo: string,
    }
}

interface ExtendedOne extends Base {
    count: number,
}

interface ExtendedTwo extends Base {
    origin: string,
}

现在,我想要的是通过interface的定义ExtendedOne并向来自 的 propExtendedTwo添加另一个属性和类型。commonBase

因此可以说(伪代码)

interface ExtendedOne extends Base {
    count: number,
    common: {
        ...Base,
        anotherProp: boolean,
    }
}

interface ExtendedTwo extends Base {
    origin: string,
    common: {
        ...Base,
        anotherProp: number,
    }
}

添加的道具总是会有相同的名称(此处anotherProp),但类型会有所不同。

如果需要的话,可以将接口更改为类型。

typescript
  • 1 个回答
  • 18 Views
Martin Hope
four-eyes
Asked: 2024-12-06 14:50:49 +0800 CST

无法将元素推送到联合类型数组中

  • 5

我有这个代码

export interface CommonAnimalProps {
    name: string
  
}

export interface DogResponse extends CommonAnimalProps {

}

export interface CatResponse extends CommonAnimalProps {
    color: string,
}

export type AllAnimals = (DogResponse[] | CatResponse[])

export interface AllAnimalsProps {
    height: number | null,
    errorCodes: number[] | null,
    uuid?: string,
    [ANIMALS.dog]?: DogResponse[],
    [ANIMALS.cat]?: CatResponse[],
}

export enum ANIMALS {
    dog = 'dog',
    cat = 'cat'
}

export const transformCalculatedEmissionsResponse = (response: AllAnimalsProps): AllAnimals => {
    const result: AllAnimals = [];
    (Object.values(ANIMALS) as ANIMALS[]).map(animal => {
        const bars = response[animal]
        if (Array.isArray(bars)) {
            bars.map(bar => result.push(bar))
        }
    })
    return result
}

并且它在这条线上失败了

bars.map(bar => result.push(bar))

无结果 类型为“DogResponse | CatResponse”的参数无法分配给类型为“CatResponse”的参数。类型为“DogResponse”的参数缺少属性“color”,但类型为“CatResponse”的参数是必需的。

为什么以及如何解决这个问题?

这里是广场

typescript
  • 2 个回答
  • 37 Views
Martin Hope
four-eyes
Asked: 2024-12-02 16:03:57 +0800 CST

带有密封接口的详尽 when 语句不适用于 MappedSuperclass、Entity 和密封接口

  • 6

我有这个 MappedSuperClass

@MappedSuperclass
abstract class BaseFoo(
    ...
) : FooItem {
    ...
}

sealed interface FooItem

然后像这样使用

@Entity
@Table(name = "bar_1")
class Bar1(
    ...
) : BaseFoo(
    ...
) { ... }


@Entity
@Table(name = "bar_2")
class Bar2(
    ...
) : BaseFoo(
    ...
) { ... }


@Entity
@Table(name = "all_bar")
class AllBar(
    ...

    @OneToMany(mappedBy = "all_bar", fetch = FetchType.LAZY, cascade = [CascadeType.REMOVE])
    val bar1: List<Bar1>? = null,

    @OneToMany(mappedBy = "all_bar", fetch = FetchType.LAZY, cascade = [CascadeType.REMOVE])
    val bar2: List<Bar2>? = null,
) {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long = 0

    val barItems: List<FooItem>
        get() = listOfNotNull(bar1, bar2).flatten()
}

然后我想添加一个详尽的 when 语句

val bars = allBarRepository.findById(someId).getOrElse {...}
bars.barItems.forEach {
    when (it) {
        is Bar1 -> ...
        is Bar2 -> ...
    }

但是编译器说

‘when’ 表达式必须详尽无遗,请添加必要的‘is BaseFoo’ 分支或‘else’ 分支

我不想检查BaseFoo,而只想检查Bar1和Bar2以及将来是否Bar_<INT>会添加所有其他 Bar。我希望当我忘记添加任何内容时,编译器会发出警告Bar_<INT>。通过添加else分支或检查BaseFoo这不再有效。我认为这sealed interfaces可以用于什么?

kotlin
  • 1 个回答
  • 23 Views
Martin Hope
four-eyes
Asked: 2024-09-20 19:44:28 +0800 CST

在 TypeScript 中向派生类型添加另一个值

  • 6

我有这些界面

interface CommonAnimalProps {
    common: {
        size: number, 
        weight: number,
        origin: string,
    }
}

interface DogProps extends CommonAnimalProps {
    name: string
}

interface CatProps extends CommonAnimalProps {
    furious: boolean
}

interface BirdProps extends CommonAnimalProps {
    canFly: boolean
}

export enum AnimalType {
    dog = "dog",
    cat = "cat",
    bird = "bird",
}

export interface AnimalTypeToAnimalPropsMap {
    [AnimalType.dog]: (DogProps)[],
    [AnimalType.cat]: (CatProps)[],
    [AnimalType.bird]: (BirdProps)[]
}

export type AllAnimalValues<T> = T[keyof T]
export type AllAnimalTypesArray = AllAnimalValues<AnimalTypeToAnimalPropsMap>
export type AllAnimalTypes = AllAnimalValues<AnimalTypeToAnimalPropsMap>[0]
export type AllAnimalTypesArrayDiscriminating = AllAnimalTypes[]

这AllAnimalTypesArrayDiscriminating将导致数组看起来像这样

const foo: AllAnimalTypesArrayDiscriminating = [
    {
        name: "Bello",
        common: {
            size: 10,
            weight: 25,
            origin: "Knowhwere"

        },
    },
    {
        furious: true,
        common: {
            size: 3,
            weight: 5,
            origin: "Anywhere"

        },
    },
    {
        canFly: false,
        common: {
            size: 39,
            weight: 50,
            origin: "Somewhere"

        },
    },    
]

是否可以使用AllAnimalTypesArrayDiscriminating并从中创建一个新的类型/接口(AllAnimalTypesArrayDiscriminatingModified),其中结果数组中的每个元素bar都有另一个 prop(color: string)添加,CommonAnimalProps以便结果如下所示

const bar: AllAnimalTypesArrayDiscriminatingModified = [
  {
    name: "Bello",
    common: {
      size: 10,
      weight: 25,
      origin: "Knowhwere",
      color: 'red',

    },
  },
  {
    furious: true,
    common: {
      size: 3,
      weight: 5,
      origin: "Anywhere",
      color: 'brown',

    }
  }, {
    canFly: false,
    common: {
      size: 39,
      weight: 50,
      origin: "Somewhere",
      color: 'white',

    },
  }
];

请注意,我无法修改原始内容CommonAnimalProps以将其添加color为可选参数。我也无法编辑DogProps, CatProps, BirdProps。我正在寻找一种使用AllAnimalTypesArrayDiscriminating(或任何其他我未排除的类型)来添加此属性的方法。有办法做到这一点吗?

typescript
  • 1 个回答
  • 48 Views
Martin Hope
four-eyes
Asked: 2024-07-25 21:34:16 +0800 CST

XCode 更新后模拟器消失

  • 5

我正在运行版本 15.4 (15F31d)。昨天我安装了一个更新,再次打开 XCode,出现一条消息,如“模拟器需要更新”。我点击了确定,什么也没发生。现在,我所有的模拟器都消失了,我无法找回它们。我已经重新启动了 XCode 和我的电脑。

在这里,在我安装更新之前,我可以选择不同的模拟器

模拟器选择

当我点击“管理运行目标...”时,它看起来是这样的。它们都选择“显示运行目标:始终”

管理跑步目的地

Product - Destination在我已经选择的菜单下Show all run destinations。

我不明白的是,我可以启动模拟器应用程序

模拟器应用程序

但是 XCode 无法识别任何模拟器......

当我连接 iPhone 时,它​​没有显示在这里

模拟器选择

但我可以在这里看到

物理设备

我也尝试从命令行运行它

$ xcrun simctl list devices

这给了我

    iPhone Xs (6723AC4A-4B19-46F5-BAE5-6C3DF2BC253B) (Shutdown)
    iPhone SE (3rd generation) (CA9C9B3E-B542-412C-B845-71A0B7D9D797) (Booted)
    iPhone SE (3rd generation) (DB2FF536-D849-4786-B3BD-8FB7068F212A) (Shutdown)
    iPhone 15 (B039DEC7-D015-4313-A7D9-2CB2324E232B) (Shutdown)
    iPhone 15 Plus (797BBF51-A7A9-4F41-A532-424B775AB14D) (Shutdown)
    iPhone 15 Pro (36E9933C-D4FB-4818-B4EA-F3ADE9BC5AFF) (Shutdown)
    iPhone 15 Pro Max (4CDB180C-79F2-4827-B2AB-256F1812FE98) (Shutdown)
    iPad Air (5th generation) (AE3E77BB-137D-42EC-B2C0-2179320216F6) (Shutdown)
    iPad (10th generation) (8FD9CB57-CEBA-4570-B7F0-FDEFAAF20683) (Shutdown)
    iPad mini (6th generation) (0B6E1473-1864-49B0-BB91-4A2C4F692424) (Shutdown)
    iPad Pro (11-inch) (4th generation) (6B9E5069-A52A-4772-96D9-68FFCF496BEC) (Shutdown)
    iPad Pro (12.9-inch) (6th generation) (1E45FFF9-E844-4EFC-9938-59C80F8721D7) (Shutdown)

然后我跑

$ yarn ios --udid "CA9C9B3E-B542-412C-B845-71A0B7D9D797"

返回

error Failed to build iOS project. "xcodebuild" exited with error code '70'. To debug build logs further, consider building your app with Xcode.app, by opening 'Foo.xcworkspace'.
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace Foo.xcworkspace -configuration Debug -scheme Foo -destination id=CA9C9B3E-B542-412C-B845-71A0B7D9D797

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES


2024-07-25 15:38:32.989 xcodebuild[2255:51186] Writing error result bundle to /var/folders/_j/5k_qtwqn5k39srgfty_40xmc0000gp/T/ResultBundle_2024-25-07_15-38-0032.xcresult
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
        { id:CA9C9B3E-B542-412C-B845-71A0B7D9D797 }

    Ineligible destinations for the "Foo" scheme:
        { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device, error:iOS 17.5 is not installed. To use with Xcode, first download and install the platform }

error Command failed with exit code 1.

为什么我不能再在模拟器上运行我的应用程序了?我的应用程序iOS Deployment target设置为13...

  • 1 个回答
  • 22 Views
Martin Hope
four-eyes
Asked: 2024-07-25 15:29:06 +0800 CST

在 IntelliJ 中返回上一个文件的快捷方式

  • 3

我找不到可以让我回到上一个文件的快捷方式。我知道这一点,但是,这太过精细了。它总是跳转到上一个光标位置。如果我在文件中多次移动光标,这意味着我必须经过所有这些位置才能转到我来自的文件。我希望能够直接转到我来自/之前所在的文件。

有捷径吗?

intellij-idea
  • 1 个回答
  • 15 Views
Martin Hope
four-eyes
Asked: 2024-07-23 15:07:35 +0800 CST

在 Spring Data JPA 中使用动态列名

  • 4

我正在尝试在 Spring Data JPA 中的查询中使用动态列名和值

interface CustomFooRepository {
    fun findByValueIgnoreCase(query: String, type: RequestType): List<Foo>
}

class CustomFooRepositoryImpl(
    @PersistenceContext private val entityManager: EntityManager
) : CustomFooRepository {

    override fun findByValueIgnoreCase(query: String, type: RequestType): List<Foo> {
        val column = when (type) {
            RequestType.first_name -> "first_name"
            RequestType.last_name -> "last_name"
            RequestType.email -> "email"
        }

        val sql = """
            SELECT 
                *,
                SIMILARITY(:column, :query) AS score
            FROM foo
            WHERE :column iLIKE %:query%
            ORDER BY score DESC NULLS LAST, :column
            LIMIT 20;
        """

        val constructedQuery = entityManager.createNativeQuery(sql, Foo::class.java)
        constructedQuery.setParameter("column", column)
        constructedQuery.setParameter("query", query)
        return constructedQuery.resultList as List<Foo>
    }
}


interface FooRepository : JpaRepository<Foo, Long>, CustomFooRepository

但这让我

org.springframework.dao.InvalidDataAccessResourceUsageException:没有命名参数':query%'的参数

为什么?

java
  • 1 个回答
  • 44 Views
Martin Hope
four-eyes
Asked: 2024-07-15 15:07:01 +0800 CST

限制 Spring Scroll Api 返回的结果

  • 4

我想从 Spring 实现滚动 API。这样,当用户在前端滚动时,前端每次发出请求时都会加载新数据。

我尝试限制 Spring 返回的结果,并且正在尝试各种方法。

  1. 页面请求
    // Service
    fun getOrders(customerId: Long): List<OrderDto> {
        val customer = customerRepository.findById(customerId).getOrElse { return emptyList() }
        val orders: WindowIterator<Order> = WindowIterator.of<Order> { position ->
            orderRepsitory.findAllByCustomerOrderByCreated(
                 customer, 
                 position as KeysetScrollPosition?,
                 PageRequest.of(0, 20)
            )
        }
            .startingAt(ScrollPosition.keyset())
        val ordersResult: MutableList<Orders> = ArrayList<Orders>()
        orders.forEachRemaining { ordersResult.add(it) }
        return ordersResult.map {
            OrderDto(...)
        }
    }


    // Order Respository
    interface OrderRepository : JpaRepository<Order, Long> {
    fun findAllByCustomerOrderByCreated(
        customer: Customer, 
        position: KeysetScrollPosition?,
        pageable: Pageable,
        ): Window<Order>
    }

这总是返回整个表。

  1. 调整 JPA 查询
    // Order Respository
    interface OrderRepository : JpaRepository<Order, Long> {
    fun findFirst5ByCustomerOrderByCreated(
        customer: Customer, 
        position: KeysetScrollPosition?,
        ): Window<Order>
    }


    // call to repository in service
    orderRepsitory.findFirst5ByCustomerOrderByCreated(
        customer, 
        position as KeysetScrollPosition?
    )

结果相同,它返回整个表。

  1. 使用限制
    // Order Respository
    interface OrderRepository : JpaRepository<Order, Long> {
    fun findAllByCustomerOrderByCreated(
        customer: Customer, 
        limit: Limit,
        ): Window<Order>
    }

    // call to repository in service
    orderRepsitory.findAllByCustomerOrderByCreated(
        customer, 
        position as KeysetScrollPosition?,
         Limit.of(20)
    )

结果相同,它返回整个表。

如何使用 Spring Scroll API 限制结果?

java
  • 1 个回答
  • 28 Views
Martin Hope
four-eyes
Asked: 2024-02-01 19:06:54 +0800 CST

使用已定义的类创建“联合类型”

  • 5

我有两个classesDTO

class FooDto (
    val a: String,
    val b: Double,
)

class BarDto (
    val c: String,
    val d: String,
)

现在,我想定义第三个AnotherDto,将属性的类型设置为BartDto或FooDto。

class AnotherDto (
    val e: FooDto || BarDto
)

这显然是行不通的。我读到,sealed classes它看起来像这样

sealed class Menu{
   data class PIZZA(val name: String, val size:String, val quantity:Int):Menu()
   data class BURGER(val quantity:Int, val size:String): Menu()
   data class CHICKEN(val quantity:Int, val pieces:String):Menu()
}

但是,这需要我再次定义所有变量(例如name: String和quanitity: Int)。这不是我想要的,我只是想重用我之前定义的FooDto而不BarDto重复。

所以这

sealed class FooBar{
   data class Foo(val a: String, val b: Double):FooBar()
   data class Bar(val c: String, val d: String): FooBar()
}

有点毫无意义,因为我FooDto已经BarDto写过并且它们在其他地方使用。我想要这样的东西

sealed class FooBar{
   FooDto:FooBar()
   BarDto: FooBar()
}

这显然是行不通的。

如何重用我已经编写的DTOsFooDto并BarDto创建一个“联合类型”,我可以将其作为数据类型分配给 Kotlin 中的变量?

kotlin
  • 2 个回答
  • 35 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve