Automatically generate DTO with AWK

zhaozj2021-02-16  55

Most tools for EJB development support automatic generation of DTO, provided that there must be some corresponding entity beans. When there is no entity bean, we have to knock on the cumbersome clicks. In this case, this AWK Script may be a boring. If you don't know awk, you can go http://www-900.ibm.com/developerWorks/cn/linux/shell/awk/awk-1/index.shtml http://www-900.ibm.com/developerWorks / c/linux/shell/awk/awk-2/index.shtml http://www-900.ibm.com/developerworks/cn/linux/shell/awk/awk-3/index.shtml Take a look. If you use Windows, you want to run this script, you need to go to Down a explanation called awk.exe. Format for text requirements: The first line is the name of the DTO, the remaining line is "Type-Variable Name" correct, pay attention to not add the number! Such examples: user_dto int ID String Name Collection Friends The following bevels are script body:

Begin {count = 0;} {if (nf == 2) {Arr [count, 0] = $ 1; arr [count, 1] = $ 2; #Print Arr [count, 0], arr [count, 1], Count; count ;}

IF (nf == 1) DTO = $ 1;}

END {Printf ("/ * DTO CREATED BY awk * // n / n"); Printf ("/ * @ Todo Complete Package & Import Here * // N / N"); Printf ("Public Class% S IMPLEments Serializable / n {/ n ", DTO);

For (i = 0; i

Printf ("/ n / n");

Printf ("/ TPUBLIC% S () / N / T {/ N / T} / N / N", DTO);

Printf ("/ TPUBLIC% S (", DTO); for (i = 0; i

IF (i! = count-1) Printf (",");} printf (") / n / t {/ n");

For (i = 0; i

# setters & getters for (i = 0; i

Printf ("/ TPUBLIC% S get% S% S () / n / t {/ n", arrx, xhead, xbody, arrx, x); printf ("/ t / treturn% S; / N", X) PRINTF ("/ t} / n / n");} # Equals printf ("/ n / n"); Printf ("/ TPUBLIC Boolean Equals (Object Obj) / N / T {/ N"); Printf "/ T / TIF (OBJ! = NULL) / N / T / T {/ N"); Printf ("/ T / T / TIF (this.getClass (). Equals (obj.getClass ())) / n / t / t / t {/ n "); Printf (" / t / t / t / t% s That = (% s) obj; / n ", DTO, DTO); Printf (" / t / t / t / t / t / T / TRETURN / N "); for (i = 0; i

# Hashcode () Printf ("/ tpublic int 6code () / n / t {/ n"); printf ("/ t / Treturn ("); for (i = 0; i

# tt () Printf ("/ TPUBLIC STRING TOSTRING () / N / T {/ N"); Printf ("/ t / treturn"); for (i = 0; i

Printf ("% s", x);} printf (";"); Printf ("/ n / t} / n / n");

Printf ("}");

######################################################################################################################################################################################################################################################################################################## ######## If there is bug, please tell me, thanks!:) # Jian, msn / email: yanjians@msn.com# 2004.03.30 ############### ###################################################################################

转载请注明原文地址:https://www.9cbs.com/read-23840.html

New Post(0)