The invention discloses a
code generation method and device based on a maven plug-in and a freemarker template. The method comprises the steps that data and the template are prepared, namely, .hbm.
xml files are written or generated according to a data base design file or a data base table, and the template is written according to the characteristics of items and freemarker template grammar; the maven plug-in is called to carry out the logical operation to generate codes, namely, the maven plug-in which encapsulates arithmetic logic generated by the codes is called, and logic operation and
code generation are carried out according to the .hbm.
xml files prepared in the first step and freemarker template files; the codes are generated, namely,
macro is applied to the code template to generate a target code of an MVC three-layer structure. The
code generation method and device based on the maven plug-in and the freemarker template solve the problem that duplicated codes are automatically generated in the developing process, and can be customized under the actual condition according to the template and improve production efficiency; because automatic code generation and a common construction tool maven are bound, the universality and the
usability of the device are improved.