有没有办法在不使用Spring-MVC的情况下使用spring-data-rest编写一个rest控制器来上传文件?

时间:2015-08-18 08:15:41

标签: java spring spring-data-rest

我已经创建了类似于给定代码的存储库

@RepositoryRestResource(collectionResourceRel = "sample", path = "/sample" )
public interface SampleRepository extends PagingAndSortingRepository<Sample, Long> {

}

适用于allcrud操作。

但是我想创建一个上传文件的rest库, 我如何用spring-data-rest做到这一点?

2 个答案:

答案 0 :(得分:9)

Spring Data Rest只是将您的Spring Data存储库公开为REST服务。支持的媒体类型为Game.GenerateSpriteObject = function(obj){ var key = ""; if (obj.x !== undefined){ //Sprite key = obj.href + obj.x + obj.y + obj.width + obj.height; }else{//Animated Sprite key = obj.href + obj.startX + obj.startY + obj.width + obj.height + obj.imagesPerRow + obj.imageCount; } if (Game.cachedSprites[key] === undefined){ var imageObj = new Image(); imageObj.src = obj.href; imageObj.crossOrigin = "Anonymous"; if (obj.x !== undefined){ //Sprite Game.cachedSprites[key] = new Sprite(imageObj, obj.x, obj.y, obj.width, obj.height); }else{//Animated Sprite Game.cachedSprites[key] = new AnimatedSpriteSheet(imageObj, obj.startX, obj.startY, obj.width, obj.height, obj.imagesPerRow, obj.imageCount); } } return Game.cachedSprites[key]; }; function Sprite(img, x, y, width, height){ this.img = img; this.x = x; this.y = y; this.width = width; this.height =height; } function AnimatedSpriteSheet(img, startX, startY, width, height, imagesPerRow, imageCount){ this.img = img; this.startX = startX; this.startY = startY; this.width = width; this.height = height; this.imagesPerRow = imagesPerRow; this.imageCount = imageCount; } application/hal+json

此处列出了您可以对Spring Data Rest执行的自定义:Customizing Spring Data REST

如果要执行任何其他操作,则需要编写单独的控制器(以下是Uploading Files的示例):

application/json

答案 1 :(得分:4)

是的,你可以试试这个:

JavaTimeModule