Angularjs 以角度设置休眠日期格式的最佳实践
将JSON对象的时间值(以毫秒为单位)格式化为日期并在视图中呈现的最佳方式是什么。出于某种原因,angular似乎没有正确格式化,因此输入字段保持为空 hibernate实体将通过REST作为JSON返回 实体账户:Angularjs 以角度设置休眠日期格式的最佳实践,angularjs,hibernate,rest,Angularjs,Hibernate,Rest,将JSON对象的时间值(以毫秒为单位)格式化为日期并在视图中呈现的最佳方式是什么。出于某种原因,angular似乎没有正确格式化,因此输入字段保持为空 hibernate实体将通过REST作为JSON返回 实体账户: @Entity @Table(name = "account") @JsonIgnoreProperties(ignoreUnknown = true) public class Account extends BaseEntity implements Serializa
@Entity
@Table(name = "account")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "NAME")
private String name;
@Column(name = "EMAIL")
private String email;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "BIRTHDAY")
...
@RequestMapping(value = "upsert", method = RequestMethod.POST)
public ResponseEntity<Account> upsert(@RequestBody Account account) {
Account response = accountAccess.upsert(account);
return new ResponseEntity<>(response, HttpStatus.OK);
}
$scope.updateAccount = function(flow) {
$http.post("rest/account/upsert", $scope.account)
.success(function(response) {
$scope.account = response;
$localStorage.account = response;
toaster.pop('success', "Account saved", "Your data was succesfully saved.")
})
.error(function(error){
toaster.pop('error', "Account not saved", "Your data could not be saved.")
})
}
<div class="form-group">
<label class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<div class="input-group date">
<input id="birthday" type="date" class="form-control" ng-model="account.birthday | date" datepicker-options="dateOptions" close-text="Close" />
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
REST-WS:
@Entity
@Table(name = "account")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "NAME")
private String name;
@Column(name = "EMAIL")
private String email;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "BIRTHDAY")
...
@RequestMapping(value = "upsert", method = RequestMethod.POST)
public ResponseEntity<Account> upsert(@RequestBody Account account) {
Account response = accountAccess.upsert(account);
return new ResponseEntity<>(response, HttpStatus.OK);
}
$scope.updateAccount = function(flow) {
$http.post("rest/account/upsert", $scope.account)
.success(function(response) {
$scope.account = response;
$localStorage.account = response;
toaster.pop('success', "Account saved", "Your data was succesfully saved.")
})
.error(function(error){
toaster.pop('error', "Account not saved", "Your data could not be saved.")
})
}
<div class="form-group">
<label class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<div class="input-group date">
<input id="birthday" type="date" class="form-control" ng-model="account.birthday | date" datepicker-options="dateOptions" close-text="Close" />
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
帐户HTML:
@Entity
@Table(name = "account")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "NAME")
private String name;
@Column(name = "EMAIL")
private String email;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "BIRTHDAY")
...
@RequestMapping(value = "upsert", method = RequestMethod.POST)
public ResponseEntity<Account> upsert(@RequestBody Account account) {
Account response = accountAccess.upsert(account);
return new ResponseEntity<>(response, HttpStatus.OK);
}
$scope.updateAccount = function(flow) {
$http.post("rest/account/upsert", $scope.account)
.success(function(response) {
$scope.account = response;
$localStorage.account = response;
toaster.pop('success', "Account saved", "Your data was succesfully saved.")
})
.error(function(error){
toaster.pop('error', "Account not saved", "Your data could not be saved.")
})
}
<div class="form-group">
<label class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<div class="input-group date">
<input id="birthday" type="date" class="form-control" ng-model="account.birthday | date" datepicker-options="dateOptions" close-text="Close" />
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
日期
在日期筛选器中包含一个日期筛选器字符串(但您希望显示时间)。你没有告诉我生日的JSON值是多少。确保混淆Jackson,使其按照您想要的方式序列化(通常为毫秒时间戳或ISO格式的字符串,两者都被angular date filter接受),请再次检查代码。我正在使用日期过滤器,不是吗?@JB Nizet:日期作为millescond时间戳从rest Web服务返回。但它的失败之处仍然在于,存在一个形成问题。还有其他想法吗?这是chrome调试器中帐户对象的外观:活动:真实生日:274140000000城市:“埃森”国家:“奥地利”创建:1451224964000删除:虚假电子邮件:admin@test.deid:2图片:“a7.jpg”lastUpd:1452263854000姓名:“Ugur Teker”时事通讯:true