Pet*_*ler 8 spring spring-data spring-data-rest
我需要一个Spring Data Rest上的自定义方法,它有一些输入并返回一个String.
@BasePathAwareController
@RequestMapping(value = "/businessActions")
public class BusinessActionController implements ResourceProcessor<RepositoryLinksResource> {
/**
* This BusinessAction's purpose is: Generiert für ein Modell das entsprechende Barrakuda-File.
* It returns one String.
*/
@RequestMapping(value = "/modellGenerieren", method = RequestMethod.GET)
public String modellGenerieren(@Param(value="project") String project) throws IOException {
// Get project by id from repository and map to string.
return "asdf\n";
}
}
Run Code Online (Sandbox Code Playgroud)
通过使用@BasePathAwareController端点将返回"asdf\n",我想要的输出将是:
asdf
<new line>
Run Code Online (Sandbox Code Playgroud)
我能够通过仅使用产生此输出@Controller,但这打破了基本路径的意识,我需要PersistentEntityResourceAssembler在此控制器的其他方法 - 然后无法注入汇编程序.
我也有同样的问题。而且我还没有彻底解决。但我希望这些附加信息至少有帮助:
Spring 和 spring-data-rest 中有 4 个注释,恕我直言,它们都混乱地混合在一起。(例如,参见这个Bug)
如果您使用,@BasePathAwareController您将获得 Spring-data-rest 的所有魔力(请参阅SDR 文档)=> 但是您不能返回一个简单的字符串。(至少目前我还没有找到办法。)
如果您使用@RestController,那么您的端点完全独立于 SDR。
如果您希望@RestController公开与 SDR API 的其余部分相同的路径前缀,那么您可以使用以下命令:
@RestController
@RequestMapping("${spring.data.rest.base-path}")
public class MyCustomRestEndpoint { ... }
Run Code Online (Sandbox Code Playgroud)
这会从application.properties读取路径前缀
spring.data.rest.base-path=/api/v17
Run Code Online (Sandbox Code Playgroud)
然后你可以返回一个纯字符串。
但是,如果您使用@BasePathAwareController,正如OP所说,因为您需要PersistentEntityResourceAssembler,那么就无法返回纯字符串。
| 归档时间: |
|
| 查看次数: |
437 次 |
| 最近记录: |