
我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。
查看文件的内容cat 文件名 例如: 查看文件(去除注释、去除空格的所有内容)cat 文件名 | grep -v "#" | grep -v "^$" 查看所有的进程ps -ef 杀死进程kill -s 9 进程对应的序列号 捕获logtail -f 编辑vi/vim 名称输入i完成后按esc输入':wq'保存并退出输入':q!'退出 新建文件夹mkdir 文件夹名称 移除rm 文件夹名称 查看当前目录pwd 复制文件至文件夹cp 文件名 文件夹名 目录重命名mv 文件名 新文件名 解压tar文件tar -xzf 文件名 解压zip文件unzip 文件名称 Linux关机命令shutdown -h now(立刻进行关机)halt(立刻进行关机)poweroff(立刻进行关机) linux重启命令shutdown -r now(现在重新启动计算机)reboot(现在重新启动计算机) shutdown -h now和shutdown -r now必须是root用户或者具有root权限的用户才能使用,而halt和reboot是Linux系统中的任何用户都可使用,不需要root权限。
设置root用户的密码 sudo passwd root 回车 设置root用户的密码(使用root账户) 安装yum sudo apt-get updatesudo apt install yum Linux系统(Ubuntu)中使用国内的源地址 源地址列表文件路径 ubuntu系统的源列表配置文件的路径是:/etc/apt/ sources.list 为了在替换前留个备份,可以执行命令做个备份: cp /etc/apt/sources.list /etc/apt/sources.list-bak 源地址列表文件的替换 不同的版本,sources.list里的url是不同的,主要是版本好不一样,例如ubuntu14.04的代号是trusty ,而ubuntu16.04是 xenial。 具体查看方法是执行命令:lsb_release -a 回车 返回的Codename就是版本代号 如图: image.png ubuntu14.04版本 将/etc/apt/ sources.list的内容替换为: deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe 替换后执行命令: sudo apt-get update ubuntu16.04版本 将/etc/apt/ sources.list的内容替换为: deb http://mirrors.aliyun.com/ubuntu/ xenial main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe 替换后执行命令: sudo apt-get update 出现apt-get: Package has no installation candidate问题 apt-get update apt-get upgrade apt-get install <packagename> 添加第三方地址: sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" sudo apt-get update
poi Maven <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.14</version> </dependency> 基础代码 package com.peas.mdp.module.util; import com.peas.mdp.dto.Teacher; import org.apache.poi.ss.usermodel.*; import java.io.InputStream; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; public class ExcelUtil { public static List<?> getBankListByExcel(InputStream in) throws Exception { List<Teacher> list = new ArrayList<>(); //创建Excel工作薄 Workbook work = getWorkbook(in); if (null == work) { throw new Exception("创建Excel工作薄为空!"); } Sheet sheet = null; Row row = null; Cell cell = null; //遍历Excel中所有的sheet for (int i = 0; i < work.getNumberOfSheets(); i++) { sheet = work.getSheetAt(i); if (sheet == null) { continue; } //遍历当前sheet中的所有行 for (int j =1; j <= sheet.getLastRowNum(); j++) { row = sheet.getRow(j); if (row == null ) { continue; } Teacher teacher = new Teacher(); //把每个单元格的值付给对象的对应属性 if (row.getCell(0)!=null){ teacher.setAccount(String.valueOf(getCellValue(row.getCell(0)))); } if (row.getCell(1)!=null){ teacher.setName(String.valueOf(getCellValue(row.getCell(1)))); } if (row.getCell(2)!=null){ teacher.setSex(Integer.valueOf((String) getCellValue(row.getCell(2)))); } if (row.getCell(3)!=null){ teacher.setAge(Integer.valueOf((String) getCellValue(row.getCell(3)))); } if (row.getCell(4)!=null){ teacher.setEducation(String.valueOf(getCellValue(row.getCell(4)))); } if (row.getCell(5)!=null){ teacher.setJobTitle(String.valueOf(getCellValue(row.getCell(5)))); } if (row.getCell(6)!=null){ teacher.setPosition(String.valueOf(getCellValue(row.getCell(6)))); } if (row.getCell(7) != null) { teacher.setRole(String.valueOf(getCellValue(row.getCell(7)))); } if (row.getCell(8) != null) { teacher.setPhone(String.valueOf(getCellValue(row.getCell(8)))); } if (row.getCell(9) != null) { teacher.setEmail(String.valueOf(getCellValue(row.getCell(9)))); } if (row.getCell(10) != null) { teacher.setKeyWords(String.valueOf(getCellValue(row.getCell(10)))); } if (row.getCell(11) != null) { teacher.setIntroduction(String.valueOf(getCellValue(row.getCell(11)))); } if (row.getCell(12) != null) { teacher.setIdCard(String.valueOf(getCellValue(row.getCell(12)))); } if (row.getCell(13) != null) { teacher.setType(Integer.valueOf((String)getCellValue(row.getCell(13)))); } //遍历所有的列(把每一行的内容存放到对象中) list.add(teacher); } } return list; } /** * * @param inStr * @return * @throws Exception */ public static Workbook getWorkbook(InputStream inStr) throws Exception { Workbook wb = null; wb = WorkbookFactory.create(inStr); return wb; } /** * 描述:对表格中数值进行格式化 * * @param cell * @return */ public static Object getCellValue(Cell cell) { Object value = null; DecimalFormat df = new DecimalFormat("0"); //格式化number String字符 SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd"); //日期格式化 DecimalFormat df2 = new DecimalFormat("0"); //格式化数字 switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: value = cell.getRichStringCellValue().getString(); break; case Cell.CELL_TYPE_NUMERIC: if ("General".equals(cell.getCellStyle().getDataFormatString())) { value = df.format(cell.getNumericCellValue()); } else if ("m/d/yy".equals(cell.getCellStyle().getDataFormatString())) { value = sdf.format(cell.getDateCellValue()); } else { value = df2.format(cell.getNumericCellValue()); } break; case Cell.CELL_TYPE_BOOLEAN: value = cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_BLANK: value = ""; break; default: break; } return value; } } Control @ApiOperation("excel导入") @GET @Path("excelFile") public Map<String, String> readExcel(@QueryParam("path") File path) throws Exception { HashMap<String, String> map = new HashMap<>(); //读取excel中的内容 InputStream inputStream = new FileInputStream(path); List<Teacher> teachers = (List<Teacher>) ExcelUtil.getBankListByExcel(inputStream); for (Teacher teacher : teachers) { teacherService.saveOrUpdate(teacher); } return map; } /** * 读取excel更新数据 * * @param upfile * @param * @param * @throws Exception */ /* @RequestMapping(value = "/readExcel") @Transactional public Map<String, String> readExcel(MultipartFile upfile) throws Exception { HashMap<String, String> map = new HashMap<>(); InputStream in = upfile.getInputStream(); //读取excel中的内容 List<LineDownOrder> lineDownOrders = ExcelUtils.getBankListByExcel(in); String s = orderService.updateByExcel(lineDownOrders); map.put("status", s); return map; } */
limit(可以接受一个参数或者两个参数) 第一个参数 指定第一个返回记录行的偏移量(初始偏移量是0不是1) 第二个参数 指定返回记录行的最大数目 例: //检索记录行6-15 select * from table limit 5,10 为了检索从某一个偏移量到记录集的结束所有的记录行,可以制定最后一个参数为-1 //检索从96条记录到最后一条记录 select * from table limit 95,-1 如果只给定一个参数,表示返回最大的记录行个数,即(limit n == limit 0,n) limit分页查询的性能分析 基本分页方式 select ··· from ··· where ··· order by ··· limit ··· 在中小型数据量够用,数据量超级大时建议使用子查询 select * from articles where category_id = 123 order by id limit 1000000,10 修改为 select * from articles where id>=(select id from articles where category_id = 123 order by id limit 1000000,1) limit 10 优化思想:避免数据量大时扫描过多的记录 image.png image.png