小编Ami*_*iri的帖子

Dapper:是否可以自定义特定类型的特定字段的类型映射?

假设我有这User门课:

public class User
{
    public int      ID          { get; set; }
    public string   FirstName   { get; set; }
    public string   LastName    { get; set; }
    public string   Email       { get; set; }
    public DateTime DateCreated { get; set; }
    public DateTime LastLogin   { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想将其映射到下表:

CREATE TABLE "user" (
  "ID"          int(11) NOT NULL AUTO_INCREMENT,
  "FirstName"   varchar(45) DEFAULT NULL,
  "LastName"    varchar(45) DEFAULT NULL,
  "Email"       varchar(255) NOT NULL,
  "DateCreated" int(11) NOT NULL,
  "LastLogin"   int(11) NOT NULL, …
Run Code Online (Sandbox Code Playgroud)

c# sql dapper micro-orm

6
推荐指数
2
解决办法
2万
查看次数

NancyFx:将默认字符集设置为utf8

我在我的cshtml文件中有这个片段:

Expires on: @Model.EndDate.ToString("MMM dd yyyy")
Run Code Online (Sandbox Code Playgroud)

我在回复中得到了这个:

HTTP/1.1 200 OK
Content-Type: text/html

...
Expires on: ?????™ 05 2013
Run Code Online (Sandbox Code Playgroud)

如何告诉Nancy默认使用UTF8进行响应?


编辑:为了澄清,这不是一个本地化问题,输出已经本地化 - 只是本地化的UTF8字符串被发送到没有UTF8字符集声明的客户端,所以它被搞砸,试图将其视为latin1 .

我要找的是这个:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

...
Run Code Online (Sandbox Code Playgroud)

而且我不想单独为每个响应指定它.

我正在使用NancyFx Web框架

c# nancy

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

Spring boot gradle插件强制Mockito版本

我大致有以下设置:

test-utils/build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

dependencies {
    compile ('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.mockito'
        exclude group: 'org.hamcrest'
    }
    compile  'org.mockito:mockito-core:2.0.41-beta'
    compile  'org.assertj:assertj-core:3.3.0'
}
Run Code Online (Sandbox Code Playgroud)

main/build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

dependencies {
    testCompile project(':test-utils')
}
Run Code Online (Sandbox Code Playgroud)

但出于某种原因,似乎spring boot插件强制mockito版本回到1.x:

# ./gradlew :main:dependencies --configuration=testCompile

testCompile - Compile classpath for source set 'test'.
+--- project :test-utils
     +--- org.springframework.boot:spring-boot-starter-test: …
Run Code Online (Sandbox Code Playgroud)

java spring gradle spring-boot spring-boot-gradle-plugin

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

在没有System.Windows.Forms的情况下设置鼠标位置

有没有办法在不使用System.Windows.Forms.Cursor的情况下操纵鼠标位置?也许是互操作的东西?

原因是我们使用的是一个专门的.NET子集,它不能包含System.Windows.Forms.

c# windows mouse

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

C#无界泛型类型作为约束

是否可以使用通用约束,这是一种无界泛型类型?

例如:

public T DoSomething<T>(T dictionary) where T : IDictionary<,>
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

编辑:为了解释上下文,我想将方法​​的用法限制为IDictionary,但对于方法本身而言,TKey和TValue究竟是什么并不重要.

c# generics generic-constraints

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

D:无需复制即可将元素添加到数组中

我必须完全愚蠢,因为我无法理解这一点:如何在不复制数组的情况下向数组中添加元素.

换句话说,假设我要创建一个大的列表:

int[] arr;

while (...) { // 1,000,000 iterations
    ...
    arr ~= something;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我不太明白什么时候~=会添加到数组,什么时候会创建它的副本.

为了澄清,我正在寻找像Java或C#中的ArrayList这样的语义,即我可以把东西放进去的一些抽象容器,如果需要的话会增长,但通常保持相同的"对象"(即如果传递等).

d

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

D:不期望的匿名函数属性

考虑以下模板:

mixin template test(void function() callback)
{
    static this()
    {
        callback();
    }
}
Run Code Online (Sandbox Code Playgroud)

这有效:

mixin test!(&sort_arr);
void sort_arr()
{
    arr.sort;
}
Run Code Online (Sandbox Code Playgroud)

但是这不起作用:

mixin test!({ arr.sort; });
Run Code Online (Sandbox Code Playgroud)

DMD给出以下错误:

Error: safe function 'main.__lambda6' cannot call system function '_adSort'
Error: @nogc function 'main.__lambda6' cannot call non-@nogc function '_adSort'
Run Code Online (Sandbox Code Playgroud)

在我看来,lambda版本被推断为safe @nogc,而显式sort_arr不是.

我怎样才能克服这一点并将匿名lambda传递给此模板?


编辑:根据接受的答案中的建议提交的错误报告:https://issues.dlang.org/show_bug.cgi?id = 13481

lambda d

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

Spring AMQP:如何避免手动声明多个队列?

创建了一个基本的spring-amqp设置后,我看到对于我要发送的每种类型的消息(使用消息POJO),我需要在spring配置中声明队列.

所以对于每一对:

amqpTemplate.convertAndSend("queue1", new MessageType1(...));

@RabbitListener(queues = "queue1")
public void handleMessage(MessageType1 msg) {...}
Run Code Online (Sandbox Code Playgroud)

我需要一个Spring配置中的条目,如下所示:

<rabbit:queue name="queue1"/>
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎是多余的.如果我想到像HTTP url这样的队列,而不是用它来声明一个控制器@RequestMapping("/some-url"),那么就不必/some-url在配置中的其他地方声明.

如果最终应用程序将有许多类型的消息通过代理,那将只会使配置膨胀.

我看到两种避免这种情况的方法:

  1. 自动声明每个带注释的侦听器端点的队列.即,如果存在带注释的侦听器端点@RabbitListener(queues = "hello"),则可以推断出hello应该声明队列.我认为可能已经是这种情况,但是当我从上下文配置中删除队列时,我收到以下错误:

    WARN  BlockingQueueConsumer - Failed to declare queue:hello
    WARN  BlockingQueueConsumer - Queue declaration failed; retries left=2
    org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[hello]
        at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:479)
        at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:400)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1022)
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在同一队列中使用不同的消息POJO.所以同时发送MessageType1MessageType2queue1,每达到不同的端点,基于有效载荷类型.实际上,这会创建一个单独的"应用程序队列",类似于数据库模式:

