我尝试测试 Hibernate 的一对多关系。我定义 Post 和 PostComment 实体如下: Post.java
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "post")
public class Post {
@Id
@Column(name="post_id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long postId;
@Column(name="title")
private String title;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "post",
orphanRemoval = true)
private List<PostComment> comments = new ArrayList<>();
public Post() {};
public Post(String title) {
this.title = title;
}
// Add getter and setter
}
Run Code Online (Sandbox Code Playgroud)
发表评论.java
import javax.persistence.*;
@Entity
@Table(name = "post_comment")
public class PostComment {
@Id
@Column(name="comment_id")
@GeneratedValue(strategy= GenerationType.IDENTITY) …Run Code Online (Sandbox Code Playgroud) 每当我运行由angularjs 1.4.3实现的应用程序时。
BannerService.js
app.service('BannerService',function ($http) {
this.save = function saveBanner(banner) {
return $http({
method: 'POST',
url: 'http://localhost:8081/api/banners'
});
}
});
Run Code Online (Sandbox Code Playgroud)
BannerController.js
app.controller('BannerAddCtrl', ['$scope','$log','BannerService',
function ($scope,$log, BannerService) {
$scope.save = function() {
BannerService.saveBanner(myBanner)
.success(function (result) {
$log.debug('RESULT', result);
}, function (reason) {
$log.debug('REASON', reason);
});
}
Run Code Online (Sandbox Code Playgroud)
}]);
还有index.html
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-block" ng-click="save()">Save Banner</button>
</div>
Run Code Online (Sandbox Code Playgroud)
它引发如下异常:
TypeError: BannerService.saveBanner is not a function
at ChildScope.$scope.save (bannerControllers.js:64)
at fn (eval at compile (angular.js:13145), <anonymous>:4:203)
at callback (angular.js:23298)
at ChildScope.$eval (angular.js:15846) …Run Code Online (Sandbox Code Playgroud) 我用以下代码解析datetime:
String parseDate(String tranDateTime, String originalDateFormat, String toDateFormat) throws ParseException {
SimpleDateFormat originalMonthYear = new SimpleDateFormat(originalDateFormat);
Date date = originalMonthYear.parse(tranDateTime);
SimpleDateFormat formatter = new SimpleDateFormat(toDateFormat);
return formatter.format(date);
}
Run Code Online (Sandbox Code Playgroud)
并尝试解析日期时间值,如下所示:
parseDate("2017-08-16T00:00:00Z",
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
抛出异常:
java.text.ParseException:无法解析的日期:"2017-08-16T00:00:00Z"
但是,当我更改日期值时"2017-08-16T02:54:15.537Z",功能正常.我不知道为什么.