struts 自动将 Action 类中的属性装载为 bean

在ssh整合项目中,由于 struts 框架使用 spring-plugin ,当struts初始化时,struts 会自动装载 Action 类中属性(即 setXxx() 方法)。

例如:

public class TestAction {
    
    private AccountService service;

    public AccountService getService() {
        return service;
    }

    public void setService(AccountService service) {
        this.service = service;
    }
    
}

struts会把TestAction中的属性类型AccountService作为Spring bean装载。

牢记: struts为Action自动装载的属性的bean idsetXxx, getXxx中的xxx(首字母转为小写)。

即使属性名为如下,beanid也是service

public class TestAction {
    
    private AccountService service111111;

    public AccountService getService() {
        return service;
    }

    public void setService(AccountService service) {
        this.service = service;
    }
    
}

你可能感兴趣的:(struts 自动将 Action 类中的属性装载为 bean)