简体   繁体   English

无法添加图片http.post POST 500内部服务器错误。 AngularJS Java Spring

[英]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.

相关问题 AngularJs $ http.post可以春季启动吗? - AngularJs $http.post to spring boot? POST 500(内部服务器错误)-AngularJS-Jersey API - POST 500 (Internal Server Error) - AngularJS - Jersey API Spring Boot Post API 中的 500 内部服务器错误 - 500 Internal Server Error in spring boot post API Spring Boot 使用 Post 方法获取 500 内部服务器错误 - Spring Boot Get a 500 Internal Server Error with Post method Spring RestTemplate Post 收到 500 内部服务器错误 - Spring RestTemplate Post getting 500 internal server error Java AngularJS Spring MVC - 将 bean 发送到控制器时,$http.post 400 错误请求在语法上不正确 - Java AngularJS Spring MVC - $http.post 400 bad request syntactically incorrect when sending bean to controller 与angularjs $ http.post和spring restful的错误请求 - bad request with angularjs $http.post and spring restful 尝试从AngularJS到Spring MVC使用$ http.post服务时出现错误415-Maven - Error 415 when trying to consume $http.post service from AngularJS to Spring MVC - Maven HTTP 500 - 内部服务器错误。 servlet spring-dispatcher 的 Servlet.init() 抛出异常 - HTTP 500 - INTERNAL SERVER ERROR. Servlet.init() for servlet spring-dispatcher threw exception 500 来自 HTTP POST 请求的内部错误 - 500 Internal error from HTTP POST request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM