Commit d4dbd4eb by Mark

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

parent cca20342
...@@ -36,8 +36,8 @@ public class GenUtils { ...@@ -36,8 +36,8 @@ public class GenUtils {
templates.add("template/Service.java.vm"); templates.add("template/Service.java.vm");
templates.add("template/ServiceImpl.java.vm"); templates.add("template/ServiceImpl.java.vm");
templates.add("template/Controller.java.vm"); templates.add("template/Controller.java.vm");
templates.add("template/list.html.vm"); templates.add("template/adminlte/list.html.vm");
templates.add("template/list.js.vm"); templates.add("template/adminlte/list.js.vm");
templates.add("template/menu.sql.vm"); templates.add("template/menu.sql.vm");
return templates; return templates;
} }
...@@ -200,12 +200,12 @@ public class GenUtils { ...@@ -200,12 +200,12 @@ public class GenUtils {
} }
if (template.contains("list.html.vm" )) { 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"; + "modules" + File.separator + moduleName + File.separator + className.toLowerCase() + ".html";
} }
if (template.contains("list.js.vm" )) { 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"; + "modules" + File.separator + moduleName + File.separator + className.toLowerCase() + ".js";
} }
......
package ${package}.${moduleName}.controller; package ${package}.${moduleName}.controller;
import java.util.List; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
...@@ -14,12 +14,10 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -14,12 +14,10 @@ import org.springframework.web.bind.annotation.RestController;
import ${package}.${moduleName}.entity.${className}Entity; import ${package}.${moduleName}.entity.${className}Entity;
import ${package}.${moduleName}.service.${className}Service; import ${package}.${moduleName}.service.${className}Service;
import ${mainPath}.common.utils.PageUtils; import ${mainPath}.common.utils.PageUtils;
import ${mainPath}.common.utils.Query;
import ${mainPath}.common.utils.R; import ${mainPath}.common.utils.R;
/** /**
* ${comments} * ${comments}
* *
...@@ -28,7 +26,7 @@ import ${mainPath}.common.utils.R; ...@@ -28,7 +26,7 @@ import ${mainPath}.common.utils.R;
* @date ${datetime} * @date ${datetime}
*/ */
@RestController @RestController
@RequestMapping("/${moduleName}/${pathName}") @RequestMapping("${moduleName}/${pathName}")
public class ${className}Controller { public class ${className}Controller {
@Autowired @Autowired
private ${className}Service ${classname}Service; private ${className}Service ${classname}Service;
...@@ -39,15 +37,9 @@ public class ${className}Controller { ...@@ -39,15 +37,9 @@ public class ${className}Controller {
@RequestMapping("/list") @RequestMapping("/list")
@RequiresPermissions("${moduleName}:${pathName}:list") @RequiresPermissions("${moduleName}:${pathName}:list")
public R list(@RequestParam Map<String, Object> params){ public R list(@RequestParam Map<String, Object> params){
//查询列表数据 PageUtils page = ${classname}Service.queryPage(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); return R.ok().put("page", page);
} }
...@@ -57,7 +49,7 @@ public class ${className}Controller { ...@@ -57,7 +49,7 @@ public class ${className}Controller {
@RequestMapping("/info/{${pk.attrname}}") @RequestMapping("/info/{${pk.attrname}}")
@RequiresPermissions("${moduleName}:${pathName}:info") @RequiresPermissions("${moduleName}:${pathName}:info")
public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){ public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
${className}Entity ${classname} = ${classname}Service.queryObject(${pk.attrname}); ${className}Entity ${classname} = ${classname}Service.selectById(${pk.attrname});
return R.ok().put("${classname}", ${classname}); return R.ok().put("${classname}", ${classname});
} }
...@@ -68,7 +60,7 @@ public class ${className}Controller { ...@@ -68,7 +60,7 @@ public class ${className}Controller {
@RequestMapping("/save") @RequestMapping("/save")
@RequiresPermissions("${moduleName}:${pathName}:save") @RequiresPermissions("${moduleName}:${pathName}:save")
public R save(@RequestBody ${className}Entity ${classname}){ public R save(@RequestBody ${className}Entity ${classname}){
${classname}Service.save(${classname}); ${classname}Service.insert(${classname});
return R.ok(); return R.ok();
} }
...@@ -79,7 +71,7 @@ public class ${className}Controller { ...@@ -79,7 +71,7 @@ public class ${className}Controller {
@RequestMapping("/update") @RequestMapping("/update")
@RequiresPermissions("${moduleName}:${pathName}:update") @RequiresPermissions("${moduleName}:${pathName}:update")
public R update(@RequestBody ${className}Entity ${classname}){ public R update(@RequestBody ${className}Entity ${classname}){
${classname}Service.update(${classname}); ${classname}Service.updateById(${classname});
return R.ok(); return R.ok();
} }
...@@ -90,7 +82,7 @@ public class ${className}Controller { ...@@ -90,7 +82,7 @@ public class ${className}Controller {
@RequestMapping("/delete") @RequestMapping("/delete")
@RequiresPermissions("${moduleName}:${pathName}:delete") @RequiresPermissions("${moduleName}:${pathName}:delete")
public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){ public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
${classname}Service.deleteBatch(${pk.attrname}s); ${classname}Service.deleteBatchIds(Arrays.asList(${pk.attrname}s));
return R.ok(); return R.ok();
} }
......
package ${package}.${moduleName}.dao; package ${package}.${moduleName}.dao;
import ${package}.${moduleName}.entity.${className}Entity; import ${package}.${moduleName}.entity.${className}Entity;
import ${mainPath}.modules.sys.dao.BaseDao; import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
...@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date ${datetime} * @date ${datetime}
*/ */
@Mapper @Mapper
public interface ${className}Dao extends BaseDao<${className}Entity> { public interface ${className}Dao extends BaseMapper<${className}Entity> {
} }
...@@ -10,71 +10,5 @@ ...@@ -10,71 +10,5 @@
#end #end
</resultMap> </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> </mapper>
\ No newline at end of file
package ${package}.${moduleName}.entity; package ${package}.${moduleName}.entity;
import java.io.Serializable; import com.baomidou.mybatisplus.annotations.TableId;
import java.util.Date; import com.baomidou.mybatisplus.annotations.TableName;
#if(${hasBigDecimal}) #if(${hasBigDecimal})
import java.math.BigDecimal; import java.math.BigDecimal;
#end #end
import java.io.Serializable;
import java.util.Date;
/** /**
* ${comments} * ${comments}
...@@ -14,12 +16,18 @@ import java.math.BigDecimal; ...@@ -14,12 +16,18 @@ import java.math.BigDecimal;
* @email ${email} * @email ${email}
* @date ${datetime} * @date ${datetime}
*/ */
@TableName("${tableName}")
public class ${className}Entity implements Serializable { public class ${className}Entity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
#foreach ($column in $columns) #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 #end
#foreach ($column in $columns) #foreach ($column in $columns)
......
package ${package}.${moduleName}.service; package ${package}.${moduleName}.service;
import com.baomidou.mybatisplus.service.IService;
import ${mainPath}.common.utils.PageUtils;
import ${package}.${moduleName}.entity.${className}Entity; import ${package}.${moduleName}.entity.${className}Entity;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -12,19 +13,8 @@ import java.util.Map; ...@@ -12,19 +13,8 @@ import java.util.Map;
* @email ${email} * @email ${email}
* @date ${datetime} * @date ${datetime}
*/ */
public interface ${className}Service { public interface ${className}Service extends IService<${className}Entity> {
${className}Entity queryObject(${pk.attrType} ${pk.attrname}); PageUtils queryPage(Map<String, Object> params);
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);
} }
package ${package}.${moduleName}.service.impl; package ${package}.${moduleName}.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map; 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}.dao.${className}Dao;
import ${package}.${moduleName}.entity.${className}Entity; import ${package}.${moduleName}.entity.${className}Entity;
import ${package}.${moduleName}.service.${className}Service; import ${package}.${moduleName}.service.${className}Service;
@Service("${classname}Service") @Service("${classname}Service")
public class ${className}ServiceImpl implements ${className}Service { public class ${className}ServiceImpl extends ServiceImpl<${className}Dao, ${className}Entity> 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 @Override
public List<${className}Entity> queryList(Map<String, Object> map){ public PageUtils queryPage(Map<String, Object> params) {
return ${classname}Dao.queryList(map); Page<${className}Entity> page = this.selectPage(
} new Query<${className}Entity>(params).getPage(),
new EntityWrapper<${className}Entity>()
);
@Override return new PageUtils(page);
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);
} }
} }
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>${comments}</title> <title>${comments}</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <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"> <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/bootstrap.min.css">
<link rel="stylesheet" href="../../css/font-awesome.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/jqgrid/ui.jqgrid-bootstrap.css">
<link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css"> <link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
<link rel="stylesheet" href="../../css/main.css"> <link rel="stylesheet" href="../../css/main.css">
<script src="../../libs/jquery.min.js"></script> <script src="../../libs/jquery.min.js"></script>
<script src="../../plugins/layer/layer.js"></script> <script src="../../plugins/layer/layer.js"></script>
<script src="../../libs/bootstrap.min.js"></script> <script src="../../libs/bootstrap.min.js"></script>
<script src="../../libs/vue.min.js"></script> <script src="../../libs/vue.min.js"></script>
<script src="../../plugins/jqgrid/grid.locale-cn.js"></script> <script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
<script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script> <script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="../../plugins/ztree/jquery.ztree.all.min.js"></script> <script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
<script src="../../js/common.js"></script> <script src="../../js/common.js"></script>
</head> </head>
<body> <body>
<div id="rrapp" v-cloak> <div id="rrapp" v-cloak>
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
<div style="padding: 10px 0 20px 10px;"> <div style="padding: 10px 0 20px 10px;">
<h3>&nbsp;&nbsp;&nbsp;获取帮助</h3> <h3>&nbsp;&nbsp;&nbsp;获取帮助</h3>
<ul> <ul>
<li>Git地址:<a href="http://git.oschina.net/babaio/renren-generator" target="_blank">http://git.oschina.net/babaio/renren-generator</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/open/" target="_blank">http://www.renren.io/open/</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> <li>如需关注项目最新动态,请Watch、Star项目,同时也是对项目最好的支持</li>
</ul> </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