我有一封表格信。更新记录时,看不到记录的查看日期。
我尝试按以下方式获取日期:
<input type="date" name="dateSend" value="${letter.dateSend}">
我调试了代码,在控制器中获取了日期,但在视图中看不到日期。 当我从日期类型更改为文本类型时,我看到了信件的发送日期,但是我想使用日期类型。
public Iterable<Letters> updateLetter(
String numberList, String titleLetter, String addressee,
Date dateSend, Letters letter
){
letter.setNumberList(numberList);
letter.setTitleLetter(titleLetter);
letter.setAddressee(addressee);
letter.setDateSend(dateSend);
letterRepository.save(letter);
return getAllLetters();
}
public Iterable<Letters> updateLetter(
String numberList, String titleLetter, String addressee,
Date dateSend, Letters letter
){
letter.setNumberList(numberList);
letter.setTitleLetter(titleLetter);
letter.setAddressee(addressee);
letter.setDateSend(dateSend);
letterRepository.save(letter);
return getAllLetters();
}
@PostMapping("editLetter")
public String editLetter(
@RequestParam String numberList, String titleLetter,
String addressee, @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateSend,
Model model, @RequestParam("letterId") Letters letter
){
letterService.updateLetter(numberList, titleLetter, addressee, dateSend,
letter);
model.addAttribute("letter", letter);
return "redirect:/letter";
}
@GetMapping("/del/{letter}")
public String deleteLetters(
@PathVariable Letters letter
){
letterService.deleteLetter(letter);
return "redirect:/letter";
}
<#import "parts/common.ftl" as c>
<@c.page>
Letter editor
<form action="editLetter" method="post">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Number list: </label>
<div class="col-sm-6">
<input type="text" class="form-control" name="numberList" value="${letter.numberList}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Title letter: </label>
<div class="col-sm-6">
<input type="text" class="form-control" name="titleLetter" value="${letter.titleLetter}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Addressee: </label>
<div class="col-sm-6">
<input type="text" class="form-control" name="addressee" value="${letter.addressee}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Date send: </label>
<div class="col-sm-6">
<input type="date" name="dateSend" class="form-control" value="${letter.getDateSend()}" placeholder="Please enter date of sending">
</div>
</div>
<input type="hidden" value="${letter.id}" name="letterId">
<input type="hidden" value="${_csrf.token}" name="_csrf">
<button type="submit" class="btn btn-primary">Save</button>
</form>
我期望:记录的日期,但是我的结果是dd.mm.rrrr
请帮助我! :)
答案 0 :(得分:0)
如果您在输出中看到dd.mm.rrrr
,则表示FreeMarker被错误地配置为将日期格式化为dd.mm.rrrr
,字面意思是。有人尝试将date_format
配置设置设置为dd.mm.rrrr
,但实际上将其设置为'dd.mm.rrrr'
,其中包括'
-s。删除那些'
-s。之后,您还将意识到正确的模式将是dd.MM.yyyy
。