    @RabbitListener(queues = "queue1")
    public void handleMessage1(MessageType1 msg) {...}
    
    @RabbitListener(queues = "queue1")
    public void handleMessage2(MessageType2 msg) {...} …
    Run Code Online (Sandbox Code Playgroud)

java spring spring-amqp

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

Spring:@PropertySource的程序化等价物是什么

请考虑以下设置:

@Configuration
@PropertySource("classpath:common.properties")
public class CommonConfig {

}
Run Code Online (Sandbox Code Playgroud)

现在让我们假设我想要在这个配置中加载的属性源和一些属性源背后有一些非平凡的逻辑,我想为此使用属性API:

@Configuration
public class CommonConfig {

    @Autowired
    private ConfigurableEnvironment env;

    public void loadCommonConfig() {
        // Determine what properties to load and how...
        env.getPropertySources().addLast(...);
    }

}
Run Code Online (Sandbox Code Playgroud)

我不明白我应该如何通知Spring我有兴趣在loadCommonConfig生命周期中被调用的地方@PropertySource.简单地返回属性作为一个@Bean似乎没有工作.

java spring

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

Kotlin:如何将序列(协程)传递为Iterable <T>

我不明白如何通过需要Iterable的Coroutine.

假设我有以下功能:

fun <T> iterate(iterable: Iterable<T>) {
    for (obj in iterable) {
        // do something..
    }
}
Run Code Online (Sandbox Code Playgroud)

我想通过一个协程:

iterate( ?? {
    for (obj in objects) {
        yield(transform(obj))
    }
})
Run Code Online (Sandbox Code Playgroud)

我该怎么做而不是??为了这个工作呢?我尝试了buildIterator,buildSequence但他们都没有工作.

kotlin kotlinx.coroutines

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