I have a problem with adding Image. When I press button i got error "POST http://localhost:8080/image/addImage 500 (Internal Server Error)". I think with my controller and class everything is okey but I know only basic in angularJS. I can't find good resolve for me on google well I'm writing here. Thanks for help!
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;
}
Thanks for you answer David, I don't have any stack trace in 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();
}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.