Model.java
package cn.wizzer.common.base;
import cn.wizzer.modules.models.sys.Sys_user;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.ColType;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.EL;
import org.nutz.dao.entity.annotation.Prev;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.random.R;
import java.io.Serializable;
/**
* Created by wizzer on 2016/6/21.
*/
public abstract class Model implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Comment("操作人")
@Prev(els = @EL("$me.uid()"))
@ColDefine(type = ColType.VARCHAR, width = 32)
private String opBy;
@Column
@Comment("操作时间")
@Prev(els = @EL("$me.now()"))
@ColDefine(type = ColType.INT)
private Integer opAt;
@Column
@Comment("删除标记")
@Prev(els = @EL("$me.flag()"))
@ColDefine(type = ColType.BOOLEAN)
private Boolean delFlag;
public String toString() {
return String.format("/*%s*/%s", super.toString(), Json.toJson(this, JsonFormat.compact()));
}
public Boolean flag() {
return false;
}
public Integer now() {
return (int) (System.currentTimeMillis() / 1000);
}
public String uid() {
try {
Subject subject = SecurityUtils.getSubject();
Sys_user user = (Sys_user) subject.getPrincipal();
return user == null ? "" : user.getId();
} catch (Exception e) {
return "";
}
}
public String getOpBy() {
return opBy;
}
public void setOpBy(String opBy) {
this.opBy = opBy;
}
public Integer getOpAt() {
return opAt;
}
public void setOpAt(Integer opAt) {
this.opAt = opAt;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
public String uuid() {
return R.UU32().toLowerCase();
}
public String unitid() {
try {
Subject subject = SecurityUtils.getSubject();
Sys_user user = (Sys_user) subject.getPrincipal();
return user == null ? "" : user.getUnitid();
} catch (Exception e) {
return "";
}
}
}
bean
package cn.wizzer.modules.models.crm;
import cn.wizzer.common.base.Model;
import org.nutz.dao.DB;
import org.nutz.dao.entity.annotation.*;
import java.io.Serializable;
@Table("crm_customer")
public class Crm_customer extends Model implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Name
@Comment("ID")
@ColDefine(type = ColType.VARCHAR, width = 32)
@Prev(els = {@EL("uuid()")})
private String id;
@Column
@Comment("所属单位ID")
@ColDefine(type = ColType.VARCHAR, width = 32)
@Prev(els = {@EL("unitid()")})
private String parentId;
@Column
@Comment("公司名称")
@ColDefine(type = ColType.VARCHAR, width = 100)
private String name;
@Column
@Comment("公司简称")
@ColDefine(type = ColType.VARCHAR, width = 100)
private String aliasName;
@Column
@Comment("公司简介")
@ColDefine(type = ColType.VARCHAR, width = 255)
private String note;
@Column
@Comment("公司地址")
@ColDefine(type = ColType.VARCHAR, width = 100)
private String address;
@Column
@Comment("公司邮箱")
@ColDefine(type = ColType.VARCHAR, width = 100)
private String email;
@Column
@Comment("公司网站")
@ColDefine(type = ColType.VARCHAR, width = 100)
private String website;
@Column
@Comment("排序字段")
@Prev({
@SQL(db = DB.MYSQL, value = "SELECT IFNULL(MAX(location),0)+1 FROM crm_customer"),
@SQL(db = DB.ORACLE, value = "SELECT COALESCE(MAX(location),0)+1 FROM crm_customer")
})
private Integer location;
}
controller
package cn.wizzer.modules.controllers.platform.crm;
import cn.wizzer.common.annotation.SLog;
import cn.wizzer.common.base.Result;
import cn.wizzer.common.filter.PrivateFilter;
import cn.wizzer.common.page.DataTableColumn;
import cn.wizzer.common.page.DataTableOrder;
import cn.wizzer.modules.models.crm.Crm_customer;
import cn.wizzer.modules.services.crm.CrmCustomerService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@IocBean
@At("/platform/crm/customer")
@Filters({@By(type = PrivateFilter.class)})
public class CrmCustomerController {
private static final Log log = Logs.get();
@Inject
private CrmCustomerService crmCustomerService;
@At
@Ok("json")
@RequiresPermissions("crm.customer.company.add")
@SLog(tag = "添加客户", msg = "公司名称:${args[0].name}")
public Object addDo(@Param("..") Crm_customer crmCustomer, HttpServletRequest req) {
try {
crmCustomerService.insert(crmCustomer);
return Result.success("system.success");
} catch (Exception e) {
return Result.error("system.error");
}
}
}
执行结果
由于controller中catch异常,我直接打印出异常
2017-01-10 11:26:16,454 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/platform/crm/customer : CrmCustomerController.index(CrmCustomerController.java:39)
2017-01-10 11:26:16,454 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-10 11:26:16,455 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-10 11:26:16,456 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-10 11:26:16,456 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'crmCustomerController'<class cn.wizzer.modules.controllers.platform.crm.CrmCustomerController>
2017-01-10 11:26:16,457 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM crm_customer WHERE parentId IS NOT NULL ORDER BY location ASC
2017-01-10 11:26:16,799 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/platform/crm/customer 345ms
2017-01-10 11:26:17,788 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/platform/home/path : SysHomeController.path(SysHomeController.java:67)
2017-01-10 11:26:17,788 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-10 11:26:17,789 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-10 11:26:17,789 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-10 11:26:17,789 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'sysHomeController'<class cn.wizzer.modules.controllers.platform.sys.SysHomeController>
2017-01-10 11:26:17,790 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM sys_menu WHERE href IN (?,?,?) ORDER BY href DESC, path DESC LIMIT 0, 1
| 1 | 2 | 3 |
|------------------------|---------------|-----------|
| /platform/crm/customer | /platform/crm | /platform |
For example:> "SELECT * FROM sys_menu WHERE href IN ('/platform/crm/customer','/platform/crm','/platform') ORDER BY href DESC, path DESC LIMIT 0, 1 "
2017-01-10 11:26:17,791 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/platform/home/path 3ms
2017-01-10 11:26:17,846 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/platform/crm/customer/data : CrmCustomerController.data(CrmCustomerController.java:46)
2017-01-10 11:26:17,846 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-10 11:26:17,846 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-10 11:26:17,847 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-10 11:26:17,847 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'crmCustomerController'<class cn.wizzer.modules.controllers.platform.crm.CrmCustomerController>
2017-01-10 11:26:17,850 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT COUNT(*) FROM crm_customer
2017-01-10 11:26:17,867 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM crm_customer ORDER BY name ASC LIMIT 0, 10
2017-01-10 11:26:17,894 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/platform/crm/customer/data 48ms
2017-01-10 11:26:21,467 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/platform/crm/customer/add : CrmCustomerController.add(CrmCustomerController.java:55)
2017-01-10 11:26:21,467 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-10 11:26:21,467 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-10 11:26:21,468 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-10 11:26:21,468 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'crmCustomerController'<class cn.wizzer.modules.controllers.platform.crm.CrmCustomerController>
2017-01-10 11:26:21,472 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/platform/crm/customer/add 5ms
2017-01-10 11:27:17,864 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/platform/crm/customer/addDo : CrmCustomerController.addDo(CrmCustomerController.java:63)
2017-01-10 11:27:17,865 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-10 11:27:17,865 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-10 11:27:17,866 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-10 11:27:17,867 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'crmCustomerController'<class cn.wizzer.modules.controllers.platform.crm.CrmCustomerController>
2017-01-10 11:27:17,909 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - // NOT SQL // ElFieldMacro=uuid()
2017-01-10 11:27:17,909 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) DEBUG - Exception when parser SQL sql, skip cache detect!! SQL=RUN
2017-01-10 11:27:17,910 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - // NOT SQL // ElFieldMacro=unitid()
2017-01-10 11:27:17,910 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) DEBUG - Exception when parser SQL sql, skip cache detect!! SQL=RUN
org.nutz.dao.DaoException: org.nutz.el.ElException: no such key=unitid
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77)
at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63)
at org.nutz.trans.Trans.exec(Trans.java:174)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:247)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:157)
at cn.wizzer.common.base.Service.insert(Service.java:103)
at cn.wizzer.modules.controllers.platform.crm.CrmCustomerController.addDo(CrmCustomerController.java:63)
at cn.wizzer.modules.controllers.platform.crm.CrmCustomerController$$NUTZAOP._aop_invoke(CrmCustomerController.java:2)
at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
at cn.wizzer.common.services.log.SLogAopInterceptor.filter(SLogAopInterceptor.java:62)
at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
at cn.wizzer.modules.controllers.platform.crm.CrmCustomerController$$NUTZAOP.addDo(CrmCustomerController.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.common.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.common.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.common.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:37)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at cn.wizzer.common.filter.RouteFilter.doFilter(RouteFilter.java:33)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.el.ElException: no such key=unitid
at org.nutz.el.opt.object.MethodOpt.fetchMethod(MethodOpt.java:67)
at org.nutz.el.opt.object.MethodOpt.calculate(MethodOpt.java:48)
at org.nutz.el.opt.object.InvokeMethodOpt.calculate(InvokeMethodOpt.java:22)
at org.nutz.el.arithmetic.RPN.calculate(RPN.java:55)
at org.nutz.el.arithmetic.RPN.calculate(RPN.java:38)
at org.nutz.el.El.eval(El.java:30)
at org.nutz.dao.impl.entity.macro.ElFieldMacro.onAfter(ElFieldMacro.java:37)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:64)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor._exec(CachedNutDaoExecutor.java:317)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:111)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93)
... 77 more