Spring BootアプリケーションでThymeleafを使用する際に問題が見つかりました。Thymeleafはデータフィールドを使用している入力にフォーマッタを使用していません
バージョン:
- 春ブート1.3.4と1.3.3
マイエンティティ:
@Entity
public class MyEntity {
@Id
@GeneratedValue
private Long id;
@Version
private int version;
@DateTimeFormat(pattern="dd/MM/yyyy")
private Calendar calendar;
@DateTimeFormat(pattern="dd/MM/yy")
private Date date;
@NumberFormat(pattern="#0.00000")
private Double aDouble;
}
マイコントローラー:
@RequestMapping(value = "/{myEntity}/edit-form",
method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@PathVariable MyEntity myEntity, Model model) {
return "myEntity/edit";
}
マイmyEntity/edit.htmlテンプレート:
<form class="form-horizontal" method="POST"
data-th-object="${myEntity}"
data-th-action="@{/myEntity/{id}(id=*{id})}">
<input type="hidden" name="_method" value="PUT" />
<div class="form-group"
data-th-classappend="${#fields.hasErrors('calendar')}? 'has-error has-feedback'">
<label for="calendar" class="col-md-3 control-label">Calendar</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{calendar}"/>
<span data-th-text="*{{calendar}}"></span>
</div>
</div>
<div class="form-group"
data-th-classappend="${#fields.hasErrors('date')}? 'has-error has-feedback'">
<label for="date" class="col-md-3 control-label">Date</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{date}"/>
<span data-th-text="*{{date}}"></span>
</div>
</div>
<div class="form-group"
data-th-classappend="${#fields.hasErrors('aDouble')}? 'has-error has-feedback'">
<label for="date" class="col-md-3 control-label">aDouble</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{{aDouble}}"/>
<span data-th-text="*{{aDouble}}"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</form>
私は、このページを表示しようとすると私が取得:
<body>
<form class="form-horizontal" method="POST" action="/myEntity/1">
<input type="hidden" name="_method" value="PUT" />
<div class="form-group">
<label for="calendar" class="col-md-3 control-label">Calendar</label>
<div class="col-md-3">
<input type="text" class="form-control" id="calendar" name="calendar"
value="java.util.GregorianCalendar[time=1451602800000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Madrid",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=165,lastRule=java.util.SimpleTimeZone[id=Europe/Madrid,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2016,MONTH=0,WEEK_OF_YEAR=53,WEEK_OF_MONTH=0,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]" />
<span>01/01/2016</span>
</div>
</div>
<div class="form-group">
<label for="date" class="col-md-3 control-label">Date</label>
<div class="col-md-3">
<input type="text" class="form-control" id="date" name="date"
value="2016-02-01 00:00:00.0" />
<span>01/02/16</span>
</div>
</div>
<div class="form-group">
<label for="date" class="col-md-3 control-label">aDouble</label>
<div class="col-md-3">
<input type="text" class="form-control" id="aDouble" name="aDouble"
value="0.1" />
<span>0.10000</span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</form>
</body>
あなたが見ることができるように、すべてのフィールドの値期待通りにをフォーマットしません(span
はth-text
属性で同じ値を使用します)すべての値に対して0メソッド。
誰かが私を助けることができますか?前もって感謝します。
EDIT 1:私は、私が使用したい日付についてnew issue about it
入力にも二重括弧を使用してはどうでしょうか。 [this](https://github.com/thymeleaf/thymeleaf/issues/223)によると、それはうまくいく可能性があります。 –
私は試みましたが、何も変わりませんでした( 'data-th-field =" * {{aDouble}} ")。ありがとうございました。 – jmvivo