Reputation: 3459
Is it possible to create a template/live template with IntelliJ to create the full stack of usual boilerplate for a Domain Object?
Let me give you an example: A usual structure in in a backend could look something like this:
Create the entity FoobarEntity:
@Entity @Table(name="foobar") @Getter @Setter
public class FoobarEntity implements Persistable<Long> {
@Id
private Long id;
@Column
private String someData;
@Column
private String someMoreData;
}
Now the boilerplate party starts, create data transfer objects, data access objects, services, ...: Create FoobarDto
(to get started), Interface FoobarDao
(CRUD) and default implementation FoobarDaoJpa
, Interface FoobarService
(CRUD) and default implementation FoobarServiceImpl
, a mapper to map from Entity to Dto FoobarDtoMapper
, maybe a Spring config FoobarConfig
, maybe a filter object to search FoobarSearchFilter
, maybe some more Classes for a REST api like FoobarRessource
, FoobarController
, ...
Some further considerations: More annotations (like @Service
or something like that) would be somehow useless since the all the classes start with the same code base (like add
, delete
, edit
, load
methods for a service and a dao) but, however, will grow in the further process of development.
Is this somehow possible with IntelliJ (or another tool you know)?
Upvotes: 0
Views: 1799
Reputation: 73281
You can create entities like that with hibernate plugin. It creates entities according to your table structure. Just add hibernate framework to your project (in linux, press Ctrl + Shift + a, then type hibernate
and select add hibernate framework
), then you'll get a task window like that:
Now right click on your projects name (will be different in your case) and select Generate Persistence Mapping
> By Database Schema
.
Now a window will open and you can select the tables you want to create an entity for.
Note that you need to have set up your database in idea to make this work.
For your third point, use file templates. Again, press Ctrl + Shift + a, but then type file template
- create the templates once and just use them...
Upvotes: 1