代码
JSP:
<div class="col-md-4 col-sm-6 col-xs-12">
<fmt:formatDate value="${sighting.sightingDateAsDate}" var="sightingDateString" pattern="yyyy-MM-dd'T'hh:mm:ss"/>
<sf:input type="datetime-local" class="add-form form-control" path="sightingDate" value="${sightingDateString}"/>
</div>
Controller:
String sightingDateString = request.getParameter("sightingDate");
LocalDateTime sightingDate = LocalDateTime.parse(sightingDateString.replace("T"," "), DateTimeFormatter.ISO_DATE_TIME);
Run Code Online (Sandbox Code Playgroud)
我正在处理这个编辑表单。fmt:formatDate 是将sightingDate 转换为html 可读的格式,因此输入字段datetime-local 将填充现有的LocalDateTime 值。
现在的问题是将其转换回 LocalDateTime。我得到的当前错误是:
错误
Request processing failed; nested exception is
java.time.format.DateTimeParseException: Text '2017-03-22 01:00' could not be parsed at index 10
Run Code Online (Sandbox Code Playgroud)
我也试过没有替换(“T”,“”)。错误会说 Text '2017-03-22T01:00' 而不是 Text '2017-03-22 01:00'
我想在登录时获取userName信息.如果用户未登录,则if语句应跳过此操作.我认为暗示是我应该使用但当用户未登录时它当前抛出空指针.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String displayHomePage(Model model, Principal user) {
if(!user.implies(null)){
String name = user.getName();
User currentUser = userService.getUserByName(name);
}
Run Code Online (Sandbox Code Playgroud)