通过注解配置bean package org.jxnd.bean;import org.springframework.stereotype.Component;@Componentpublic class UserInfo implements BaseBean{private Integer id;private String name;private String pwd;private Integer rolesid;private Roles
package org.jxnd.bean; import org.springframework.stereotype.Component; @Component public class UserInfo implements BaseBean{ private Integer id; private String name; private String pwd; private Integer rolesid; private Roles rinfo; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public Integer getRolesid() { return rolesid; } public void setRolesid(Integer rolesid) { this.rolesid = rolesid; } public Roles getRinfo() { return rinfo; } public void setRinfo(Roles rinfo) { this.rinfo = rinfo; } @Override public String toString() { return "UserInfo [id=" + id + ", name=" + name + ", pwd=" + pwd + ", rolesid=" + rolesid + ", rinfo=" + rinfo + "]"; } public UserInfo(Integer id, String name, String pwd, Integer rolesid, Roles rinfo) { super(); this.id = id; this.name = name; this.pwd = pwd; this.rolesid = rolesid; this.rinfo = rinfo; } public UserInfo(Integer id, String name, String pwd, Integer rolesid) { super(); this.id = id; this.name = name; this.pwd = pwd; this.rolesid = rolesid; } //构造函数,你写或者不写,它都在 public UserInfo() { System.out.println("这是一个构造函数"); } } 使用注解配置Bean -->@Component 组件,和下面三个注解功能等效,但下面功能强大于我,推荐每层用自己的注解,如果实在分不清当前包奴属于那一层,请使用我 -->@Repository DAO层注解 -->@Service Service层注解 -->@Controller Controller注解 -->@Autowired 自动注入,按类型进行匹配 -->如果没找到会抛异常,如不想抛异常,请使用required属性 -->可使用在属性上,亦可在使用在方法上 -->@Qualifier 指定名称注入 -->可使用在属性上,亦可使用在方法上,亦可使用在方法参数上 -->@Scope 配置生命周期 -->必须在配置文件加入