Key words: getters and setters, getter and setter methods, constructor using fields, constructor, eclipse-jee usage, Automatic GenerationCodeEclipse3.5, graphic tutorial
(1) The pojo class automatically generates the getter and setter methods:
Persion. Java original code:
Right-click the blank area of the code above, or right-click the person class name-> source-> Generate getters and setters, for example:
Then, in the generate getters and setters dialog box, hook the persion attribute ID and name, or directly click "select all" to select all attributes, and click OK.
Let's take a look at the person. Java class code:
It can be seen that the getter method and setter method are automatically generated, which is much easier than tapping the code one by one.
(2) automatically generate the constructor (constructor ):
Right-click the blank area of the class code, or right-click the class name-> source-> Generate constructor using fields, for example:
In the generate constructor using Fields dialog box, hook all or some attributes of the persion class, and click OK. For example:
Next, let's take a look at the self-generated constructor. See the selected section: