我需要一个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-Data-Rest项目中,我们在/ buergers/search/findBuergerFuzzy?searchString ="..."端点上进行了自定义(模糊)搜索.
是否可以在/ buergers/search端点上添加链接(不覆盖自动公开的Repository findBy方法)?
控制器暴露搜索:
@BasePathAwareController
@RequestMapping("/buergers/search/")
public class BuergerSearchController {
@Autowired
QueryService service;
@RequestMapping(value = "/findBuergerFuzzy", method = RequestMethod.GET)
public
@ResponseBody
ResponseEntity<?> findBuergerFuzzy(PersistentEntityResourceAssembler assembler, @Param("searchString") String searchString) {
if (searchString.length() < 3)
throw new IllegalArgumentException("Search String must be at least 3 chars long.");
List<Buerger> list = service.query(searchString, Buerger.class, new String[]{"vorname", "nachname", "geburtsdatum", "augenfarbe"});
final List<PersistentEntityResource> collect = list.stream().map(assembler::toResource).collect(Collectors.toList());
return new ResponseEntity<Object>(new Resources<>(collect), HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)