在Grails中创建RESTful API时,我在域类之前添加了@Resource(uri='env',formats=['multipart/form-data']
。然后使用grails generate-all domain_name
生成 Controller 和 View 。
但是,在Eclipse中有一个Java问题,例如
The project was not built due to "RequestEnvironmentController$_on_closure51 [in [Working copy] RequestEnvironment.groovy [in test.environment.manager [in grails-app/domain [in restful-api-for-tem]]]] does not exist". Fix the problem, then try refreshing this project and building it since it may be inconsistent.
然后,我摆脱了注释,错误消失了,并且post方法仍然有效。我很困惑,注释是否必要?如有必要,如何清除Java错误?
最佳答案
使用@Resource批注时,无需创建 Controller ,因为它将根据documentation自动生成
Simply by adding the Resource transformation and specifying a URI, your domain class will automatically be available as a REST resource in either XML or JSON formats. The transformation will automatically register the necessary RESTful URL mapping and create a controller called BookController.
关于grails - 在域类之前grails @Resource Annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31438154/