生成demo调整。基本运行验证
Showing
9 changed files
with
156 additions
and
17 deletions
| ... | @@ -26,11 +26,6 @@ | ... | @@ -26,11 +26,6 @@ |
| 26 | <artifactId>cronos-generator</artifactId> | 26 | <artifactId>cronos-generator</artifactId> |
| 27 | <version>1.1.0</version> | 27 | <version>1.1.0</version> |
| 28 | </dependency> | 28 | </dependency> |
| 29 | <dependency> | ||
| 30 | <groupId>com.topdraw</groupId> | ||
| 31 | <artifactId>cronos-logging</artifactId> | ||
| 32 | <version>1.1.0</version> | ||
| 33 | </dependency> | ||
| 34 | 29 | ||
| 35 | <!-- Spring boot 热部署 : 此热部署会遇到 java.lang.ClassCastException 异常 --> | 30 | <!-- Spring boot 热部署 : 此热部署会遇到 java.lang.ClassCastException 异常 --> |
| 36 | <!-- optional=true,依赖不会传递--> | 31 | <!-- optional=true,依赖不会传递--> | ... | ... |
| 1 | package com.topdraw.modules.config; | ||
| 2 | |||
| 3 | import org.springframework.context.annotation.Bean; | ||
| 4 | import org.springframework.context.annotation.Configuration; | ||
| 5 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
| 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| 9 | import org.springframework.security.config.core.GrantedAuthorityDefaults; | ||
| 10 | import org.springframework.security.config.http.SessionCreationPolicy; | ||
| 11 | |||
| 12 | @Configuration | ||
| 13 | @EnableWebSecurity | ||
| 14 | @EnableGlobalMethodSecurity(prePostEnabled = true) | ||
| 15 | public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 16 | |||
| 17 | |||
| 18 | @Bean | ||
| 19 | GrantedAuthorityDefaults grantedAuthorityDefaults() { | ||
| 20 | // Remove the ROLE_ prefix | ||
| 21 | return new GrantedAuthorityDefaults(""); | ||
| 22 | } | ||
| 23 | |||
| 24 | @Override | ||
| 25 | protected void configure(HttpSecurity httpSecurity) throws Exception { | ||
| 26 | httpSecurity | ||
| 27 | // 禁用 CSRF | ||
| 28 | .csrf().disable() | ||
| 29 | // 授权异常 | ||
| 30 | // .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() | ||
| 31 | // 不创建会话 | ||
| 32 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() | ||
| 33 | // 过滤请求 | ||
| 34 | .authorizeRequests() | ||
| 35 | .anyRequest().permitAll(); | ||
| 36 | } | ||
| 37 | } |
src/main/resources/banner.txt
0 → 100644
| 1 | # If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger | ||
| 2 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator | ||
| 3 | log4jdbc.auto.load.popular.drivers=false | ||
| 4 | log4jdbc.drivers=com.mysql.cj.jdbc.Driver | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/main/resources/logback.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <configuration scan="true" scanPeriod="60 seconds" debug="false"> | ||
| 3 | |||
| 4 | <contextName>CronosDemo</contextName> | ||
| 5 | <!--定义参数,后面可以通过${app.name}使用--> | ||
| 6 | <property name="app.name" value="cronos-demo"/> | ||
| 7 | <property name="log.path" value="./logs"/> | ||
| 8 | <property name="log.pattern" value="%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n"/> | ||
| 9 | |||
| 10 | <!--输出到控制台--> | ||
| 11 | <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
| 12 | <!-- encoder 默认配置为PatternLayoutEncoder --> | ||
| 13 | <!--定义控制台输出格式--> | ||
| 14 | <encoder> | ||
| 15 | <pattern>%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg %n</pattern> | ||
| 16 | <charset>utf-8</charset> | ||
| 17 | </encoder> | ||
| 18 | </appender> | ||
| 19 | |||
| 20 | <!--获取比info级别高(包括info级别)但除error级别的日志--> | ||
| 21 | <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 22 | <filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
| 23 | <level>ERROR</level> | ||
| 24 | <onMatch>DENY</onMatch> | ||
| 25 | <onMismatch>ACCEPT</onMismatch> | ||
| 26 | </filter> | ||
| 27 | <encoder> | ||
| 28 | <pattern>${log.pattern}</pattern> | ||
| 29 | </encoder> | ||
| 30 | <!--滚动策略--> | ||
| 31 | <file>${log.path}/${app.name}-info.log</file> | ||
| 32 | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 33 | <!--路径--> | ||
| 34 | <fileNamePattern>${log.path}/info/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern> | ||
| 35 | <maxHistory>30</maxHistory> | ||
| 36 | <totalSizeCap>10GB</totalSizeCap> | ||
| 37 | </rollingPolicy> | ||
| 38 | </appender> | ||
| 39 | |||
| 40 | <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 41 | <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
| 42 | <level>ERROR</level> | ||
| 43 | </filter> | ||
| 44 | <encoder> | ||
| 45 | <pattern>${log.pattern}</pattern> | ||
| 46 | </encoder> | ||
| 47 | <!--滚动策略--> | ||
| 48 | <file>${log.path}/${app.name}-error.log</file> | ||
| 49 | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 50 | <!--路径--> | ||
| 51 | <fileNamePattern>${log.path}/error/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern> | ||
| 52 | <maxHistory>30</maxHistory> | ||
| 53 | <totalSizeCap>10GB</totalSizeCap> | ||
| 54 | </rollingPolicy> | ||
| 55 | </appender> | ||
| 56 | |||
| 57 | |||
| 58 | <!--普通日志输出到控制台--> | ||
| 59 | <root level="info"> | ||
| 60 | <appender-ref ref="console" /> | ||
| 61 | <appender-ref ref="info" /> | ||
| 62 | <appender-ref ref="error" /> | ||
| 63 | </root> | ||
| 64 | |||
| 65 | |||
| 66 | <!--监控sql日志输出 --> | ||
| 67 | <logger name="jdbc.sqlonly" level="INFO" additivity="false"> | ||
| 68 | <appender-ref ref="console" /> | ||
| 69 | <appender-ref ref="info" /> | ||
| 70 | </logger> | ||
| 71 | |||
| 72 | <logger name="jdbc.resultset" level="ERROR" additivity="false"> | ||
| 73 | <appender-ref ref="console" /> | ||
| 74 | <appender-ref ref="info" /> | ||
| 75 | </logger> | ||
| 76 | |||
| 77 | <!-- 如想看到表格数据,将OFF改为INFO --> | ||
| 78 | <logger name="jdbc.resultsettable" level="OFF" additivity="false"> | ||
| 79 | <appender-ref ref="console" /> | ||
| 80 | </logger> | ||
| 81 | |||
| 82 | <logger name="jdbc.connection" level="OFF" additivity="false"> | ||
| 83 | <appender-ref ref="console" /> | ||
| 84 | <appender-ref ref="info" /> | ||
| 85 | </logger> | ||
| 86 | |||
| 87 | <logger name="jdbc.sqltiming" level="OFF" additivity="false"> | ||
| 88 | <appender-ref ref="console" /> | ||
| 89 | <appender-ref ref="info" /> | ||
| 90 | </logger> | ||
| 91 | |||
| 92 | <logger name="jdbc.audit" level="OFF" additivity="false"> | ||
| 93 | <appender-ref ref="console" /> | ||
| 94 | <appender-ref ref="info" /> | ||
| 95 | </logger> | ||
| 96 | </configuration> |
| 1 | package ${package}.rest; | 1 | package ${package}.rest; |
| 2 | 2 | ||
| 3 | import com.topdraw.aop.log.Log; | ||
| 4 | import ${package}.domain.${className}; | 3 | import ${package}.domain.${className}; |
| 5 | import ${package}.service.${className}Service; | 4 | import ${package}.service.${className}Service; |
| 6 | import ${package}.service.dto.${className}QueryCriteria; | 5 | import ${package}.service.dto.${className}QueryCriteria; |
| ... | @@ -27,35 +26,30 @@ public class ${className}Controller { | ... | @@ -27,35 +26,30 @@ public class ${className}Controller { |
| 27 | private ${className}Service ${changeClassName}Service; | 26 | private ${className}Service ${changeClassName}Service; |
| 28 | 27 | ||
| 29 | @GetMapping(value = "/download") | 28 | @GetMapping(value = "/download") |
| 30 | @Log("导出数据") | ||
| 31 | @ApiOperation("导出数据") | 29 | @ApiOperation("导出数据") |
| 32 | public void download(HttpServletResponse response, ${className}QueryCriteria criteria) throws IOException { | 30 | public void download(HttpServletResponse response, ${className}QueryCriteria criteria) throws IOException { |
| 33 | ${changeClassName}Service.download(${changeClassName}Service.queryAll(criteria), response); | 31 | ${changeClassName}Service.download(${changeClassName}Service.queryAll(criteria), response); |
| 34 | } | 32 | } |
| 35 | 33 | ||
| 36 | @GetMapping | 34 | @GetMapping |
| 37 | @Log("查询${className}") | ||
| 38 | @ApiOperation("查询${className}") | 35 | @ApiOperation("查询${className}") |
| 39 | public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable) { | 36 | public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable) { |
| 40 | return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK); | 37 | return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK); |
| 41 | } | 38 | } |
| 42 | 39 | ||
| 43 | @GetMapping(value = "/all") | 40 | @GetMapping(value = "/all") |
| 44 | @Log("查询所有${className}") | ||
| 45 | @ApiOperation("查询所有${className}") | 41 | @ApiOperation("查询所有${className}") |
| 46 | public ResponseEntity get${className}s(${className}QueryCriteria criteria) { | 42 | public ResponseEntity get${className}s(${className}QueryCriteria criteria) { |
| 47 | return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria),HttpStatus.OK); | 43 | return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria),HttpStatus.OK); |
| 48 | } | 44 | } |
| 49 | 45 | ||
| 50 | @PostMapping | 46 | @PostMapping |
| 51 | @Log("新增${className}") | ||
| 52 | @ApiOperation("新增${className}") | 47 | @ApiOperation("新增${className}") |
| 53 | public ResponseEntity create(@Validated @RequestBody ${className} resources) { | 48 | public ResponseEntity create(@Validated @RequestBody ${className} resources) { |
| 54 | return new ResponseEntity<>(${changeClassName}Service.create(resources),HttpStatus.CREATED); | 49 | return new ResponseEntity<>(${changeClassName}Service.create(resources),HttpStatus.CREATED); |
| 55 | } | 50 | } |
| 56 | 51 | ||
| 57 | @PutMapping | 52 | @PutMapping |
| 58 | @Log("修改${className}") | ||
| 59 | @ApiOperation("修改${className}") | 53 | @ApiOperation("修改${className}") |
| 60 | public ResponseEntity update(@Validated @RequestBody ${className} resources) { | 54 | public ResponseEntity update(@Validated @RequestBody ${className} resources) { |
| 61 | ${changeClassName}Service.update(resources); | 55 | ${changeClassName}Service.update(resources); |
| ... | @@ -63,7 +57,6 @@ public class ${className}Controller { | ... | @@ -63,7 +57,6 @@ public class ${className}Controller { |
| 63 | } | 57 | } |
| 64 | 58 | ||
| 65 | @DeleteMapping(value = "/{${pkChangeColName}}") | 59 | @DeleteMapping(value = "/{${pkChangeColName}}") |
| 66 | @Log("删除${className}") | ||
| 67 | @ApiOperation("删除${className}") | 60 | @ApiOperation("删除${className}") |
| 68 | public ResponseEntity delete(@PathVariable ${pkColumnType} ${pkChangeColName}) { | 61 | public ResponseEntity delete(@PathVariable ${pkColumnType} ${pkChangeColName}) { |
| 69 | ${changeClassName}Service.delete(${pkChangeColName}); | 62 | ${changeClassName}Service.delete(${pkChangeColName}); |
| ... | @@ -74,7 +67,6 @@ public class ${className}Controller { | ... | @@ -74,7 +67,6 @@ public class ${className}Controller { |
| 74 | <#list columns as column> | 67 | <#list columns as column> |
| 75 | <#if column.columnName == 'code'> | 68 | <#if column.columnName == 'code'> |
| 76 | @GetMapping(value = "/getByCode/{code}") | 69 | @GetMapping(value = "/getByCode/{code}") |
| 77 | @Log("根据标识查询") | ||
| 78 | @ApiOperation(value = "根据标识查询") | 70 | @ApiOperation(value = "根据标识查询") |
| 79 | public ResponseEntity getByCode(@PathVariable String code) { | 71 | public ResponseEntity getByCode(@PathVariable String code) { |
| 80 | return new ResponseEntity(${changeClassName}Service.getByCode(code),HttpStatus.OK); | 72 | return new ResponseEntity(${changeClassName}Service.getByCode(code),HttpStatus.OK); | ... | ... |
| ... | @@ -13,6 +13,7 @@ import org.springframework.test.annotation.Rollback; | ... | @@ -13,6 +13,7 @@ import org.springframework.test.annotation.Rollback; |
| 13 | import org.springframework.test.context.junit4.SpringRunner; | 13 | import org.springframework.test.context.junit4.SpringRunner; |
| 14 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 15 | 15 | ||
| 16 | import java.util.Arrays; | ||
| 16 | import java.util.List; | 17 | import java.util.List; |
| 17 | import java.util.Map; | 18 | import java.util.Map; |
| 18 | 19 | ||
| ... | @@ -33,8 +34,11 @@ public class GeneratorCode { | ... | @@ -33,8 +34,11 @@ public class GeneratorCode { |
| 33 | @Rollback(value = false) | 34 | @Rollback(value = false) |
| 34 | @Transactional(rollbackFor = Exception.class) | 35 | @Transactional(rollbackFor = Exception.class) |
| 35 | public void generator() { | 36 | public void generator() { |
| 37 | // 表名称,支持多表 | ||
| 38 | var tableNames = Arrays.asList("dict", "dict_detail"); | ||
| 39 | tableNames.forEach(tableName -> { | ||
| 36 | // 生成的表名称 | 40 | // 生成的表名称 |
| 37 | var tableName = "x_media"; | 41 | // var tableName = "x_media"; |
| 38 | // 拿参数 | 42 | // 拿参数 |
| 39 | var columnsMap = (Map<String, Object>) generatorService.getColumns(tableName); | 43 | var columnsMap = (Map<String, Object>) generatorService.getColumns(tableName); |
| 40 | var columnInfos = (List<ColumnInfo>) columnsMap.get("content"); | 44 | var columnInfos = (List<ColumnInfo>) columnsMap.get("content"); |
| ... | @@ -43,8 +47,8 @@ public class GeneratorCode { | ... | @@ -43,8 +47,8 @@ public class GeneratorCode { |
| 43 | // 未设置id无法生成 | 47 | // 未设置id无法生成 |
| 44 | .setId(1L) | 48 | .setId(1L) |
| 45 | // 根据需求更改包路径 | 49 | // 根据需求更改包路径 |
| 46 | .setPack("com.topdraw.modules.xxx") | 50 | .setPack("com.topdraw.modules.content") |
| 47 | // 前端路径。 | 51 | // 前端路径。不生成前端可置空 |
| 48 | .setPath("") | 52 | .setPath("") |
| 49 | // 作者 | 53 | // 作者 |
| 50 | .setAuthor("why") | 54 | .setAuthor("why") |
| ... | @@ -55,5 +59,6 @@ public class GeneratorCode { | ... | @@ -55,5 +59,6 @@ public class GeneratorCode { |
| 55 | 59 | ||
| 56 | // 生成代码 | 60 | // 生成代码 |
| 57 | generatorService.generator(columnInfos, genConfig, tableName); | 61 | generatorService.generator(columnInfos, genConfig, tableName); |
| 62 | }); | ||
| 58 | } | 63 | } |
| 59 | } | 64 | } | ... | ... |
-
Please register or sign in to post a comment