问题
In order to perform pre/post insert/update/delete actions (isRegisterFor(Class<?> clazz)
, postInsert(BeanPersistRequest<?> request)
, ... ) with Ebean in Play, I implemented a class IndexAdapter extends BeanPersistAdapter
.
Works
- app
-- models
--- Car
--- Person
--- House
--- IndexAdapter
-- controllers
--- ...
Everything went well until I decided to transform it (it's more than one class actually) into a Play plugin.
Doesn't work
- app
-- plugin
--- IndexAdapter
-- models
--- Car
--- Person
--- House
-- controllers
--- ...
From a colleague I learned that the class derived from BeanPersistAdapter
will only intervene into the insert/update/delete actions if it's placed inside the models directory. So is there any way of telling the Adapter where the models (on which insert/update/delete actions it should intervene) are located?
回答1:
If you want, you can put the class in a module project (http://www.playframework.com/documentation/2.1.x/SBTSubProjects)
I did this on my project. I have the main project, with two modules: - the common module (where my BeanPersistAdapter is) - the models module (where all my model classes are), which depends on the common module The main project depends on the models module.
Doing this, you will have the same thing you want, but in modules, not in the app folder of the main project.
来源:https://stackoverflow.com/questions/20371960/use-of-beanpersistadapter-in-a-plugin