1. 程式人生 > 實用技巧 >jq實現點選新增和刪除一行

jq實現點選新增和刪除一行

在Spring4之後,要使用註解開發,必須保證aop的包被匯入了,匯入context的約束,增加註解的支援

1.bean

@Component

2.屬性如何注入

@value

package com.yl.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//等價於<bean id = "user" class = "com.yl.pojo.User">
@Component
public class User {
@Value("lulu")//屬性注入
public String name;
}

3.衍生註解

@Component有幾個衍生註解,我們在web開發中,會按照mvc三層架構分層。

  • dao:@Repository

  • service:@Service

  • controller:@Controller

    這四個註解功能都是一樣的,都是代表將某個類註冊到Spring中,裝配Bean

4.作用域

@Scope:@Scope("singleton")

xml與註解:

  • xml更加萬能,適用於任何場合,維護簡單方便

  • 註解:不是自己類使用不了,維護相對複雜

  • 推薦xml用來管理bean,註解負責屬性的注入