问题列表 - 第317973页

如何实现给定类型的泛型方法?

我有一个java接口,像这样:

public interface ScheduleControllerInterface {

    <T extends ScheduleAddUpdateDTO> CommonResult<String> commit(@Valid T commitDTO);
}  

Run Code Online (Sandbox Code Playgroud)

现在,我想实现这个接口,并给泛型类型一个类型,如下所示:

public class CarScheduleController implements ScheduleControllerInterface {

    @Override
    public CommonResult<String> commit(CarScheduleDTO commitDTO) {
        carSchedule.commitSchedule(commitDTO);
        return CommonResult.success();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试它时,它调用我没有重写方法,我的接口有很多通用方法,我想实现它,我能做什么?

桌子设计

java generics

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

如何在反应函数内保留程序反应性?

我正在开发一个基于 python 的闪亮应用程序,用于通过串行传输线驱动流体泵。配置具有设定幅度和运行时间的流量曲线后,可以通过按操作按钮“p1”启动串行传输。

我面临的问题是与按钮“p1”相关的内部缺乏反应性reactive.event(input.p1):我想确保通过单击“p1”开始传输,从而触发可以reactive.event(input.p1)随时通过单击“p2”终止传输。

然而,当前的实现导致停止消息 inreactive.event(input.p2)排队并在传输reactive.event(input.p1)结束后发送。

我怎样才能解决这个问题?有什么方法可以确保我的程序仍然对其他输入做出反应?我希望单击“p2”后立即停止传输。两个按钮的实现都放在下面。

@reactive.Effect
@reactive.event(input.p1)
def _():
    y = yg.get() # fetch np.array y from reactive value yg, numbers in y correspond to driving voltages

     for e in y: # iterate over array
         msg = "1:1:"+str(e)+":100" # formatted string containing the driving voltage
         #print(msg) # print to console in debug mode
         ser.write(bytes(msg,'utf-8')) # send the formatted string
         t0 = time.time() # time stamp
        
         while(((time.time()-t0)<=2)): # next driving voltage …
Run Code Online (Sandbox Code Playgroud)

python reactive-programming py-shiny

5
推荐指数
1
解决办法
191
查看次数

在 C 中,如果我使用数组作为函数的参数,则数组大小没有意义,因为数组名作为指针

据我所知

int func(int arr[5]) {
    printf("Test");
}
Run Code Online (Sandbox Code Playgroud)

方括号中的数组大小(例如 5)没有任何意义,因为 arr 只是指向数组第一个元素的指针,即它与

int func(int *arr) {
    printf("Test");
}
Run Code Online (Sandbox Code Playgroud)

或者

int func(int arr[]) {
    printf("Test");
}
Run Code Online (Sandbox Code Playgroud)

但是,如果数字本身没有任何意义,为什么可以在方括号中写入像 5 这样的数字呢?

c arrays size

2
推荐指数
1
解决办法
85
查看次数

Django:使用 Q 对象进行列表理解

据我所知,您可以创建一个过滤器列表,然后只需在 filter() 或 except() 方法中解压该列表即可。看起来超级方便。

我尝试这样做:

words_to_exclude = ['one', 'two', 'three']
excluded_clauses = [Q(title__icontains=word) for word in words_to_exclude]
search_result = MyObject.objects.exclude(*excluded_clauses)
Run Code Online (Sandbox Code Playgroud)

查询有效,但有一个问题。如果我使用此方法创建过滤器列表,则此列表(excluded_clauses)将如下所示:

[<Q: (AND: ('title__icontains', 'one'))>, <Q: (AND: ('title__icontains', 'two'))>, <Q: (AND: ('title__icontains', 'three'))>]
Run Code Online (Sandbox Code Playgroud)

这些是带有 AND 运算符的 Q 对象,因此查询集将仅排除不包含所有单词的对象。我需要它来排除标题包含任何单词的结果,所以我需要 OR 运算符。我可以手动更改 Q 对象中的运算符吗?或者没有办法像这样使用列表理解?抱歉,我知道如何手动编写过滤器,但我需要这个来实现参数数量未指定的过滤器函数。

python django

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

Blazor、.Net 8 和身份的全局交互问题

我一直在使用新的 .Net 8 Blazor 模板,并遇到了身份验证和设置全局 InteractiveServer 渲染模式的问题。我所做的更改是在 App.Razor 文件中更改为:

<Routes @rendermode="InteractiveServer" />
Run Code Online (Sandbox Code Playgroud)

我添加此内容的原因是因为我还尝试集成 MudBlazor,这是它正常运行所必需的(至少据我所知)。MS 确实通过文档列出了执行此操作的能力,因此似乎是设置此全局渲染模式的合理选择。

然后我面临的问题是使用 AccountLayout 组件的任何页面,例如登录、注册、重置密码等,因为它在这部分循环:

if (HttpContext is null)
{
    // If this code runs, we're currently rendering in interactive mode, so there is no HttpContext.
    // The identity pages need to set cookies, so they require an HttpContext. To achieve this we
    // must transition back from interactive mode to a server-rendered page.
    NavigationManager.Refresh(forceReload: true);
}
Run Code Online (Sandbox Code Playgroud)

由于它是全局设置的,因此它总是会被点击,因此会进入无限的导航循环。我尝试设置帐户布局和/或帐户页面以使用 null、默认、静态等渲染模式,但它们似乎不是有效的选项,我也找不到任何人这样做的示例。

所以我的问题是,有谁知道一种在渲染模式组件上设置默认/静态的方法,或者知道一种让 MudBlazor 在 .net 8 项目中工作而不使用全局交互模式的方法?我显然已经尝试使用 mudblazor 将渲染模式设置为在相关页面上进行交互。

identity blazor mudblazor .net-8.0

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

如何在 NextJS 中使用 Suspense 的多个 useSWR 钩子?

我有一个 NextJS 项目,我尝试使用 SWR 来获取数据。我的问题是:

useSWR当我在一个组件中使用两个以上的-hooks 时,我会收到以下钩子错误:

  • Warning: React has detected a change in the order of Hooks called by ComponentExample. This will lead to bugs and errors if not fixed.
  • Uncaught Error: Update hook called on initial render. This is likely a bug in React. Please file an issue.

这是最小复制代码存储库:https ://github.com/LarsFlieger/swr-suspense-multiple

我正在Component.tsx尝试进行 3 次提取并控制台记录输出:

"use client";

import useSWR from "swr";

const fetchWithDelay = async (url: string) => {
    const delay = parseInt(url) * 1000;
    await …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs next.js react-suspense

10
推荐指数
0
解决办法
370
查看次数

解决“c-source”名称和 GHC RTS 名称之间的冲突

我有一些使用 FFI 从 Haskell 调用的 C 源代码ccall。为了使构建过程尽可能简单,我想使用 Cabal 编译 C 文件,因此我已将源代码添加到c-sources我的.cabal文件部分。

问题是我导入 Haskell 的 C 函数是根据另一个名为 的 C 函数(我没有直接从 Haskell 使用)来实现的allocate,这会导致链接时发生冲突:

ratkai> [16 of 16] Linking .stack-work/dist/x86_64-linux/Cabal-3.8.1.0/build/ratkai-tvc/ratkai-tvc [Objects changed]
ratkai> /usr/bin/ld.gold: error: /home/cactus/.ghcup/ghc/9.4.5/lib/ghc-9.4.5/lib/../lib/x86_64-linux-ghc-9.4.5/rts-1.0.2/libHSrts-1.0.2.a(Storage.o): multiple definition of 'allocate'
ratkai> /usr/bin/ld.gold: .stack-work/dist/x86_64-linux/Cabal-3.8.1.0/build/ratkai-tvc/ratkai-tvc-tmp/import/ZX0/src/memory.o: previous definition here
ratkai> collect2: error: ld returned 1 exit status
ratkai> ghc-9.4.5: `gcc' failed in phase `Linker'. (Exit code: 1)
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题,而无需修补导入的 C 库来重命名其allocate函数?

linker haskell ffi ghc

6
推荐指数
0
解决办法
46
查看次数

为什么没有为 Date 对象定义 cummin/cummax 以及临时数字转换是否存在危险?

cummin/cummax不能用于 Date 对象。这会触发Error in Math.Date(x): cummax not defined for "Date" objects.

我想知道这背后的原因是什么,因为我认为完全有可能确定日期的累积最小值/最大值。特别是因为最小/最大是为日期对象定义的,所以这个限制似乎是任意的。

这里描述的解决方案是使用zoo::rollapplyr()或临时转换。

问题

  1. cummin/cummax未定义日期的原因是什么?
  2. 临时转制是否存在风险?我可以想到有关精度或起源的问题,但我缺乏创造力,在这种情况下确实会出现问题。

代码

示例数据

x <- as.Date(c("2022-01-01", "2023-01-01", "1900-01-01", "2024-01-01"),
             origin = "1970-01-01")
Run Code Online (Sandbox Code Playgroud)

直接使用

# not working
cummax(x)
#> Error in Math.Date(x): cummax not defined for "Date" objects
cummin(x)
#> Error in Math.Date(x): cummin not defined for "Date" objects
Run Code Online (Sandbox Code Playgroud)

使用 {zoo}rollapplyr()

zoo::rollapplyr(x, FUN = min, width …
Run Code Online (Sandbox Code Playgroud)

r date

2
推荐指数
1
解决办法
129
查看次数

为什么基于 Alpine Linux 的 Docker 镜像无法找到在绝对路径下执行的命令?

我是 Docker 新手。我想容器化一个小环境,以便可以运行可执行文件,但我陷入困境,因为我什至无法运行可执行文件。

我的文件夹结构如下所示:

example/
|-Dockerfile
|-hello_world
Run Code Online (Sandbox Code Playgroud)

我的Dockerfile看起来像这样:

# Use Alpine Linux as the base image
FROM alpine:latest

# Set the working directory inside the container
WORKDIR /app

# Copy the executable to the container
COPY hello_world /app/

# Set the permissions for the executable
RUN chmod +x /app/hello_world

# Define the command to run your server when the container starts
ENTRYPOINT ["/app/hello_world"]
Run Code Online (Sandbox Code Playgroud)

然后我运行:

> sudo docker build -t example .

> sudo docker run --name example_container example …

unix rust docker dockerfile alpine-linux

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

调整ggplot2中几个饼图的大小

library(dplyr)
library(ggplot2)

df <- data.frame(Subjects = c("Literature", "Literature", "Geography", "Geography", "Arts", "Arts", 
                              "English", "English", "Math", "Math", "History", "History", 
                              "Biology", "Biology", "French", "French"),
                 Sex = rep(c("Girls", "Boys"), 2),
                 N = c(15, 20, 30, 22, 77, 40, 14, 17, 
                       80, 78, 52, 65, 32, 56, 89, 41)) |>
  group_by(Subjects) |>
  mutate(pct = proportions(N) * 100) |>
  mutate_at(vars(pct), list(~ round(., 1))) |>
  ungroup()

df |>
  ggplot(aes(x = "", y = pct, fill = Sex)) +
  geom_bar(stat = "identity", width = 1, color = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

2
推荐指数
1
解决办法
34
查看次数