Today you create a table with more than 10 fields, and you must write a Java domain entity class that corresponds to it when you create it. Isn't that a repetitive job? Why not first find out all the fields of this table, and then put it in the Linux environment and use the SED tool to precede each line with "private String" followed by ";" after each line. This can save a lot of repetitive work. Below are the SQL code and SED commands.
The SQL code that queries the column names of all columns in a MySQL table is as follows:
SELECT column_name from INFORMATION_SCHEMA. Columnswhere table_name = ' table_name ';
Execution results
OK, after you get all the column names, create a new file on the Linux environment, and copy the column name in. Save exit.
Use SED on Linux to process a file that is a column name for each row. The command is as follows:
[Email protected] tmp]# sed-i "s/^/private string/g" web.txt [[email protected] tmp]# sed-i "s/$/; /g "Web.txt
The first command means to add "private String" at the beginning of each line, and "^" to denote the meaning of the beginning in the regular expression. The second command adds ";" at the end of each line, and "$" dollar the dollar sign to mean the end of the line in a regular expression.
Again cat this file, the output is as follows:
Okay, OK, put this code in your IDE, because the variables of type string are the majority, so the uniform plus "string". The following work is the type of the field that is not the correct type.
This process can knock out a lot of code less. And in the case of using Ibatis, the property name of the class and the field name of the database table if it is the same, then you do not have to write any resultmap.
Finally, add "@Data" annotations (Lombok annotations) to the class name so that the getter, setter method is generated for all fields. The whole class is very concise.
Quickly create Java domain entity classes corresponding to MySQL tables