小编nic*_*net的帖子

在Symfony 2中输出带有消息的实体约束

我有一个拥有这些领域的实体.

class User implements UserInterface, \Serializable
{
  /**
   * @var string
   *
   * @ORM\Column(name="first_name", type="string", length=64)
   * @Assert\NotBlank(message="First name cannot be blank")
   * @Assert\Length(max=64, maxMessage="First name cannot more than {{ limit }} characters long")
   */ 
   private $firstName;

   .....

}
Run Code Online (Sandbox Code Playgroud)

现在我想以这样的形式输出这些约束.

<input type="text" required="required" data-required-msg="First name cannot be blank" name="firstname" data-max-length="64" data-max-length-msg="First name cannot be more than 64 characters long">
Run Code Online (Sandbox Code Playgroud)

无论如何,我可以在Symfony 2中实现这一点,而无需再次手动创建表单中的这些消息和数据属性.

forms symfony

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

使用Redis在Symfony 2应用程序中缓存doctrine结果

我正在尝试使用Redis缓存查询结果和APC for metacache.根据Symfony文档,我需要做的就是.

doctrine:
    orm:
        auto_mapping: true
        metadata_cache_driver: apc
        result_cache_driver:
            type: redis
            host: localhost
            instance_class: Redis
Run Code Online (Sandbox Code Playgroud)

这是为doctrine配置缓存属性的正确方法吗?此外,当我谷歌"使用redis与symfony"我得到的结果,告诉我使用SNCRedis捆绑.

是否有必要使用SNCRedis包在Symfony中使用Redis作为学说?它在Symfony默认值之上提供了什么好处.我在这里有点困惑,因为在Symfony中与Doctrine相关的缓存文档很少.有人可以在这件事上给我任何见解.

doctrine redis symfony

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

本地主机在 docker for mac 中不起作用

我正在使用最新的 Docker for mac。我遇到了这个奇怪的问题。我可以通过http://127.0.0.1/而不是http://localhost/访问我的 webapp但是我可以访问https://localhost/(自签名证书)。所以,我不确定这里有什么问题。

这是我的 docker compose。

version: "3"
services:
  php:
    build:
      context: .
    container_name: php
    volumes:
      - .:/var/www/html
      - conf:/etc/apache2/sites-enabled
    ports:
      - "80:80"
      - "443:443"
Run Code Online (Sandbox Code Playgroud)

这是我的 Apache 配置

<VirtualHost _default_:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html

  <Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/apache2/certs/localhost.crt …
Run Code Online (Sandbox Code Playgroud)

php apache macos docker docker-compose

5
推荐指数
2
解决办法
8715
查看次数

如何让 JUnit 采用任何 Lambda 表达式

我正在使用 SpringAMQP 来测试生产者方法(基本上是 AMQP 模板),就像这样。

