내 Struts2 애플리케이션에서 Hibernate 인터셉터를 사용하여 모든 CURD 작업을 감사하고 싶습니다. 구현 방법을 알려주십시오.Struts2에서 hibernate 인터셉터를 구현하는 방법
0
A
답변
0
당신은 EmptyInterceptor
을 확장하여 인터셉터를 만들 수 있습니다, 설명서를 읽어
Chapter 12. Interceptors and events
문서는 인터셉터를 사용하여 감사를 구현하는 방법에 대한 예제가 있습니다. 당신은 인터셉터를 구현하여 또는 EmptyInterceptor
을 확장하여 XXXDAO
클래스를 만들 수 있습니다 Hibernate interceptor example – audit log
0
:
또한 여기에 유사한 기능의 또 다른 예이다. Interceptor
인터페이스를 사용하는 경우 아래에서 재정의 된 방법을 사용하여 별도의 테이블에 데이터를 저장하십시오. 당신은 EmptyInterceptor
에게 모든 메소드를 오버라이드 (override) 할 필요를 확장하지 않으면
public boolean onLoad(Object o, Serializable srlzbl, Object[] os, String[] strings, Type[] types) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean onFlushDirty(Object o, Serializable srlzbl, Object[] os, Object[] os1, String[] strings, Type[] types) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean onSave(Object o, Serializable srlzbl, Object[] os, String[] strings, Type[] types) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void onDelete(Object o, Serializable srlzbl, Object[] os, String[] strings, Type[] types) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void onCollectionRecreate(Object o, Serializable srlzbl) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void onCollectionRemove(Object o, Serializable srlzbl) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void onCollectionUpdate(Object o, Serializable srlzbl) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void preFlush(Iterator itrtr) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void postFlush(Iterator itrtr) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public Boolean isTransient(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public int[] findDirty(Object o, Serializable srlzbl, Object[] os, Object[] os1, String[] strings, Type[] types) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Object instantiate(String string, EntityMode em, Serializable srlzbl) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public String getEntityName(Object o) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public Object getEntity(String string, Serializable srlzbl) throws CallbackException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void afterTransactionBegin(Transaction t) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void beforeTransactionCompletion(Transaction t) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void afterTransactionCompletion(Transaction t) {
throw new UnsupportedOperationException("Not supported yet.");
}
public String onPrepareStatement(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
, 필요한 방법은 DAO 클래스에서 재정의 할 수 있습니다.
예를 들어 내 감사 테이블에 fieldName
, fieldValue
, fieldType
, className
, 방법 save()
위해를 저장해야합니다. 업데이트 사용 findDirty()
방법에 대한 삭제 사용 onDelete()
방법
//Audit save Pojo
public class AuditSave{
private String className;
private String fieldName
private String fieldValue
private String fieldType
//setter's and getter's
}
//AuditDAO class
public class AuditDao exteds EmptyInterceptor{
public boolean onSave(Object o, Serializable srlzbl, Object[] os, String[] strings,
Type[] types) throws CallbackException {
Session session = HibernateUtil.getSessionFactory().openSesson();
String className = o.getClass().getName();
try{
Transaction tx = session.beginTransaction();
for(int i = 0;i < os.length ;i++){
AuditSave auditSave = new AuditSave();
auditSave.setClassName(className);
auditSave.setFieldName((String)strings[i]);
auditSave.setFieldValue((String)os[i]);
auditSave.setFieldType(types[i].toString());
session.save(auditSave);
tx.commit();
}catch(Exception e){
tx.rollback();
e.printStackTra;
}
if(session.isOpen())
session.close();
}
return true;
}
// same as update,delete
,
관련 문제
- 1. req/res 인터셉터를 구현하는 방법
- 2. 우리는 Struts2에서 JSON 액션을위한 인터셉터를 가지고 있습니까
- 3. iBATIS를 사용하여 감사 인터셉터를 구현하는 방법은 무엇입니까?
- 4. java struts2에서 내보내기 기능을 구현하는 방법
- 5. struts2에서 폼 기반 인증을 구현하는 방법
- 6. 런타임에 세션 팩토리에 Hibernate 인터셉터를 추가하십시오.
- 7. hibernate 인터셉터를 사용하여 조인 테이블에서 추가 필드를 채우는 방법?
- 8. jdbi에서 감사 인터셉터를 구현하는 방법은 무엇입니까?
- 9. struts2에서 URL 인증을 수행하는 방법
- 10. Struts2에서 i18n 인터셉터 사용
- 11. struts2에서 사용자 정의 conversionerrorinterceptor를 구성하는 방법
- 12. 주입 시간에 인터셉터를 지정하는 방법
- 13. 런타임시 메서드 인터셉터를 비활성화하는 방법
- 14. UsernameTokenInterceptor cxf 인터셉터를 추가하는 방법
- 15. struts2는 Struts2에서
- 16. Hibernate 인터셉터를 사용할 때 Struts2 웹 응용 프로그램에서 Hibernate 세션을 열고 닫아야하는 곳
- 17. struts2에서 간단한 테마를 사용하는 방법
- 18. struts2에서 $ .ajax() 메서드를 사용하는 방법
- 19. struts2에서 xml 응답을 얻는 방법
- 20. Struts2에서 Ajax 응답을 얻는 방법
- 21. struts2에서 세션의 숫자를 포맷하는 방법
- 22. Struts2에서 동작 별칭을 만드는 방법
- 23. Spring과 Hibernate : 하나의 폼에서 하나 이상의 POJO를 구현하는 방법
- 24. struts2에서 Ajax를
- 25. Struts2에서 양식에 테두리 추가
- 26. Struts2에서 데이터 필터링 jqGrid
- 27. URL struts2에서 다시 쓰기
- 28. 'after'함수를 사용하여 받침대에 인터셉터를 만드는 방법
- 29. postgeapp와 함께 작동하는 메일 인터셉터를 얻는 방법
- 30. IEnumerable을 반환하는 메서드에 대한 인터셉터를 작성하는 방법