package com.ydook.demo2.pojo;
import org.springframework.stereotype.Component;
// @Component:将 Car 类添加到 Spring 组件中
@Component
public class Car {
private String name;
private String price;
}
2. 右键 => 选择:generate:
3. 出现:generate 面板:
4. 点击:construct : 生成构造函数:
无参构造函数点击:Select None:
package com.ydook.demo2.pojo;
import org.springframework.stereotype.Component;
// @Component:将 Car 类添加到 Spring 组件中
@Component
public class Car {
private String name;
private String price;
public Car() {
}
有参构造函数点击:OK:
package com.ydook.demo2.pojo;
import org.springframework.stereotype.Component;
// @Component:将 Car 类添加到 Spring 组件中
@Component
public class Car {
private String name;
private String price;
public Car() {
public Car(String name, String price) {
this.name = name;
this.price = price;
}
5. 点击:Getter: 生成: 类参数获取方法:
package com.ydook.demo2.pojo;
import org.springframework.stereotype.Component;
// @Component:将 Car 类添加到 Spring 组件中
@Component
public class Car {
private String name;
private String price;
public Car() {
public Car(String name, String price) {
this.name = name;
this.price = price;
public String getName() {
return name;
public String getPrice() {
return price;
}
6. 如果已经生成相应的 getter函数或 setter函数,则不能重新定义:
7. 点击:Setter: 生成: 类参数设置方法:
package com.ydook.demo2.pojo;
import org.springframework.stereotype.Component;
// @Component:将 Car 类添加到 Spring 组件中
@Component
public class Car {
private String name;
private String price;
public Car() {
public Car(String name, String price) {
this.name = name;
this.price = price;
public String getName() {
return name;
public String getPrice() {
return price;
public void setName(String name) {
this.name = name;
public void setPrice(String price) {
this.price = price;
}