Autowired注解

2018-04-03 14:34:34 浏览数 (1)

代码语言:javascript复制
package com.how2java.pojo;
 
import org.springframework.beans.factory.annotation.Autowired;
 
public class Product {
 
    private int id;
    private String name;
    @Autowired
//  等价于 @Resource(name="c")
    private Category category;
 
    public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public Category getCategory() {
        return category;
    }
// @Autowired
    public void setCategory(Category category) {
        this.category = category;
    }
}

--------------------Category类-----------------

0 人点赞