All Downloads are FREE. Search and download functionalities are using the official Maven repository.

code.controller.vm Maven / Gradle / Ivy

package ${packageName};

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 ${table.EntityFullClassName};
import ${table.ServiceFullClassName};
import org.apache.shiro.authz.annotation.RequiresAuthentication;
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.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

#set($parameterId = '${args[0].id}')
#set($parameterId2 = "${args[2].getAttribute('id')}")
@IocBean
@At("${table.UriPrefix}")
@Filters({@By(type = PrivateFilter.class)})
public class ${table.ControllerClassName} {
	private static final Log log = Logs.get();
	@Inject
	private ${table.ServiceClassName} ${table.ServiceInstanceName};

	@At("")
	@Ok("beetl:/${table.ViewBasePath}/index.html")
	@RequiresAuthentication
	public void index() {

	}

	@At
	@Ok("json:full")
	@RequiresAuthentication
	public Object data(@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List order, @Param("::columns") List columns) {
		Cnd cnd = Cnd.NEW();
    	return ${table.ServiceInstanceName}.data(length, start, draw, order, columns, cnd, null);
    }

    @At
    @Ok("beetl:/${table.ViewBasePath}/add.html")
    @RequiresAuthentication
    public void add() {

    }

    @At
    @Ok("json")
    @SLog(tag = "新建${table.Label}", msg = "")
    public Object addDo(@Param("..") ${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) {
		try {
			${table.ServiceInstanceName}.insert(${table.EntityInstanceName});
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }

    @At("/edit/?")
    @Ok("beetl:/${table.ViewBasePath}/edit.html")
    @RequiresAuthentication
    public Object edit(${table.pkType} id) {
		return ${table.ServiceInstanceName}.fetch(id);
    }

    @At
    @Ok("json")
    @SLog(tag = "修改${table.Label}", msg = "ID:$parameterId")
    public Object editDo(@Param("..") ${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) {
		try {

			${table.EntityInstanceName}.setOpAt((int) (System.currentTimeMillis() / 1000));
			${table.ServiceInstanceName}.updateIgnoreNull(${table.EntityInstanceName});
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }


    @At({"/delete","/delete/?"})
    @Ok("json")
    @SLog(tag = "删除${table.Label}", msg = "ID:$parameterId2")
    public Object delete(${table.pkType} id, @Param("ids") ${table.pkType}[] ids ,HttpServletRequest req) {
		try {
			if(ids!=null&&ids.length>0){
				${table.ServiceInstanceName}.delete(ids);
    			req.setAttribute("id", org.apache.shiro.util.StringUtils.toString(ids));
			}else{
				${table.ServiceInstanceName}.delete(id);
    			req.setAttribute("id", id);
			}
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
    }


    @At("/detail/?")
    @Ok("beetl:/${table.ViewBasePath}/detail.html")
    @RequiresAuthentication
	public Object detail(${table.pkType} id) {
		if (!Strings.isBlank(id)) {
			return ${table.ServiceInstanceName}.fetch(id);

		}
		return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy