The invention discloses a Word
report generation method based on a reflection mechanism, and relates to the technical field of databases. Comprising the following steps: step 1, creating a
Java class, representing information generated in Word by using the
Java class, and creating different types of annotations to modify the
Java class or Java class attributes, including text
paragraph annotations and table data annotations, by using attribute fields of the Java class to correspond to data required by a Word report; 2, compiling a Word
report generation method: defining parameters of the generation method as generic objects and a
list with elements as generic objects, executing a text
paragraph strategy of a generated report according to the generic objects by the generation method, and executing a data table strategy of the generated report according to the
list, obtaining the
annotation of the Java class corresponding to the object and the
annotation of the attribute value corresponding to the Java class in the object through a reflection mechanism; and 3, calling a Word
report generation method to generate a Word report: taking the
Java object with the text
paragraph data and the table data as input parameters of the generation method to generate the Word report, and changing the parameters according to requirements to execute the generation method for multiple times so as to adjust data in the Word report.