IDCM項目學習筆記

來源:互聯網
上載者:User

標籤:

項目介紹:

IDCM:Internet Data center monitoring 網路資料中心監控平台

IRP:Information Resource planing 資訊資源規劃

 

1.設定表中公用欄位

在商務邏輯的表中,都有五個公用欄位,如下:

`gmt_create` datetime NOT NULL COMMENT ‘資料新增時間‘,`creator` varchar(128) NOT NULL DEFAULT ‘0‘ COMMENT ‘建立者‘,`gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘資料修改時間‘,`modifier` varchar(128) NOT NULL DEFAULT ‘0‘ COMMENT ‘修改者‘,`is_deleted` char(1) NOT NULL DEFAULT ‘n‘ COMMENT ‘是否邏輯刪除,預設為n‘,

在常見的增刪改查操作中,需要對錶中的五個欄位賦值。而添加每個實體類的時候,都有相同的方法,因此,我們將這些公用的部分提取出來,構造了CommonUtil.java類,如下:

package com.alibaba.tboss.common.auth.common;import java.lang.reflect.Method;import java.util.Date;import org.apache.commons.lang.StringUtils;import com.alibaba.tboss.common.auth.exception.AppAuthCommonException;import com.alibaba.tboss.common.auth.privilege.PrivilegeInfo;public class CommonUtil {    private static String SET_CREATOR     = "setCreator";    private static String SET_MODIFIER    = "setModifier";    private static String SET_GMTCREATE   = "setGmtCreate";    private static String SET_GMTMODIFIED = "setGmtModified";    private static String SET_ISDELETED   = "setIsDeleted";    public static void setCommonValueForCreate(Object pojo, PrivilegeInfo privilegeInfo) {        try {            Method setCreator = pojo.getClass().getMethod(SET_CREATOR, String.class);            setCreator.invoke(pojo, getOperator(privilegeInfo));            Method setModifier = pojo.getClass().getMethod(SET_MODIFIER, String.class);            setModifier.invoke(pojo, getOperator(privilegeInfo));            Method setGmtCreate = pojo.getClass().getMethod(SET_GMTCREATE, Date.class);            setGmtCreate.invoke(pojo, new Date());            Method setGmtModified = pojo.getClass().getMethod(SET_GMTMODIFIED, Date.class);            setGmtModified.invoke(pojo, new Date());            Method setIsDeleted = pojo.getClass().getMethod(SET_ISDELETED, String.class);            setIsDeleted.invoke(pojo, "n");        } catch (Exception e) {            throw new AppAuthCommonException("invoke method error ", e);        }    }    public static String getOperator(PrivilegeInfo pvgInfo) {        if (pvgInfo == null || StringUtils.isEmpty(pvgInfo.getWorkNo())) {            return "SYSTEM";        } else {            return pvgInfo.getWorkNo();        }    }}

CommonUtil.setCommonValueForCreate(bean,privilegeInfo);由於當前類中的方法是靜態方法,所以,我們在商務邏輯代碼中可以直接用類名來調用靜態方法.Java反射的使用.

2.<aop:scoped-proxy/>配置的解釋

首先,xml中的標籤<bean>、<property>、<map>、<entry>、<beans>是如何被解析的,參考xml基礎教程:

http://www.w3school.com.cn/x.asp

其次,bean的scope屬性取值:singleton、prototype、request、session、globalsession。

System.out.println(System.identityHashCode(s1));

 

IDCM項目學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.