public void send(Message message, Throwable error, String queue, String routingKey) {

    this.amqpTemplate.convertAndSend(
        RabbitConfiguration.ERROR_EXCHANGE,
        RabbitConfiguration.ERROR_ROUTING_KEY,
        message,
        messageMetaData -> {

            messageMetaData.getMessageProperties().getHeaders().put("x-death-reason", error.getMessage());

            return messageMetaData;
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

我正在使用以下内容测试此代码

import static org.hamcrest.Matchers.any;
....
@Test
public void will_create_error_message_if_incorrect_payload_is_given() {

    AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
    Throwable throwable = mock(Throwable.class);
    when(throwable.getMessage()).thenReturn("first");
    when(throwable.getStackTrace()).thenReturn(null);

    ErrorMessageProducer errorMessageProducer = new ErrorMessageProducer(amqpTemplate);

    Message message = MessageBuilder.withBody("test".getBytes()).build();

    verify(amqpTemplate).convertAndSend(
        eq(RabbitConfiguration.ERROR_EXCHANGE),
        eq(RabbitConfiguration.ERROR_ROUTING_KEY),
        any(Message.class),
        Mockito.any()
    );
}
Run Code Online (Sandbox Code Playgroud)

但我得到Invalid use of argument matchers! 4 matchers expected, 3 recorded. 有什么方法可以使用 Lambda …

java lambda junit mockito spring-amqp

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

@apply 在 Laravel Mix 中的 Vue 组件内不起作用

我在 Laravel 中使用 Tailwind CSS 和 VueJS 组件,如下所示。

<template>

</template>

<script>

</script>

<style lang="postcss" scoped>

    .day-disabled {

        @apply text-gray-400;
    }

</style>
Run Code Online (Sandbox Code Playgroud)

然而它抱怨的是

Module parse failed: Unexpected token (685:0)
File was processed with these loaders:
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|
> .day-disabled {
|
|     @apply text-gray-400;
Run Code Online (Sandbox Code Playgroud)

无论如何,是否可以@apply使用 Laravel Mix 在 VueJS 组件中使用指令。这是我的webpack.mix.js

const mix = require('laravel-mix');
mix.options({ extractVueStyles: true})
   .js('resources/js/app.js', 'public/js')
   .postCss('resources/css/app.css', 'public/css', [
       require('postcss-import'), …
Run Code Online (Sandbox Code Playgroud)

laravel webpack vue.js laravel-mix tailwind-css

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

在 WebClient 请求中添加查询参数

我正在使用 Spring WebFlux 接受请求并使用相同的请求来调用另一个服务。但我不确定如何添加查询参数。这是我的代码

@RequestMapping(value= ["/ptta-service/**"])
suspend fun executeService(request: ServerHttpRequest): ServerHttpResponse {

    val requestedPath = if (request.path.toString().length > 13) "" else request.path.toString().substring(13)

    return WebClient.create(this.dataServiceUrl)
                    .method(request.method ?: HttpMethod.GET)
                    .uri(requestedPath)
                    .header("Accept", "application/json, text/plain, */*")
                    .body(BodyInserters.fromValue(request.body))
                    .retrieve()
                    .awaitBody()
                    // But how about query parameters??? How to add those
}
Run Code Online (Sandbox Code Playgroud)

尽管代码在 Kotlin 中,但 Java 也会有所帮助。

java kotlin spring-webflux spring-webclient

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

@Cacheable 在控制器中工作,但不在服务内部工作

我在 Spring Boot 中遇到这个奇怪的问题,@Cacheable它在控制器中工作,但不在服务内部工作。我可以在 Redis 中看到 GET 调用,但看不到 PUT 调用。

这是有效的,因为它位于控制器内部

@RestController
@RequestMapping(value="/places")
public class PlacesController {

    private AwesomeService awesomeService;

    @Autowired
    public PlacesController(AwesomeService awesomeService) {
        this.awesomeService = awesomeService;
    }

    @GetMapping(value = "/search")
    @Cacheable(value = "com.example.webservice.controller.PlacesController", key = "#query", unless = "#result != null")
    public Result search(@RequestParam(value = "query") String query) {
        return this.awesomeService.queryAutoComplete(query);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是@Cacheable当我在服务中这样做时不起作用

@Service
public class AwesomeApi {

    private final RestTemplate restTemplate = new RestTemplate();

    @Cacheable(value = "com.example.webservice.api.AwesomeApi", key = "#query", unless = …
Run Code Online (Sandbox Code Playgroud)

redis spring-boot spring-cache spring-restcontroller

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

函数返回名称不以 async 结尾的 Deferred

我最近正在尝试学习 Kotlin 协程,我注意到在返回一堆asyncIDE的地图的情况下,显示消息说Function returning Deferred with a name that does not end with async. 这是我的代码

runBlocking {
    try {
        val siteDeferred = async { getSite(order) }
        // Place where I get warning-----------| (Function returning Deferred with a name that does not end with Async)
        //                                     v
        val orderLineDeferred = order.line.map { async { getOrderDetail(it) } }

        // Place where I get warning-------------------| (Function returning Deferred with a name that does not end with Async)
        //                                             v …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlinx.coroutines

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

groupByTo 在 Kotlin 中返回 emptySet

我有这样的字符串。

val input = "perm1|0,perm2|2,perm2|1"
Run Code Online (Sandbox Code Playgroud)

所需的输出类型是

val output: Set<String, Set<Long>>
Run Code Online (Sandbox Code Playgroud)

和期望的输出值是

{perm1 [], perm2 [1,2] }
Run Code Online (Sandbox Code Playgroud)

如果值为 ,我需要空集0。我使用groupByTo这样的

val output = input.split(",")
                  .map { it.split("|") }
                  .groupByTo(
                       mutableMapOf(),
                       keySelector = { it[0] },
                       valueTransform = { it[1].toLong()  }
                   )
Run Code Online (Sandbox Code Playgroud)

然而输出结构是这样的

MutableMap<String, MutableList<Long>> 
Run Code Online (Sandbox Code Playgroud)

和输出是

{perm1 [0], perm2 [1,2] }
Run Code Online (Sandbox Code Playgroud)

我正在寻找获得所需输出的最佳方法,而无需使用这样的命令式样式。

val output = mutableMapOf<String, Set<Long>>()
input.split(",").forEach {

    val t = it.split("|")

    if (t[1].contentEquals("0")) {

        output[t[0]] = mutableSetOf()
    }

    if (output.containsKey(t[0]) && !t[1].contentEquals("0")) {

        output[t[0]] = output[t[0]]!! + …
Run Code Online (Sandbox Code Playgroud)

java kotlin

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

使用 R2BC Kotlin 协程进行数据库事务

我在 Spring Webflux 项目中使用 R2bc 和 Kotlin。它运行良好。但我有这个方法

@Component
class UserRepository(private val client: DatabaseClient, private val operator: TransactionalOperator) {

    suspend fun updateUser(user: User, value: String): Int {

        client.execute("INSERT INTO log(user_id, activity) VALUES (:user_id, :activity)")
              .bind("activity", user.activity)
              .bind("user_id", user.id)
              .fetch()
              .awaitRowsUpdated()

        return client.execute("UPDATE users SET value = :value WHERE id = :id")
                     .bind("value", value)
                     .bind("id", user.id)
                     .fetch()
                     .awaitRowsUpdated()
}
Run Code Online (Sandbox Code Playgroud)

此方法有效,但我想使用数据库事务。Kotlin 是否支持。

reactive-programming kotlin reactive spring-webflux kotlin-coroutines

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