4 回答

TA貢獻1876條經驗 獲得超6個贊
注解本身并沒有任何作用,編譯后只會留在二進制字節(jié)碼中,不會參與函數的執(zhí)行過程
@Autowired 注解是用來注入參數的,但是如果本身是無參的,也就代表沒有要注入的參數,其實應該是可以省略的,當然,上面的代碼也可以換一下:
1234 | @Autowired public void regFun(TplFun pubtranslate){ ModelBeanMap.put( "pubtranslate" , pubtranslate); } |
我不保證是正確的,理解意思就好

TA貢獻2012條經驗 獲得超12個贊
這個是@Autowired 的定義
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})
public @interface Autowired {
/**
* Declares whether the annotated dependency is required.
* <p>Defaults to <code>true</code>.
*/
boolean required() default true;
}
只可用在構造方法,字段,以及實例方法上;方法參數注入這個不知你是指哪鐘?

TA貢獻1744條經驗 獲得超4個贊
public
class
TestController {
private
final
TestService1 test1;
private
final
TestService2 test2;
private
final
TestService3 test3;
@Autowired
public
TestController(TestService1 test1, TestService2 test2, TestService3 test3) {
this
.test1 = test1;
this
.test2 = test2;
this
.test3 = test3;
}
}
添加回答
舉報