Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

java - Does IntelliJ support any kind of templating to create multiple files automatically?

So I have a spring mvc application, and I am noticing there is allot of repetitive code I am doing (I'm newish to both java/spring).

Each time I create a new entity I have to create the following files:

Entity
EntityDao
EntityDaoImpl
EntityService
EntityServiceImpl

All of the files except for the Entity.java file (say User.java or Product.java etc) are pretty much something that could be automatically generated.

Is there anything out there that can help generate these files (in the correct folders)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unfortunately I think the answer is no. It seems like the capability could be there... They have configurable file templates, but AFAIK the templates are locking into the create menu, which means one file at a time.

What you are suggesting is very possible with Velocity or Freemarker (or any other template engine.) You should be able to find examples out there that do what you are looking for by searching with those tool names.

Finally this is another topic, but I'll just suggest that if you find yourself doing a lot of repetitive code. Maybe there is another way to setup up your project (annotations, dependency injection) or another framework (Hibernate w Seam or JPA + EJB) that might be easier for what you are trying to do. Worth investigating.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...