SpringRoo 2.0.RC1 - 我如何在 entityFormatExpression 中使用日期 Calenderfields 并获得正确的格式
SpringRoo 2.0.RC1 - How can i use date Calenderfields in entityFormatExpression and got correct format
日期日历
当我在 entityFormatExpression 中使用日期日历字段时,我得到一个
entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"
field date --fieldName birthDay --type java.util.Calendar --notNull --dateTimeFormatPattern "dd.MM.yyyy"
记录警告
2017-03-22 10:43:55.738 WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableExcep
tion: Could not write content: Failed to convert from type [org.springframework.roo.petclinic.domain
.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='M
imi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAl
lFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSa
vings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,of
fset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,st
artDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTi
me=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF
_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0
,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_T
O_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_C
ANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petc
linic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationExceptio
n: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNu
ll @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.Grego
rianCalendar to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2Dat
aWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException
: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to type [java.lang.Stri
ng] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weight='4.5', birthDay=
'java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=tru
e,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600
000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],fi
rstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_
OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=
0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='T
he given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The give
n Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domain.Pet@1f'; nested
exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:(pos 0): Type conv
ersion problem, cannot convert from @javax.validation.constraints.NotNull @javax.persistence.Tempora
l @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalendar to java.lang.Str
ing (through reference chain: io.springlets.data.web.select2.Select2DataWithConversion["results"])
2017-03-22 10:43:55.754 WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessa
geNotWritableException: Could not write content: Failed to convert from type [org.springframework.ro
o.petclinic.domain.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminder
s='false', name='Mimi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFi
eldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",of
fset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[i
d=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMont
h=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,en
dDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=20
17,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_
IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFS
ET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', IT
ERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.spring
framework.roo.petclinic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.Spel
EvaluationException: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation
.constraints.NotNull @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeForm
at java.util.GregorianCalendar to java.lang.String (through reference chain: io.springlets.data.web.
select2.Select2DataWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.Js
onMappingException: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to ty
pe [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weigh
t='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=
true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=36000
00,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=360000
0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWee
k=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,
endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WE
EK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOU
R_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_
BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL
_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domai
n.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:
(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNull @javax.p
ersistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalenda
r to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2DataWithConver
sion["results"])
当我创建 Visit the Pet 时,列表中没有显示。
日期日期
当我使用日期 Date 字段并创建列表中显示的 Visit the Pet 但格式不正确时。
在 Clinic Eaxmpel 中,我为 Pet 设置了一个 birthDay 字段,并在 entityFormatExpression
中使用它
entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"
focus --class ~.domain.Pet
field date --fieldName birthDay --type java.util.Date --notNull --dateTimeFormatPattern "dd.MM.yyyy"
我设置了 dateTimeFormatPattern "dd.MM.yyyy"
在创建编辑/视图中我看到
enter image description here
当我创建访问对象时,我看到了
enter image description here
这不是我用于此字段的格式。
JSON数据发送到select2组件时,由EntityExpression utilities转换为String,在ConversionService中注册。
这些实用程序使用 SpEl 支持来解析表达式并将实体转换为字符串。 SpEl 表达式似乎没有使用或无权访问 ConversionService 本身以将表达式中包含的对象属性转换为 String。
我创建了一个 issue in the Springlets project 来查看问题。
日期日历
当我在 entityFormatExpression 中使用日期日历字段时,我得到一个
entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"
field date --fieldName birthDay --type java.util.Calendar --notNull --dateTimeFormatPattern "dd.MM.yyyy"
记录警告
2017-03-22 10:43:55.738 WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableExcep
tion: Could not write content: Failed to convert from type [org.springframework.roo.petclinic.domain
.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='M
imi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAl
lFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSa
vings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,of
fset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,st
artDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTi
me=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF
_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0
,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_T
O_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_C
ANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petc
linic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationExceptio
n: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNu
ll @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.Grego
rianCalendar to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2Dat
aWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException
: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to type [java.lang.Stri
ng] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weight='4.5', birthDay=
'java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=tru
e,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600
000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],fi
rstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_
OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=
0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='T
he given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The give
n Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domain.Pet@1f'; nested
exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:(pos 0): Type conv
ersion problem, cannot convert from @javax.validation.constraints.NotNull @javax.persistence.Tempora
l @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalendar to java.lang.Str
ing (through reference chain: io.springlets.data.web.select2.Select2DataWithConversion["results"])
2017-03-22 10:43:55.754 WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessa
geNotWritableException: Could not write content: Failed to convert from type [org.springframework.ro
o.petclinic.domain.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminder
s='false', name='Mimi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFi
eldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",of
fset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[i
d=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMont
h=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,en
dDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=20
17,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_
IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFS
ET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', IT
ERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.spring
framework.roo.petclinic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.Spel
EvaluationException: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation
.constraints.NotNull @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeForm
at java.util.GregorianCalendar to java.lang.String (through reference chain: io.springlets.data.web.
select2.Select2DataWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.Js
onMappingException: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to ty
pe [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weigh
t='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=
true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=36000
00,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=360000
0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWee
k=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,
endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WE
EK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOU
R_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_
BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL
_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domai
n.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:
(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNull @javax.p
ersistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalenda
r to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2DataWithConver
sion["results"])
当我创建 Visit the Pet 时,列表中没有显示。
日期日期
当我使用日期 Date 字段并创建列表中显示的 Visit the Pet 但格式不正确时。
在 Clinic Eaxmpel 中,我为 Pet 设置了一个 birthDay 字段,并在 entityFormatExpression
中使用它entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"
focus --class ~.domain.Pet
field date --fieldName birthDay --type java.util.Date --notNull --dateTimeFormatPattern "dd.MM.yyyy"
我设置了 dateTimeFormatPattern "dd.MM.yyyy"
在创建编辑/视图中我看到
enter image description here
当我创建访问对象时,我看到了
enter image description here
这不是我用于此字段的格式。
JSON数据发送到select2组件时,由EntityExpression utilities转换为String,在ConversionService中注册。
这些实用程序使用 SpEl 支持来解析表达式并将实体转换为字符串。 SpEl 表达式似乎没有使用或无权访问 ConversionService 本身以将表达式中包含的对象属性转换为 String。
我创建了一个 issue in the Springlets project 来查看问题。