新增仅查询功能(不含增删改)的代码生成模板 #IOZ3S

This commit is contained in:
thinkgem
2018-11-24 21:40:58 +08:00
parent 125018df1d
commit 0b63e8ad6b
7 changed files with 476 additions and 22 deletions

View File

@@ -15,34 +15,29 @@
<category value="treeGrid" label="树表/树结构表(增删改查)">
<template>category-ref:crud</template>
</category>
<category value="service" label="业务层和持久层(增删改查">
<category value="service" label="业务层和持久层(不含控制器和视图">
<template>category-ref:dao</template>
<template>crud/service.xml</template>
</category>
<category value="dao" label="仅持久层dao/mapper/entity">
<template>crud/dao.xml</template>
<template>crud/mapper.xml</template>
<template>crud/entity.xml</template>
<template>crud/dao.xml</template>
</category>
<category value="query" label="仅查询功能(不含增删改)">
<template>crud/mapper.xml</template>
<template>crud/entity.xml</template>
<template>query/dao.xml</template>
<template>query/service.xml</template>
<template>query/controller.xml</template>
<template>query/viewList.xml</template>
<template>query/viewForm.xml</template>
<childTable>
<template>crud/mapper.xml</template>
<template>crud/entity.xml</template>
<template>query/dao.xml</template>
</childTable>
</category>
<!-- <category value="tableForm" label="单表 - 表格表单(增删改查)"> -->
<!-- <template>category-ref:dao</template> -->
<!-- <template>crud/service.xml</template> -->
<!-- <template>crud/controller.xml</template> -->
<!-- <template>crud/viewList.xml</template> -->
<!-- <template>crud/viewTableForm.xml</template> -->
<!-- </category> -->
<!-- <category value="treeTableAndList" name="树结构表(左树右表)"> -->
<!-- <template>category-ref:dao</template> -->
<!-- </category> -->
<!-- <category value="query" label="仅查询功能"> -->
<!-- <template>query/entity.xml</template> -->
<!-- <template>query/mapper.xml</template> -->
<!-- <template>query/dao.xml</template> -->
<!-- <template>query/service.xml</template> -->
<!-- <template>query/controller.xml</template> -->
<!-- <template>query/viewList.xml</template> -->
<!-- <template>query/viewView.xml</template> -->
<!-- </category> -->
</tplCategory>
<!-- 属性类型 -->
<attrType>

View File

@@ -18,7 +18,7 @@ import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subMod
* @author ${functionAuthor}
* @version ${functionVersion}
*/
@MyBatisDao<% if(table.dataSourceName != ''){ %>(dataSourceName="${table.dataSourceName}")<% } %>
@MyBatisDao<% if(isNotBlank(table.dataSourceName)){ %>(dataSourceName="${table.dataSourceName}")<% } %>
public interface ${ClassName}Dao extends ${table.isTreeEntity?'Tree':'Crud'}Dao<${ClassName}> {
}]]>

View File

