[英]Can't add Image http.post POST 500 internal server error. AngularJS Java Spring
I have a problem with adding Image. 我在添加图片时遇到问题。 When I press button i got error "POST http://localhost:8080/image/addImage 500 (Internal Server Error)".
当我按下按钮时,出现错误“ POST http:// localhost:8080 / image / addImage 500(内部服务器错误)”。 I think with my controller and class everything is okey but I know only basic in angularJS.
我认为使用我的控制器和类一切都不错,但我只知道angularJS的基本知识。 I can't find good resolve for me on google well I'm writing here.
我在Google上找不到适合我的好的解决方法。 Thanks for help!
感谢帮助!
JS JS
var ImageController = function($scope, $routeParams, $http) {
$scope.name = $routeParams.name;
$scope.url = "i.imgur.com/" + $scope.name;
$scope.image = {};
$scope.addNewImage = function(image) {
$http.post('image/addImage', image).success(function() {
$scope.image.name = '';
})
};}
Contoller 位指示
@RequestMapping("/image")
@Controller
public class ImageController {
@RequestMapping(value = "/addImage", method = RequestMethod.POST)
public @ResponseBody void addImage(@RequestBody Image image) {imageService.addImage(image); }
Image class 图片类
@Entity
@Table(name = "IMAGE")
public class Image {
@Id
@GeneratedValue
private Long id;
@NotEmpty
@Column(name="URL", nullable=false)
private String url;
public Image(Long id, String url) {
this.id = id;
this.url = url;
}
HTML http://pastebin.com/73MExyJ8 HTML http://pastebin.com/73MExyJ8
Thanks for you answer David, I don't have any stack trace in Java. 谢谢您回答David,我在Java中没有任何堆栈跟踪。 I check database and i don't have any new records.
我检查数据库,但没有任何新记录。 Maybe my code with saving object to database isn't correct.
也许我将对象保存到数据库的代码不正确。
public interface ImageService {
public void addImage(Image image);}
Implements 器物
@Service("imageService")
public class ImageServiceImpl implements ImageService {
@Override
public void addImage(Image image)
{
HibernateUtil hibernateUtil = new HibernateUtil();
SessionFactory sessFact = hibernateUtil.getSessionFactory();
Session session = sessFact.getCurrentSession();
org.hibernate.Transaction tr = session.beginTransaction();
System.out.println(tr.isActive());
session.save(image);
tr.commit();
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.