SpringRoo 2.0.RC1 - 如何在entityFormatExpression中使用日期Calenderfields并获得正确的格式

时间:2017-03-22 09:35:31

标签: spring-roo

日期日历

当我在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"])

当我创建一个访问时,宠物不会显示在列表中。

日期

当我使用日期日期字段并创建一个访问列表中显示的宠物,但格式不正确。

在诊所Eaxmpel我已将birthDay字段设置为Pet并在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

这不是我用于此字段的格式。

1 个答案:

答案 0 :(得分:0)

将JSON数据发送到select2组件时转换为String由{em> ConversionService 中注册的EntityExpression utilities执行。

这些实用程序使用SpEl支持来解析表达式并将实体转换为String。似乎SpEl表达式没有使用或无法访问ConversionService本身,无法将表达式中包含的对象属性转换为String。

我已经创建了一个issue in the Springlets project来查看问题。