The invention discloses an automatic code generation method based on entity annotation, which comprises the following steps of: 1, defining an entity relationship model, and compiling entity class codes and annotations thereof; 2, reading all classes, fields and annotation information of a specified entity class, and generating a data table and fields in a target database; 3, generating server entity mapping, data access, business logic and interface control layer codes according to the basic information of classes and fields; 4, generating a front-end code; and 5, detecting the operation effect. The method has the beneficial effects that a corresponding input control and check codes are automatically generated according to the field type, and common field types such as dates, numbers, enumeration and file types are supported; foreign key field list display is supported, and form foreign key field single-selection and multi-selection input and display are supported; according to entity class metadata information, field grouping and personalized sorting are supported, and automatic generation of simple and complex class form codes is supported.