标签:style http color io os 使用 ar java sp
成功创建Koala Project,并且勾选集成业务日志子系统。
格式:
| @MethodAlias("业务方法别名") 业务方法 |
示例:
| @MethodAlias("savePersonInfo") public PersonInfo savePersonInfo(PersonInfo personInfo) { personInfo.save(); return personInfo; } |
要求:
在web模块src/main/resources的businessLogConfig目录下创建任意以*.groovy结尾的文件,
例:xxx.groovy。
模板:
| package org.openkoala.businesslog.config(非必要) import org.dayatang.domain.InstanceFacroty(非必要) class OrganizationApplicationImpl { (类名必须符合Java命名) //必须 def context
def OrganizationApplicationImpl_createAsTopOrganization() { "${getPreTemplate()}:创建顶层机构:${context._param0.name}" } def OrganizationApplicationImpl_createCompany() { "${getPreTemplate()}:为${context._param0.name},创建分公司:${context._param1.name}" } def OrganizationApplicationImpl_assignChildOrganization() { "${getPreTemplate()}:向${context._param0.name},分配子机构:${context._param1.name},期限为${context._param2}" } def OrganizationApplicationImpl_createDepartment() { "${getPreTemplate()}:在${context._param0.name}下创建部门:${context._param1.name}" } def OrganizationApplicationImpl_terminateEmployeeOrganizationRelation() { "${getPreTemplate()}:终止机构${context._param0.name}" } def getPreTemplate(){ "${context._user}-" } } |
说明:
日志模板实际上是一个groovy类,你可以定义任何方法,只有某个业务方法的别名(@MethodAlias的值)等于方法名,我们才认为它是一个业务日志方法,它的返回值(return或者放在方法最后一行的变量)将会被赋值给org.openkoala.businesslog.BusinessLog对象进行持久化。
日志方法返回值有两种情况:
1. 只返回一个String类型的日志文本;
2. 返回一个Map,这个Map包括key为category的日志分类及日志文本。
在类中,def context定义一个变量,这个变量实际上是一个Map。
Map中存储的是业务方法的返回值、参数。如果需要,你可以存储任何你需要的数据。你可以从这个context中取出你需要的内容,填充到你的日志中。默认情况下,我们会放一些默认的key在context中,请看下表。
context参数说明
| key |
value |
| _methodReturn |
业务方法返回值 |
| _param |
业务方法的参数, _param0代表第一个参数 _param1代表第二个参数,依此类推 |
| _executeError |
业务方法执行失败的异常信息 |
| _businessMethod |
业务方法 |
| _user |
业务方法操作人 |
| _time |
业务方法操作时间 |
| _ip |
ip地址 |
示例1:
class PersonInfoApplicationImpl {
def context
def savePersonInfo() {
"创建个人信息"
}
def pageQueryPersonInfo() {
"查询个人信息列表"
}
}
示例2:
package org.openkoala.businesslog.config
class PersonInfoApplicationImpl {
def context
def savePersonInfo() {
"${getPreTemplate()}:创建个人信息,名字为:${context._param0.name}"
}
def pageQueryPersonInfo() {
[category:"查询类", log:"查询个人信息列表"]
}
def getPreTemplate(){
"${context._user}-"
}
}
示例3:
package org.openkoala
import org.dayatang.domain.InstanceFactory
import org.openkoala.example.application.PersonInfoApplication
import org.openkoala.example.domain.PersonInfo
class PersonInfoApplicationImpl {
def context
def savePersonInfo() {
"${getPreTemplate()}:创建个人信息,名字为:${context._param0.name}"
}
def pageQueryPersonInfo() {
[category:"查询类", log:"查询个人信息列表"]
}
def removePersonInfo() {
PersonInfoApplication personInfoApplication
= InstanceFactory.getInstance(PersonInfoApplication.class)
String name = personInfoApplication.getPersonInfo(577).getName()
"删除用户信息:名称为:" + name
}
def getPreTemplate(){
"${context._user}-"
}
}
以上示例代码仅供参考
默认不需要配置,项目创建好会把接口实现类的包路径配置成切入点,可自行修改扩展。
切入点配置在web模块src/main/resources下koala-businesslog.properties里,key为pointcut
| pointcut=execution(* org.openkoala.example.application.impl.*.*(..)) || execution(* org.openkoala.example.facade.impl.*.*(..)) |
运行项目,访问地址:http://localhost:8080/pages/log/index.jsp
标签:style http color io os 使用 ar java sp
原文地址:http://my.oschina.net/xiaokaceng/blog/333019