Commit d4dbd4eb by Mark

更新代码生成器,支持adminlte主题

parent cca20342
......@@ -36,8 +36,8 @@ public class GenUtils {
templates.add("template/Service.java.vm");
templates.add("template/ServiceImpl.java.vm");
templates.add("template/Controller.java.vm");
templates.add("template/list.html.vm");
templates.add("template/list.js.vm");
templates.add("template/adminlte/list.html.vm");
templates.add("template/adminlte/list.js.vm");
templates.add("template/menu.sql.vm");
return templates;
}
......@@ -200,12 +200,12 @@ public class GenUtils {
}
if (template.contains("list.html.vm" )) {
return "main" + File.separator + "resources" + File.separator + "views" + File.separator
return "main" + File.separator + "resources" + File.separator + "adminlte" + File.separator
+ "modules" + File.separator + moduleName + File.separator + className.toLowerCase() + ".html";
}
if (template.contains("list.js.vm" )) {
return "main" + File.separator + "resources" + File.separator + "static" + File.separator + "js" + File.separator
return "main" + File.separator + "resources" + File.separator + "adminlte" + File.separator + "js" + File.separator
+ "modules" + File.separator + moduleName + File.separator + className.toLowerCase() + ".js";
}
......
package ${package}.${moduleName}.controller;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
......@@ -14,85 +14,77 @@ import org.springframework.web.bind.annotation.RestController;
import ${package}.${moduleName}.entity.${className}Entity;
import ${package}.${moduleName}.service.${className}Service;
import ${mainPath}.common.utils.PageUtils;
import ${mainPath}.common.utils.Query;
import ${mainPath}.common.utils.R;
/**
* ${comments}
*
*
* @author ${author}
* @email ${email}
* @date ${datetime}
*/
@RestController
@RequestMapping("/${moduleName}/${pathName}")
@RequestMapping("${moduleName}/${pathName}")
public class ${className}Controller {
@Autowired
private ${className}Service ${classname}Service;
/**
* 列表
*/
@RequestMapping("/list")
@RequiresPermissions("${moduleName}:${pathName}:list")
public R list(@RequestParam Map<String, Object> params){
//查询列表数据
Query query = new Query(params);
List<${className}Entity> ${classname}List = ${classname}Service.queryList(query);
int total = ${classname}Service.queryTotal(query);
PageUtils pageUtil = new PageUtils(${classname}List, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 信息
*/
@RequestMapping("/info/{${pk.attrname}}")
@RequiresPermissions("${moduleName}:${pathName}:info")
public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
${className}Entity ${classname} = ${classname}Service.queryObject(${pk.attrname});
return R.ok().put("${classname}", ${classname});
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("${moduleName}:${pathName}:save")
public R save(@RequestBody ${className}Entity ${classname}){
${classname}Service.save(${classname});
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("${moduleName}:${pathName}:update")
public R update(@RequestBody ${className}Entity ${classname}){
${classname}Service.update(${classname});
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("${moduleName}:${pathName}:delete")
public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
${classname}Service.deleteBatch(${pk.attrname}s);
return R.ok();
}
@Autowired
private ${className}Service ${classname}Service;
/**
* 列表
*/
@RequestMapping("/list")
@RequiresPermissions("${moduleName}:${pathName}:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = ${classname}Service.queryPage(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{${pk.attrname}}")
@RequiresPermissions("${moduleName}:${pathName}:info")
public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
${className}Entity ${classname} = ${classname}Service.selectById(${pk.attrname});
return R.ok().put("${classname}", ${classname});
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("${moduleName}:${pathName}:save")
public R save(@RequestBody ${className}Entity ${classname}){
${classname}Service.insert(${classname});
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("${moduleName}:${pathName}:update")
public R update(@RequestBody ${className}Entity ${classname}){
${classname}Service.updateById(${classname});
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("${moduleName}:${pathName}:delete")
public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
${classname}Service.deleteBatchIds(Arrays.asList(${pk.attrname}s));
return R.ok();
}
}
package ${package}.${moduleName}.dao;
import ${package}.${moduleName}.entity.${className}Entity;
import ${mainPath}.modules.sys.dao.BaseDao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
......@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date ${datetime}
*/
@Mapper
public interface ${className}Dao extends BaseDao<${className}Entity> {
public interface ${className}Dao extends BaseMapper<${className}Entity> {
}
......@@ -10,71 +10,5 @@
#end
</resultMap>
<select id="queryObject" resultType="${package}.${moduleName}.entity.${className}Entity">
select * from ${tableName} where ${pk.columnName} = #{value}
</select>
<select id="queryList" resultType="${package}.${moduleName}.entity.${className}Entity">
select * from ${tableName}
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by ${pk.columnName} desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from ${tableName}
</select>
<insert id="save" parameterType="${package}.${moduleName}.entity.${className}Entity"#if($pk.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$pk.attrname"#end>
insert into ${tableName}
(
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
`$column.columnName`#if($velocityCount != $columns.size()), #end
#end
#end
)
values
(
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
#{$column.attrname}#if($velocityCount != $columns.size()), #end
#end
#end
)
</insert>
<update id="update" parameterType="${package}.${moduleName}.entity.${className}Entity">
update ${tableName}
<set>
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
<if test="$column.attrname != null">`$column.columnName` = #{$column.attrname}#if($velocityCount != $columns.size()), #end</if>
#end
#end
</set>
where ${pk.columnName} = #{${pk.attrname}}
</update>
<delete id="delete">
delete from ${tableName} where ${pk.columnName} = #{value}
</delete>
<delete id="deleteBatch">
delete from ${tableName} where ${pk.columnName} in
<foreach item="${pk.attrname}" collection="array" open="(" separator="," close=")">
#{${pk.attrname}}
</foreach>
</delete>
</mapper>
\ No newline at end of file
package ${package}.${moduleName}.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
import java.util.Date;
/**
* ${comments}
......@@ -14,12 +16,18 @@ import java.math.BigDecimal;
* @email ${email}
* @date ${datetime}
*/
@TableName("${tableName}")
public class ${className}Entity implements Serializable {
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
//$column.comments
private $column.attrType $column.attrname;
/**
* $column.comments
*/
#if($column.columnName == $pk.columnName)
@TableId
#end
private $column.attrType $column.attrname;
#end
#foreach ($column in $columns)
......
package ${package}.${moduleName}.service;
import com.baomidou.mybatisplus.service.IService;
import ${mainPath}.common.utils.PageUtils;
import ${package}.${moduleName}.entity.${className}Entity;
import java.util.List;
import java.util.Map;
/**
* ${comments}
*
*
* @author ${author}
* @email ${email}
* @date ${datetime}
*/
public interface ${className}Service {
${className}Entity queryObject(${pk.attrType} ${pk.attrname});
List<${className}Entity> queryList(Map<String, Object> map);
int queryTotal(Map<String, Object> map);
void save(${className}Entity ${classname});
void update(${className}Entity ${classname});
void delete(${pk.attrType} ${pk.attrname});
void deleteBatch(${pk.attrType}[] ${pk.attrname}s);
public interface ${className}Service extends IService<${className}Entity> {
PageUtils queryPage(Map<String, Object> params);
}
package ${package}.${moduleName}.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import ${mainPath}.common.utils.PageUtils;
import ${mainPath}.common.utils.Query;
import ${package}.${moduleName}.dao.${className}Dao;
import ${package}.${moduleName}.entity.${className}Entity;
import ${package}.${moduleName}.service.${className}Service;
@Service("${classname}Service")
public class ${className}ServiceImpl implements ${className}Service {
@Autowired
private ${className}Dao ${classname}Dao;
@Override
public ${className}Entity queryObject(${pk.attrType} ${pk.attrname}){
return ${classname}Dao.queryObject(${pk.attrname});
}
@Override
public List<${className}Entity> queryList(Map<String, Object> map){
return ${classname}Dao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map){
return ${classname}Dao.queryTotal(map);
}
@Override
public void save(${className}Entity ${classname}){
${classname}Dao.save(${classname});
}
@Override
public void update(${className}Entity ${classname}){
${classname}Dao.update(${classname});
}
@Override
public void delete(${pk.attrType} ${pk.attrname}){
${classname}Dao.delete(${pk.attrname});
}
@Override
public void deleteBatch(${pk.attrType}[] ${pk.attrname}s){
${classname}Dao.deleteBatch(${pk.attrname}s);
}
public class ${className}ServiceImpl extends ServiceImpl<${className}Dao, ${className}Entity> implements ${className}Service {
@Override
public PageUtils queryPage(Map<String, Object> params) {
Page<${className}Entity> page = this.selectPage(
new Query<${className}Entity>(params).getPage(),
new EntityWrapper<${className}Entity>()
);
return new PageUtils(page);
}
}
<!DOCTYPE html>
<html>
<head>
<title>${comments}</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/font-awesome.min.css">
<link rel="stylesheet" href="../../plugins/jqgrid/ui.jqgrid-bootstrap.css">
<link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
<link rel="stylesheet" href="../../css/main.css">
<script src="../../libs/jquery.min.js"></script>
<script src="../../plugins/layer/layer.js"></script>
<script src="../../libs/bootstrap.min.js"></script>
<script src="../../libs/vue.min.js"></script>
<script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
<script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
<script src="../../js/common.js"></script>
<title>${comments}</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/font-awesome.min.css">
<link rel="stylesheet" href="../../plugins/jqgrid/ui.jqgrid-bootstrap.css">
<link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
<link rel="stylesheet" href="../../css/main.css">
<script src="../../libs/jquery.min.js"></script>
<script src="../../plugins/layer/layer.js"></script>
<script src="../../libs/bootstrap.min.js"></script>
<script src="../../libs/vue.min.js"></script>
<script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
<script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
<script src="../../js/common.js"></script>
</head>
<body>
<div id="rrapp" v-cloak>
<div v-show="showList">
<div class="grid-btn">
<a v-if="hasPermission('${moduleName}:${pathName}:save')" class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
<a v-if="hasPermission('${moduleName}:${pathName}:update')" class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
<a v-if="hasPermission('${moduleName}:${pathName}:delete')" class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
</div>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
<div v-show="showList">
<div class="grid-btn">
<a v-if="hasPermission('${moduleName}:${pathName}:save')" class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
<a v-if="hasPermission('${moduleName}:${pathName}:update')" class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
<a v-if="hasPermission('${moduleName}:${pathName}:delete')" class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
</div>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
</div>
<div v-show="!showList" class="panel panel-default">
<div class="panel-heading">{{title}}</div>
<form class="form-horizontal">
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
<div class="form-group">
<div class="col-sm-2 control-label">${column.comments}</div>
<div class="col-sm-10">
<input type="text" class="form-control" v-model="${classname}.${column.attrname}" placeholder="${column.comments}"/>
</div>
</div>
#end
#end
<div class="form-group">
<div class="col-sm-2 control-label"></div>
<input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
&nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
</div>
</form>
</div>
<div class="panel-heading">{{title}}</div>
<form class="form-horizontal">
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
<div class="form-group">
<div class="col-sm-2 control-label">${column.comments}</div>
<div class="col-sm-10">
<input type="text" class="form-control" v-model="${classname}.${column.attrname}" placeholder="${column.comments}"/>
</div>
</div>
#end
#end
<div class="form-group">
<div class="col-sm-2 control-label"></div>
<input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
&nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
</div>
</form>
</div>
</div>
<script src="../../js/modules/${moduleName}/${pathName}.js"></script>
......
......@@ -13,8 +13,8 @@
<div style="padding: 10px 0 20px 10px;">
<h3>&nbsp;&nbsp;&nbsp;获取帮助</h3>
<ul>
<li>Git地址:<a href="http://git.oschina.net/babaio/renren-generator" target="_blank">http://git.oschina.net/babaio/renren-generator</a></li>
<li>其他项目:<a href="http://www.renren.io/open/" target="_blank">http://www.renren.io/open/</a></li>
<li>Git地址:<a href="https://gitee.com/renrenio/renren-generator" target="_blank">https://gitee.com/renrenio/renren-generator</a></li>
<li>官方社区:<a href="http://www.renren.io/?s=index/Community" target="_blank">http://www.renren.io/?s=index/Community</a></li>
<li>如需关注项目最新动态,请Watch、Star项目,同时也是对项目最好的支持</li>
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment