templet.controller.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wk-code-generator-nb Show documentation
Show all versions of wk-code-generator-nb Show documentation
java web development framework, base on nutz
package ${packageName};
import cn.wizzer.framework.base.Result;
import cn.wizzer.app.web.commons.slog.annotation.SLog;
import cn.wizzer.app.web.commons.utils.StringUtil;
import cn.wizzer.framework.page.datatable.DataTableColumn;
import cn.wizzer.framework.page.datatable.DataTableOrder;
import ${table.EntityFullClassName};
import ${table.ServiceFullClassName};
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Cnd;
import org.nutz.lang.Strings;
import org.nutz.lang.Times;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
#set($parameterId = '${args[0].id}')
#set($parameterId2 = "${req.getAttribute('id')}")
@IocBean
@At("${table.UriPrefix}")
public class ${table.ControllerClassName}{
private static final Log log = Logs.get();
@Inject
@Reference
private ${table.ServiceClassName} ${table.ServiceInstanceName};
@At("")
@Ok("beetl:/${table.ViewBasePath}/index.html")
@RequiresPermissions("${table.Permissions}")
public void index() {
}
@At("/data")
@Ok("json:full")
@RequiresPermissions("${table.Permissions}")
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("/add")
@Ok("beetl:/${table.ViewBasePath}/add.html")
@RequiresPermissions("${table.Permissions}")
public void add() {
}
@At("/addDo")
@Ok("json")
@RequiresPermissions("${table.Permissions}.add")
@SLog(tag = "${table.Label}", msg = "$parameterId")
public Object addDo(@Param("..")${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) {
try {
${table.EntityInstanceName}.setOpBy(StringUtil.getPlatformUid());
${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")
@RequiresPermissions("${table.Permissions}")
public void edit(${table.pkType} id,HttpServletRequest req) {
req.setAttribute("obj", ${table.ServiceInstanceName}.fetch(id));
}
@At("/editDo")
@Ok("json")
@RequiresPermissions("${table.Permissions}.edit")
@SLog(tag = "${table.Label}", msg = "$parameterId")
public Object editDo(@Param("..")${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) {
try {
${table.EntityInstanceName}.setOpBy(StringUtil.getPlatformUid());
${table.EntityInstanceName}.setOpAt(Times.getTS());
${table.ServiceInstanceName}.updateIgnoreNull(${table.EntityInstanceName});
return Result.success("system.success");
} catch (Exception e) {
return Result.error("system.error");
}
}
@At({"/delete/?", "/delete"})
@Ok("json")
@RequiresPermissions("${table.Permissions}.delete")
@SLog(tag = "${table.Label}", msg = "$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")
@RequiresPermissions("${table.Permissions}")
public void detail(${table.pkType} id, HttpServletRequest req) {#if( ${table.pkType} == "Integer")
if (id!=null&&id>0) {
req.setAttribute("obj", ${table.ServiceInstanceName}.fetch(id));
}else{
req.setAttribute("obj", null);
}#else
if (!Strings.isBlank(id)) {
req.setAttribute("obj", ${table.ServiceInstanceName}.fetch(id));
}else{
req.setAttribute("obj", null);
}#end
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy