是否可以将自定义方法添加到Spring @RepositoryRestResource
并将其公开为HTTP端点,如下面的示例尝试(但失败)?还是必须将自定义方法放在单独的@Controller
中?
@RepositoryRestResource(path="person")
public interface PersonRepository extends CrudRepository<Person,Long> {
// This works, as it's an integral part of what RepositoryRestResource does:
// curl localhost:8080/person/search/findByNameStartsWith?prefix=MA
Iterable<Person> findByNameStartsWith(@Param("prefix") String prefix);
// This doesn't work:
// curl -X POST -v localhost:8080/person/3/sendWelcomeLetter
@RequestMapping(path = "/{id}/sendWelcomeLetter", method = RequestMethod.POST)
default String sendWelcomeLetter(@PathVariable("id") Long id) {
return "This is a custom method that would generate and send a letter.";
}
}
sendWelcomeLetter不是ReST。 ReST中的ST表示“状态转移”,您的呼叫是动态的,没有状态转移。
最小的解决方案可能是添加一个新的可为空的列“ sent_welcome_newsletter”。
null
表示欢迎通讯尚未发送。false
表示无法发送欢迎时事通讯(收件箱已满或无效的电子邮件)。true
表示欢迎简讯过去已成功发送。但是:注意legal right不会被DNSBL阻止。如果不遵守此标准,您的完整公司将成为巨大的法律问题!!!