• kitty项目


    项目地址

    https://gitee.com/liuge1988/kitty

    一些收获

    1baseEntity

    其他实体继承

    2、同样的crud service 也可以写个base 然后继承

    public interface CurdService<T> {
       
       int save(T record);
    
       int delete(T record);
    
       int delete(List<T> records);
       
    
       T findById(Long id);
       
       PageResult findPage(PageRequest pageRequest);
    }

    这里用的是接口,实际上,现在主张去掉inteface ,service直接class

    3Mysql 备份还原

    MySQL备份还原工具类

    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.louis.kitty.backup.constants.BackupConstants;
    import com.louis.kitty.backup.datasource.BackupDataSourceProperties;
    import com.louis.kitty.backup.service.MysqlBackupService;
    import com.louis.kitty.backup.util.FileUtils;
    import com.louis.kitty.backup.util.HttpResult;
    
    /**
     * 系统数据备份还原
     * 采用MYSQL备份还原命令
     * @author Louis
     * @date Sep 20, 2018
     */
    @RestController
    @RequestMapping("/backup")
    public class MySqlBackupController {
    
        @Autowired
        MysqlBackupService mysqlBackupService;
        @Autowired
        BackupDataSourceProperties properties;
    
        @GetMapping("/backup")
        public HttpResult backup() {
            String host = properties.getHost();
            String userName = properties.getUserName();
            String password = properties.getPassword();
            String database = properties.getDatabase();
            String backupFodlerName = BackupConstants.DEFAULT_BACKUP_NAME+ "_" + (new SimpleDateFormat(BackupConstants.DATE_FORMAT)).format(new Date());
            String backupFolderPath = BackupConstants.BACKUP_FOLDER + backupFodlerName + File.separator;
            String fileName = BackupConstants.BACKUP_FILE_NAME;
            try {
                mysqlBackupService.backup(host, userName, password, backupFolderPath, fileName, database);
            } catch (Exception e) {
                return HttpResult.error(500, e.getMessage());
            }
            return HttpResult.ok();
        }
    
        @GetMapping("/restore")
        public HttpResult restore(@RequestParam String name) {
            String host = properties.getHost();
            String userName = properties.getUserName();
            String password = properties.getPassword();
            String database = properties.getDatabase();
            String restoreFilePath = BackupConstants.RESTORE_FOLDER + name;
            try {
                mysqlBackupService.restore(restoreFilePath, host, userName, password, database);
            } catch (Exception e) {
                return HttpResult.error(500, e.getMessage());
            }
            return HttpResult.ok();
        }
        
        @GetMapping("/findRecords")
        public HttpResult findBackupRecords() {
            List<Map<String, Object>> backupRecords = new ArrayList<>();
            File restoreFolderFile = new File(BackupConstants.RESTORE_FOLDER);
            if(restoreFolderFile.exists()) {
                for(File file:restoreFolderFile.listFiles()) {
                    Map<String, Object> bean = new HashMap<>();
                    bean.put("name", file.getName());
                    bean.put("title", file.getName());
                    if(BackupConstants.DEFAULT_BACKUP_NAME.equals(file.getName())) {
                        bean.put("title", "系统默认备份");
                    }
                    backupRecords.add(bean);
                }
            }
            return HttpResult.ok(backupRecords);
        }
        
        @GetMapping("/delete")
        public HttpResult deleteBackupRecord(@RequestParam String name) {
            if(BackupConstants.DEFAULT_BACKUP_NAME.equals(name)) {
                return HttpResult.error("系统默认备份无法删除!");
            }
            String restoreFilePath = BackupConstants.RESTORE_FOLDER + name;
            try {
                FileUtils.deleteFile(new File(restoreFilePath));
            } catch (Exception e) {
                return HttpResult.error(500, e.getMessage());
            }
            return HttpResult.ok();
        }
    
    }
    View Code

    4、springboot 配置druid mybaits 以及sql监控

    5、跨域的配置

    /**
     * 跨域配置
     * @author Louis
     * @date Oct 29, 2018
     */
    @Configuration
    public class CorsConfig implements WebMvcConfigurer {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**") // 允许跨域访问的路径
            .allowedOrigins("*")   // 允许跨域访问的源
            .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") // 允许请求方法
            .maxAge(168000)    // 预检间隔时间
            .allowedHeaders("*")  // 允许头部设置
            .allowCredentials(true);   // 是否发送cookie
        }
    }
  • 相关阅读:
    多台计算机之间数据同步——1.[转]网线制作图解教程
    离心泵的使用注意事项泄露或未排气造成扬程不够
    家庭上网用路由器和ADSL的连接
    专业FLV地址解析
    [求助]带程序访问控制的防火墙 eTrust Personal Firewall 和卡巴斯基2009引起冲突造成系统频繁死机
    DV录像带导出一定要用1394
    Cursor:url()的使用
    理解并解决JavaScript内存泄漏
    CodeIgniter的HMVC
    关于在IE下JavaScript的 Stack overflow at line 错误可能的原因
  • 原文地址:https://www.cnblogs.com/lyon91/p/9890764.html
Copyright © 2020-2023  润新知