@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>controller</name>
<filePath>src/main/java/${packageName}/${moduleName}/web/${subModuleName}</filePath>
<fileName>${ClassName}Controller.java</fileName>
<content><![CDATA[
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModuleName:''};
<% if(table.isTreeEntity){ %>
import java.util.List;
import java.util.Map;
<% }else{ %>
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
<% } %>
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeesite.common.config.Global;
<% if(table.isTreeEntity){ %>
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.collect.MapUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.modules.sys.utils.UserUtils;
<% }else{ %>
import com.jeesite.common.entity.Page;
<% } %>
import com.jeesite.common.web.BaseController;
import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName};
import ${packageName}.${moduleName}.service${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName}Service;
/**
* ${functionName}Controller
* @author ${functionAuthor}
* @version ${functionVersion}
*/
@Controller
@RequestMapping(value = "\${adminPath}/${urlPrefix}")
public class ${ClassName}Controller extends BaseController {
@Autowired
private ${ClassName}Service ${className}Service;
/**
* 获取数据
*/
@ModelAttribute
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord) {
<% if (table.pkList.~size == 1){ %>
return ${className}Service.get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrName}<% } %>, isNewRecord);
<% }else{ %>
return ${className}Service.get(new Class<?>[]{<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType}.class<% } %>},
new Object[]{<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrName}<% } %>}, isNewRecord);
<% } %>
}
/**
* 查询列表
*/
@RequiresPermissions("${permissionPrefix}:view")
@RequestMapping(value = {"list", ""})
public String list(${ClassName} ${className}, Model model) {
model.addAttribute("${className}", ${className});
return "${lastPackageName}/${viewPrefix}List";
}
/**
* 查询列表数据
*/
@RequiresPermissions("${permissionPrefix}:view")
@RequestMapping(value = "listData")
@ResponseBody
<% if(table.isTreeEntity){ %>
public List<${ClassName}> listData(${ClassName} ${className}) {
if (StringUtils.isBlank(${className}.getParentCode())) {
${className}.setParentCode(${ClassName}.ROOT_CODE);
}
<% for(c in table.columnList){ %>
<% if(c.isQuery == "1" && !c.isTreeEntityColumn){ %>
if (StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})){
${className}.setParentCode(null);
}
<% } %>
<% } %>
List<${ClassName}> list = ${className}Service.findList(${className});
return list;
}
<% }else{ %>
public Page<${ClassName}> listData(${ClassName} ${className}, HttpServletRequest request, HttpServletResponse response) {
${className}.setPage(new Page<>(request, response));
Page<${ClassName}> page = ${className}Service.findPage(${className});
return page;
}
<% } %>
/**
* 查看编辑表单
*/
@RequiresPermissions("${permissionPrefix}:view")
@RequestMapping(value = "form")
public String form(${ClassName} ${className}, Model model) {
model.addAttribute("${className}", ${className});
return "${lastPackageName}/${viewPrefix}Form";
}
<% if(table.isTreeEntity){ %>
/**
* 获取树结构数据
* @param excludeCode 排除的Code
* @param isShowCode 是否显示编码true or 1显示在左侧2显示在右侧false or null不显示
* @return
*/
@RequiresPermissions("${permissionPrefix}:view")
@RequestMapping(value = "treeData")
@ResponseBody
public List<Map<String, Object>> treeData(String excludeCode, String isShowCode) {
List<Map<String, Object>> mapList = ListUtils.newArrayList();
List<${ClassName}> list = ${className}Service.findList(new ${ClassName}());
for (int i=0; i<list.size(); i++){
${ClassName} e = list.get(i);
// 过滤非正常的数据
if (!${ClassName}.STATUS_NORMAL.equals(e.getStatus())){
continue;
}
// 过滤被排除的编码(包括所有子级)
if (StringUtils.isNotBlank(excludeCode)){
if (e.getId().equals(excludeCode)){
continue;
}
if (e.getParentCodes().contains("," + excludeCode + ",")){
continue;
}
}
Map<String, Object> map = MapUtils.newHashMap();
map.put("id", e.getId());
map.put("pId", e.getParentCode());
map.put("name", StringUtils.getTreeNodeName(isShowCode, e.get${@StringUtils.cap(table.treeViewCodeAttrName)}(), e.get${@StringUtils.cap(table.treeViewNameAttrName)}()));
mapList.add(map);
}
return mapList;
}
<% } %>
}]]>
</content>
</template>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>dao</name>
<filePath>src/main/java/${packageName}/${moduleName}/dao/${subModuleName}</filePath>
<fileName>${ClassName}Dao.java</fileName>
<content><![CDATA[
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package ${packageName}.${moduleName}.dao${isNotEmpty(subModuleName)?'.'+subModuleName:''};
import com.jeesite.common.dao.${table.isTreeEntity?'Tree':'Query'}Dao;
import com.jeesite.common.mybatis.annotation.MyBatisDao;
import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName};
/**
* ${functionName}DAO接口
* @author ${functionAuthor}
* @version ${functionVersion}
*/
@MyBatisDao<% if(isNotBlank(table.dataSourceName)){ %>(dataSourceName="${table.dataSourceName}")<% } %>
public interface ${ClassName}Dao extends ${table.isTreeEntity?'Tree':'Query'}Dao<${ClassName}> {
}]]>
</content>
</template>

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>service</name>
<filePath>src/main/java/${packageName}/${moduleName}/service/${subModuleName}</filePath>
<fileName>${ClassName}Service.java</fileName>
<content><![CDATA[
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package ${packageName}.${moduleName}.service${isNotEmpty(subModuleName)?'.'+subModuleName:''};
import java.util.List;
<% if (table.childList.~size > 0){ %>
import org.springframework.beans.factory.annotation.Autowired;
<% } %>
import org.springframework.stereotype.Service;
import com.jeesite.common.entity.Page;
import com.jeesite.common.service.${table.isTreeEntity?'Tree':'Query'}Service;
import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName};
import ${packageName}.${moduleName}.dao${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName}Dao;
<% for (child in table.childList){ %>
import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${@StringUtils.cap(child.className)};
import ${packageName}.${moduleName}.dao${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${@StringUtils.cap(child.className)}Dao;
<% } %>
/**
* ${functionName}Service
* @author ${functionAuthor}
* @version ${functionVersion}
*/
@Service
public class ${ClassName}Service extends ${table.isTreeEntity?'Tree':'Query'}Service<${ClassName}Dao, ${ClassName}> {
<% for (child in table.childList){ %>
@Autowired
private ${@StringUtils.cap(child.className)}Dao ${@StringUtils.uncap(child.className)}Dao;
<% } %>
/**
* 获取单条数据
* @param ${className}
* @return
*/
@Override
public ${ClassName} get(${ClassName} ${className}) {
<% if (table.childList.~size > 0){ %>
${ClassName} entity = super.get(${className});
if (entity != null){
<% for (child in table.childList){ %>
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}(entity);
${@StringUtils.uncap(child.className)}.setStatus(${@StringUtils.cap(child.className)}.STATUS_NORMAL);
entity.set${@StringUtils.cap(child.className)}List(${@StringUtils.uncap(child.className)}Dao.findList(${@StringUtils.uncap(child.className)}));
<% } %>
}
return entity;
<% }else{ %>
return super.get(${className});
<% } %>
}
<% if(!table.isTreeEntity){ %>
/**
* 查询分页数据
* @param ${className} 查询条件
* @param ${className}.page 分页对象
* @return
*/
@Override
public Page<${ClassName}> findPage(${ClassName} ${className}) {
return super.findPage(${className});
}
<% }else{ %>
/**
* 查询列表数据
* @param ${className}
* @return
*/
@Override
public List<${ClassName}> findList(${ClassName} ${className}) {
return super.findList(${className});
}
<% } %>
}]]>
</content>
</template>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>viewForm</name>
<filePath>src/main/resources/views/${lastPackageName}/${moduleName}/${subModuleName}</filePath>
<fileName>${className}Form.html</fileName>
<content><![CDATA[
<%
var extLibs = '';
if(@ObjectUtils.toBoolean(table.optionMap['isImageUpload']) || @ObjectUtils.toBoolean(table.optionMap['isFileUpload'])){
extLibs = extLibs + ',\'fileupload\'';
}
if(table.childList.~size > 0){
extLibs = extLibs + ',\'dataGrid\'';
}
%>
\<% layout('/layouts/default.html', {title: '${functionNameSimple}查询', libs: ['validate'${extLibs}]}){ %>
<div class="main-content">
<div class="box box-main">
<div class="box-header with-border">
<div class="box-title">
<i class="fa fa-list-alt"></i> \${text(${className}.isNewRecord ? '新增${functionNameSimple}' : '详情${functionNameSimple}')}
</div>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
<${'#'}form:form id="inputForm" model="\${${className}}" action="\${ctx}/${urlPrefix}/save" method="post" class="form-horizontal">
<div class="box-body">
<div class="form-unit">\${text('基本信息')}</div>
<% if(table.isTreeEntity){ %>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4">\${text('上级${functionNameSimple}')}</label>
<div class="col-sm-8">
<${'#'}form:treeselect id="parent" title="\${text('上级${functionNameSimple}')}"
path="parent.id" labelPath="parent.${table.treeViewNameAttrName}"
url="\${ctx}/${urlPrefix}/treeData?excludeCode=\${${className}.id}"
class="" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
</div>
</div>
</div>
</div>
<% } %>
<% include('/templates/modules/gen/include/formControl.html'){} %>
<% include('/templates/modules/gen/include/formChildTable.html'){} %>
</div>
<div class="box-footer">
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> \${text('关 闭')}</button>
</div>
</div>
</div>
</${'#'}form:form>
</div>
</div>
\<% } %>
<% include('/templates/modules/gen/include/formChildTableScript.html'){} %>]]>
</content>
</template>

