Kaynağa Gözat

代码生成

x1ongzhu 6 yıl önce
ebeveyn
işleme
d2760ea3e0

+ 4 - 7
src/main/java/com/izouma/codegenerator/GeneratorTool.java

@@ -12,6 +12,7 @@ import org.apache.velocity.context.Context;
 import org.hibernate.validator.internal.util.privilegedactions.GetResource;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -139,7 +140,7 @@ public class GeneratorTool {
         template.merge(context, stringWriter);
         String newContent = stringWriter.toString();
         try {
-            oldContent = new String(Files.readAllBytes(path));
+            oldContent = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
         } catch (Exception ignored) {
         }
         if (StringUtils.isEmpty(oldContent)) {
@@ -161,14 +162,14 @@ public class GeneratorTool {
             if (Files.notExists(path)) {
                 Files.createFile(path);
             }
-            Files.write(path, content.getBytes());
+            Files.write(path, content.getBytes(StandardCharsets.UTF_8));
         } catch (Exception e) {
             logger.error(e);
         }
     }
 
     public static String replaceGeneratedCode(String src, String dst) {
-        String regex = "<!--generatedStart-->[\\s\\S]*?<!--generatedEnd-->";
+        String regex = "<!--generatedStart-->[\\s\\S]*?<!--generatedEnd-->|/\\*generatedStart\\*/[\\s\\S]*?\\*generatedEnd\\*/";
         Pattern pattern = Pattern.compile(regex);
         Matcher srcMatcher = pattern.matcher(src);
         Matcher dstMatcher = pattern.matcher(dst);
@@ -182,8 +183,4 @@ public class GeneratorTool {
         list.add(src.substring(lastIndex));
         return StringUtils.join(list, "");
     }
-
-    public static void main(String[] args) {
-
-    }
 }

+ 4 - 4
src/main/resources/templates/ControllerTemplate.vm

@@ -23,12 +23,12 @@ import javax.servlet.http.HttpServletResponse;
 @Controller
 @RequestMapping("/$display.uncapitalize($model.className)")
 public class ${model.className}Controller {
-    <!--generatedStart-->
+    /*generatedStart*/
     @Autowired
     private ${model.className}Service $display.uncapitalize(${model.className})Service;
-    <!--generatedEnd-->
+    /*generatedEnd*/
 
-    <!--generatedStart-->
+    /*generatedStart*/
     @RequiresAuthentication
     @RequestMapping(value = "/all", method = RequestMethod.GET)
     @ResponseBody
@@ -117,6 +117,6 @@ public class ${model.className}Controller {
         ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName,
                 columnNumber, columnWidth, columnName, dataList, response);
     }
-    <!--generatedEnd-->
+    /*generatedEnd*/
 }
 

+ 2 - 1
src/main/resources/templates/MapperSqlServerTemplate.vm

@@ -15,7 +15,7 @@ import com.izouma.awesomeadmin.model.${model.className};
 @DataSource("dataSourceSqlserver")
 @Repository("com.zoumaframe.dao.${model.className}Mapper")
 public interface ${model.className}Mapper{
-
+    /*generatedStart*/
     int deleteByPrimaryKey(Integer id);
 
     int insertSelective(${model.className} record);
@@ -33,5 +33,6 @@ public interface ${model.className}Mapper{
     ${model.className} query${model.className}(${model.className} record);
 
     List<${model.className}> query(${model.className} record);
+    /*generatedEnd*/
 }
 

+ 2 - 2
src/main/resources/templates/MapperTemplate.vm

@@ -17,7 +17,7 @@ import com.izouma.awesomeadmin.model.${model.className};
 #end
 @Repository("com.zoumaframe.dao.${model.className}Mapper")
 public interface ${model.className}Mapper{
-    <!--generatedStart-->
+    /*generatedStart*/
     int deleteByPrimaryKey(Integer id);
 
     int insertSelective(${model.className} record);
@@ -35,7 +35,7 @@ public interface ${model.className}Mapper{
     ${model.className} query${model.className}(${model.className} record);
 
     List<${model.className}> query(${model.className} record);
-    <!--generatedEnd-->
+    /*generatedEnd*/
 
 }
 

+ 2 - 2
src/main/resources/templates/MapperXmlTemplate.vm

@@ -14,12 +14,12 @@
         <!--generatedEnd-->
     </resultMap>
 
-    <!--generatedStart-->
     <sql id="Base_Column_List">
+        <!--generatedStart-->
         #foreach($field in $model.fields)
 #*        *#${field.name}#if( $foreach.hasNext ), #end
 #*    *##end
-
+        <!--generatedEnd-->
     </sql>
 
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">

+ 4 - 4
src/main/resources/templates/ModelTemplate.vm

@@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 @JsonAutoDetect
 @JsonInclude(JsonInclude.Include.NON_NULL)
 public class $model.className{
-    <!--generatedStart-->
+    /*generatedStart*/
 #foreach($field in $model.fields)
     private $field.javaType $field.modelName;
 #end
@@ -29,9 +29,9 @@ public class $model.className{
     * column_name_,desc_;column_name_,asc
     */
     private String orderByStr;
-    <!--generatedEnd-->
+    /*generatedEnd*/
 
-    <!--generatedStart-->
+    /*generatedStart*/
 #foreach($field in $model.fields)
     public $field.javaType get${display.capitalize($field.modelName)}(){
         return this.$field.modelName;
@@ -73,7 +73,7 @@ public class $model.className{
     public void setIdStr(String idStr) {
         this.idStr = idStr;
     }
-    <!--generatedEnd-->
+    /*generatedEnd*/
 
 }
 

+ 4 - 4
src/main/resources/templates/ServiceImplTemplate.vm

@@ -18,14 +18,14 @@ import com.izouma.awesomeadmin.dao.${model.className}Mapper;
 */
 @Service
 public class ${model.className}ServiceImpl implements ${model.className}Service{
-    <!--generatedStart-->
+    /*generatedStart*/
     private static Logger logger = Logger.getLogger(${model.className}ServiceImpl.class);
 
     @Autowired
     private ${model.className}Mapper ${display.uncapitalize(${model.className})}Mapper;
-    <!--generatedEnd-->
+    /*generatedEnd*/
 
-    <!--generatedStart-->
+    /*generatedStart*/
     @Override
     public List<${model.className}> get${model.className}List(${model.className} record) {
         logger.info("get${model.className}List");
@@ -115,6 +115,6 @@ public class ${model.className}ServiceImpl implements ${model.className}Service{
         }
         return false;
     }
-    <!--generatedEnd-->
+    /*generatedEnd*/
 }
 

+ 2 - 2
src/main/resources/templates/ServiceTemplate.vm

@@ -12,7 +12,7 @@ import com.izouma.awesomeadmin.model.${model.className};
 *  service接口类
 */
 public interface ${model.className}Service{
-    <!--generatedStart-->
+    /*generatedStart*/
     List<${model.className}> get${model.className}List(${model.className} record);
 
     List<${model.className}> get${model.className}ByPage(Page page, ${model.className} record);
@@ -26,6 +26,6 @@ public interface ${model.className}Service{
     boolean delete${model.className}(${model.className} record);
 
     boolean update${model.className}(${model.className} record);
-    <!--generatedEnd-->
+    /*generatedEnd*/
 }
 

+ 0 - 188
src/main/resources/templates/listTemplate1.vm

@@ -1,188 +0,0 @@
-<template>
-    <div>
-        <div class="filters-container">
-            <el-input placeholder="用户名" size="small" v-model="filter1" clearable class="filter-item"></el-input>
-            <el-select placeholder="性别" size="small" v-model="filter2" clearable class="filter-item">
-                <el-option
-                        label="女"
-                        value="item1">
-                </el-option>
-                <el-option
-                        label="男"
-                        value="item2">
-                </el-option>
-            </el-select>
-            <el-button @click="getData" type="primary" size="small" icon="el-icon-search" class="filter-item">搜索
-            </el-button>
-            <el-button @click="${esc.d}router.push('/user')" type="primary" size="small" icon="el-icon-edit"
-                       class="filter-item">添加
-            </el-button>
-            <el-dropdown trigger="click" size="medium" class="table-column-filter">
-                <span>
-                  筛选数据<i class="el-icon-arrow-down el-icon--right"></i>
-                </span>
-                <el-dropdown-menu slot="dropdown" class="table-column-filter-wrapper">
-                    <el-checkbox v-for="item in tableColumns" :key="item.value" v-model="item.show">{{item.label}}
-                    </el-checkbox>
-                </el-dropdown-menu>
-            </el-dropdown>
-        </div>
-        <el-table
-                :data="tableData"
-                :height="tableHeight"
-                row-key="id"
-                ref="table">
-            <el-table-column
-                    v-if="multipleMode"
-                    align="center"
-                    type="selection"
-                    width="50">
-            </el-table-column>
-            <el-table-column
-                    type="index"
-                    min-width="50"
-                    align="center">
-            </el-table-column>
-            #foreach($field in $model.fields)
-                #if($field.showInList)
-                    <el-table-column
-                            v-if="isColumnShow('$field.modelName')"
-                            prop="$field.modelName"
-                            label="$display.alt($field.remark,$field.modelName)"
-                            min-width="300">
-                    </el-table-column>
-                #end
-            #end
-            <el-table-column
-                    label="操作"
-                    align="center"
-                    fixed="right">
-                <template slot-scope="scope">
-                    <el-button @click="editRow(scope.row)" type="primary" size="mini" plain>编辑</el-button>
-                </template>
-            </el-table-column>
-        </el-table>
-        <div class="pagination-wrapper">
-            <div class="multiple-mode-wrapper">
-                <el-button size="small" v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
-                <el-button-group v-else>
-                    <el-button size="small" @click="operation1">批量操作1</el-button>
-                    <el-button size="small" @click="operation2">批量操作2</el-button>
-                    <el-button size="small" @click="toggleMultipleMode(false)">取消</el-button>
-                </el-button-group>
-            </div>
-            <el-pagination
-                    background
-                    @size-change="pageSizeChange"
-                    @current-change="currentPageChange"
-                    :current-page="currentPage"
-                    :page-sizes="[10, 20, 30, 40, 50]"
-                    :page-size="pageSize"
-                    layout="total, sizes, prev, pager, next, jumper"
-                    :total="totalNumber">
-            </el-pagination>
-        </div>
-    </div>
-</template>
-<script>
-    import {mapState} from 'vuex'
-
-    export default {
-        created() {
-            this.getData();
-        },
-        data() {
-            return {
-                totalNumber: 0,
-                totalPage: 10,
-                currentPage: 1,
-                pageSize: 20,
-                tableData: [],
-                filter1: '',
-                filter2: '',
-                tableColumns: [{
-                    label: '用户名',
-                    value: 'username',
-                    show: true
-                }, {
-                    label: '昵称',
-                    value: 'nickname',
-                    show: true
-                }, {
-                    label: '头像',
-                    value: 'icon',
-                    show: true
-                }, {
-                    label: '性别',
-                    value: 'sex',
-                    show: true
-                }, {
-                    label: 'openId',
-                    value: 'openId',
-                    show: true
-                }],
-                multipleMode: false
-            }
-        },
-        computed: {
-            ...mapState(['tableHeight']),
-            selection() {
-                return this.${esc.d}refs.table.selection.map(i => i.id);
-            }
-        },
-        methods: {
-            pageSizeChange(size) {
-                this.pageSize = size;
-                this.getData();
-            },
-            currentPageChange(page) {
-                this.currentPage = page;
-                this.getData();
-            },
-            getData() {
-                this.${esc.d}http.get({
-                    url: '/userInfo/page',
-                    data: {
-                        currentPage: this.currentPage,
-                        pageNumber: this.pageSize
-                    }
-                }).then(res => {
-                    if (res.success) {
-                        this.totalNumber = res.data.page.totalNumber;
-                        this.tableData = res.data.pp;
-                    }
-                })
-            },
-            isColumnShow(column) {
-                var row = this.tableColumns.find(i => i.value === column);
-                return row ? row.show : false;
-            },
-            toggleMultipleMode(multipleMode) {
-                this.multipleMode = multipleMode;
-                if (!multipleMode) {
-                    this.${esc.d}refs.table.clearSelection();
-                }
-            },
-            editRow(row) {
-                this.${esc.d}router.push({
-                    path: '/user',
-                    query: {
-                        id: row.id
-                    }
-                })
-            },
-            operation1() {
-                this.${esc.d}notify({
-                    title: '提示',
-                    message: this.selection
-                });
-            },
-            operation2() {
-                this.${esc.d}message('操作2');
-            }
-        }
-    }
-</script>
-<style lang="less" scoped>
-
-</style>