Created
August 23, 2015 02:38
-
-
Save arahansa/734b99bac44050326e1f to your computer and use it in GitHub Desktop.
Java Class Reader for making jstl statement and request information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.lang.reflect.Field; | |
public class ClassInfoGenerator { | |
public static void main(String[] args) { | |
// first parameter : Target Class name | |
// second parameter : variable name | |
ClassInfoGenerator.showMsg(Article.class, "article"); | |
} | |
public static void showMsg(Class<?> clazz, String variableName){ | |
Field[] fields = clazz.getDeclaredFields(); | |
for (Field field : fields) { //Setter | |
String varName = field.getName().substring(1); | |
String firstChar = field.getName().substring(0, 1).toUpperCase(); | |
String setVar = firstChar+varName; | |
System.out.println(variableName+".set"+setVar+"(request.getParameter(\""+field.getName()+"\"));"); | |
} | |
System.out.println(); | |
for (Field field : fields) //just EL | |
System.out.println("${"+variableName+"."+field.getName()+"}"); | |
System.out.println(); | |
for (Field field2 : fields) // td Lists | |
System.out.println("<td>${"+variableName+"."+field2.getName()+"}</td>"); | |
System.out.println(); | |
for (Field field : fields) { // input | |
System.out.println("<input type=\"text\" name=\""+field.getName()+"\" />"); | |
} | |
System.out.println("------------ Table ------------ "); | |
System.out.println("<table>"); | |
System.out.println("\t<tr>"); | |
for (Field field : fields) { | |
System.out.println("\t\t<th>"+field.getName()+"</th>"); | |
} | |
System.out.println("\t</tr>"); | |
System.out.println("\t<c:forEach var=\""+variableName+"\" items=\"${list}\">"); | |
System.out.println("\t\t<tr>"); | |
for (Field field2 : fields) //Lists | |
System.out.println("\t\t\t<td>${"+variableName+"."+field2.getName()+"}</td>"); | |
System.out.println("\t\t</tr>"); | |
System.out.println("\t</c:forEach>"); | |
System.out.println("</table>"); | |
} | |
} |
Author
arahansa
commented
Aug 23, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment