有没有人知道如何将双倍数值转化为3个重要数字,如本网站上的示例
有谁知道如何fieldError在下面的例子中打印出来.
对于每个有错误的项目,我想打印我在messages.properties文件中定义的自定义错误消息
所有这一切都是打印默认错误代码
item.errors?.allErrors?.each{
println it.toString()
}
Run Code Online (Sandbox Code Playgroud)
我已经看到了其他示例,您可以在其中查找字段的错误代码,例如
it.getFieldError('title').code
Run Code Online (Sandbox Code Playgroud)
但我想将默认消息转换为我的新错误消息并打印出来.
我目前正在尝试在grails中为默认约束指定自定义错误消息,但到目前为止我所有回来的都是默认错误消息.
我知道我必须编辑grails-app/i18n/messages.properties文件
如果我更改以下默认错误代码消息,它将正确显示新的错误消息
default.blank.message=Property [{0}] of class [{1}] cannot be blank
Run Code Online (Sandbox Code Playgroud)
但是,这不是我想要做的.我需要更细粒度的错误报告,并且有多个字段可以为空白等.我希望能够做的是,为类中的每个字段显示自定义消息
package com.mycompany.myapp
class Test{
String name
def constraints = {
name(nullable:false, blank:false)
}
}
Run Code Online (Sandbox Code Playgroud)
(以下代码附加到messages.properties的末尾)
test.name.blank=Name cannot be blank
test.name.nullable=Name cannot be nullable
Run Code Online (Sandbox Code Playgroud)
根据grails文档,这应该可以正常工作,无论是否包名 - className.propertyName.blank
grails.org/doc/latest/(约束部分)&(第7.4节 - 验证和国际化)
我已经尝试了所有可以想到的组合,但它总是显示自定义消息
我也尝试过安装grails i18n模板插件
http://www.grails.org/I18n+Templates+Plugin
它会自动为我生成错误代码.我将新的错误代码附加到现有messages.properties文件的末尾,但我仍然收到默认的错误消息.
但是,插件生成的错误代码有所不同.
而不是grails doc - test.name.null = ......中指定的格式,它自动生成test.name.null.error =自定义消息
我还尝试完全删除默认错误消息,但仍然显示它们
如果有人以前遇到过这个问题,我将不胜感激,任何人都可以给予我任何帮助
提前致谢
有没有人知道是否有办法为流氓做循环?
我试图循环一个字符串列表,看看其中一个字符串是否匹配模式,例如
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
Run Code Online (Sandbox Code Playgroud)
我根据可以找到的文档编写了以下规则,但我不认为语法是正确的
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings, count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
Run Code Online (Sandbox Code Playgroud)
我发现很难找到关于drl语言的好文档
我很感激任何人都可以给我的任何帮助
根据之前的回答,我尝试了以下内容
rule "Matcher"
when
TestClass:TestClass(String( this matches "^a.b.*$" ) from listOfStrings)
then
TestClass.setResponse( "Condition is True !!" );
end
Run Code Online (Sandbox Code Playgroud)
但是,我现在收到以下错误消息:
[43,197]: unknown:43:197 Unexpected token 'this'
Run Code Online (Sandbox Code Playgroud) 我是 NestJS 的新手,想要自定义日志消息以包含 x-request-id/x-correlation-id 以及日志消息所源自的文件的名称,但不确定 NestJS 中是否有任何内容可以做到这一点。
我的应用程序将 NestJS 与 Fastify 适配器结合使用,并在 bootstrap() 函数中进行以下配置
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
{
logger: WinstonModule.createLogger(winston.createLogger({
exitOnError: false,
level: 'debug',
handleExceptions: true,
format: winston.format.combine(
winston.format.timestamp(),
winston.format.ms(),
winston.format.colorize(),
winston.format.align(),
winston.format.splat(),
winston.format.printf((info) => {
return `${info.timestamp} [ ${info.level} ] : ${info.message}`;
}),
),
transports: [
new (winston.transports.Console)()
]
}),
)
}
);Run Code Online (Sandbox Code Playgroud)
这似乎按预期使用温斯顿格式化日志。
2022-03-09T11:21:22.131Z [ info ] : Starting Nest application...
但是,我还想在消息中包含请求/相关 ID 以及发生日志消息的文件名,例如
2022-03-09T11:21:22.131Z 2cfd4eee-ca2b-4869-b66b-2b7da291f567 [ info ] [ Main.ts ]: Starting …
我试图用drools drl语言编写一个规则,我想做类似的事情!(A && B)但它似乎不喜欢!操作员或不是.我很难找到关于流口水的好文档
请参阅以下示例代码:
rule "Test Rule"
when
testBean : testBean(!(testList contains "test" && testList2 contains "test2"))
then
testBean.setText( "This is a test" );
end
Run Code Online (Sandbox Code Playgroud)
我要感谢任何人都能给我的任何帮助
提前致谢
我将 NestJS v9 与 Express 适配器和@nestjs/graphql库一起使用,并且在从 graphql 请求中提取标头并使用 pino 日志库将其附加到日志消息时遇到问题。
下面是我的 LoggerModule
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { LoggerModule as PinoLoggerModule } from 'nestjs-pino';
@Module({
imports: [
PinoLoggerModule.forRootAsync({
imports: [ConfigModule.forRoot({ isGlobal: true })],
useFactory: async (configService: ConfigService) => ({
isGlobal: true,
pinoHttp: {
level: process.env.LOG_LEVEL || 'info',
redact: configService.get<string[]>('logger.redact.fields'),
transport: {
target: 'pino-pretty',
options: {
colorize: false,
singleLine: true,
levelFirst: false,
translateTime: "yyyy-mm-dd'T'HH:MM:ss.l'Z'",
messageFormat: '{req.headers.x-correlation-id} [{context}] {msg}',
ignore: 'pid,hostname,context,req,res.headers', …Run Code Online (Sandbox Code Playgroud)请帮助您解决以下示例:
class Car {
static hasMany = [cd:Cd, fluffyDice:FluffyDice, wheel:Wheel]
}
class Wheel{
static belongsTo = [car:Car]
}
Run Code Online (Sandbox Code Playgroud)
如何强制汽车至少有一个车轮?
是否可以在Grails中对addTo*函数进行单元测试?
谢谢你的帮助.