我有一个拥有这些领域的实体.
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中实现这一点,而无需再次手动创建表单中的这些消息和数据属性.
我正在尝试使用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相关的缓存文档很少.有人可以在这件事上给我任何见解.
我正在使用最新的 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) 我正在使用 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 …
我在 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) 我正在使用 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 也会有所帮助。
我在 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) 我最近正在尝试学习 Kotlin 协程,我注意到在返回一堆async
IDE的地图的情况下,显示消息说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) 我有这样的字符串。
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) 我在 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
kotlin ×4
java ×3
redis ×2
symfony ×2
apache ×1
docker ×1
doctrine ×1
forms ×1
junit ×1
lambda ×1
laravel ×1
laravel-mix ×1
macos ×1
mockito ×1
php ×1
reactive ×1
spring-amqp ×1
spring-boot ×1
spring-cache ×1
tailwind-css ×1
vue.js ×1
webpack ×1