4

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)?

codecompleting
  • 9,251
  • 13
  • 61
  • 102

3 Answers3

1

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.

javatestcase
  • 682
  • 1
  • 10
  • 25
1

Code generation is surprisingly easy, and IMO is best left out of the IDE equation. If you see an opportunity, create a quick tool using Velocity, FreeMarker, or J. Random templating solution until you figure out a better long-term solution, or it becomes unnecessary.

Also consider simple generics; it's often enough.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
0

Since IntelliJ IDEA 2020.3 File templates for multiple files can be created.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68