I get tired by adding tons of getters / setters all the time in my beans. Is there an easy way to use annotations to get rid of this stupid job? or any other way? The second example is a short version that I would like to run, since there is no need to encapsulate my members (although in a different context this may be necessary). In my real world, I need to access 15 classes with about 10 data members in each class, which will create 300 useless setters / getters.
Example TestPerson.java (works):
public class TestPerson { public String firstName; public String lastName; public TestPerson() { firstName = "Hugo"; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }
Example TestPerson.java (NOT working):
public class TestPerson { public String firstName; public String lastName; public TestPerson() { firstName = "Hugo"; } }
Test.jsp example
<jsp:useBean id="testperson" class="test.TestPerson" scope="request" /> <html> <head><title>Test</title></head> <body> <h2>Results</h2>${testperson.firstName}<br> </body> </html>
Alex004
source share