View File

@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>viewList</name>
<filePath>src/main/resources/views/${lastPackageName}/${moduleName}/${subModuleName}</filePath>
<fileName>${className}List.html</fileName>
<content><![CDATA[
\<% layout('/layouts/default.html', {title: '${functionNameSimple}查询', libs: ['dataGrid']}){ %>
<div class="main-content">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa fa-list-alt"></i> \${text('${functionNameSimple}查询')}
</div>
<div class="box-tools pull-right">
<a href="#" class="btn btn-default" id="btnSearch" title="\${text('查询')}"><i class="fa fa-filter"></i> \${text('查询')}</a>
<% if(table.isTreeEntity){ %>
<a href="#" class="btn btn-default" id="btnRefreshTree" title="\${text('刷新')}"><i class="fa fa-refresh"></i> \${text('刷新')}</a>
<a href="#" class="btn btn-default" id="btnExpandTreeNode" title="\${text('展开一级')}"><i class="fa fa-angle-double-down"></i> \${text('展开')}</a>
<a href="#" class="btn btn-default" id="btnCollapseTreeNode" title="\${text('折叠全部')}"><i class="fa fa-angle-double-up"></i> \${text('折叠')}</a>
<% } %>
</div>
</div>
<div class="box-body">
<% include('/templates/modules/gen/include/searchForm.html'){} %>
<table id="dataGrid"></table>
<% if(!table.isTreeEntity){ %>
<div id="dataGridPage"></div>
<% } %>
</div>
</div>
</div>
\<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
searchForm: $("#searchForm"),
columnModel: [
<%
// 是否是第一列
var firstColumn = true;
// 获取到唯一ID的url参数字符串
var idParam = '';
for(pk in table.pkList){
idParam = idParam + (pkLP.index!=1?'&':'') + pk.attrName + '=\'+row.' + pk.attrName + '+\'';
}
// 生成树表的节点列
if(table.isTreeEntity){
for(c in table.columnList){
if(c.attrName == table.treeViewNameAttrName){
%>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:250, align:"left", frozen:true, formatter: function(val, obj, row, act){
return '( '+row.${table.treeViewCodeAttrName}+' ) '+'<a href="\${ctx}/${urlPrefix}/form?${idParam}" class="btnList" data-title="\${text('查看${functionNameSimple}')}">'+(val||row.id)+'</a>';
}},
<%
firstColumn = false;
break;
}
}
}
%>
<%
for(c in table.columnList){
if(c.isList == "1"){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
}
// 如果是首列,则输出带链接的列
else if(firstColumn){
firstColumn = false;
%>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
return '<a href="\${ctx}/${urlPrefix}/form?${idParam}" class="btnList" data-title="\${text('查看${functionNameSimple}')}">'+(val||row.id)+'</a>';
}},
<% }else if(c.showType == 'select' || c.showType == 'select_multiple' || c.showType == 'checkbox' || c.showType == 'radio'){ %>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"center", formatter: function(val, obj, row, act){
return js.getDictLabel(\${@DictUtils.getDictListJson('${c.optionMap['dictType']}')}, val, '\${text('未知')}', true);
}},
<% }else if(c.showType == "userselect" || c.showType == "officeselect" || c.showType == "areaselect"){ %>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName2}', index:'a.${c.columnName}', width:150, align:"center"},
<% }else{
if (@StringUtils.inString(c.attrType, 'java.util.Date', 'Integer', 'Long')){
%>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"center"},
<%
}else if (@StringUtils.inString(c.attrType, 'Float', 'Double')){
%>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"right", formatter: function(val, obj, row, act){
return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值金额情况下设置0.00);
}},
<%
}else {
%>
{header:'\${text('${c.columnLabel}')}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"left"},
<%
}
}
}
}
%>
{header:'\${text('操作')}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
var actions = [];
actions.push('<a href="\${ctx}/${urlPrefix}/form?${idParam}" class="btnList" title="\${text('查看${functionNameSimple}')}"><i class="fa fa-file-text-o"></i></a>&nbsp;');
return actions.join('');
}}
],
<% if(table.isTreeEntity){ %>
treeGrid: true, // 启用树结构表格
defaultExpandLevel: 0, // 默认展开的层次
expandNodeClearPostData: '<%
for(c in table.columnList){
if(c.isQuery == "1" && !c.isTreeEntityColumn){
print(c.attrName + ',');
}
} %>', // 展开节点清理请求参数数据(一般设置查询条件的字段属性,否则在查询后,不能展开子节点数据)
<% } %>
// 加载成功后执行事件
ajaxSuccess: function(data){
}
});
</script>]]>
</content>
</template>