后端

1. Spring自带的MD5加密工具类

  1. import org.springframework.util.DigestUtils;
  2.  
  3. String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());

2. 数据库的字段名不要含有 is

比如数据库有个字段为is_valid,那么到代码里这个变量为isValid。如果恰好这个变量是Boolean类型的,那么如果返回数据到前端,那么json串为{"valid":true},可以看见is被无形去掉了。

看自动生成的get方法,没有get前缀,都是因为Boolean类型的get方法都是以is开头的,而这样会覆盖掉你名字里的is前缀,所以如果你的变量为Boolean类型命名要避免以is开头。

3. invalid comparison: org.springframework.web.bind.annotation.RequestMethod and java.lang.String

别人留下的坑:

mybatis里面的sql语句,org.springframework.web.bind.annotation.RequestMethod是个枚举类

  1. <if test="requestMethod!=null and requestMethod!='' ">
  2. REQUEST_METHOD=#{requestMethod , jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler},
  3. </if>

这里的判断:requestMethod != '' 导致报错,因为你一个枚举类怎么能跟字符串作比较呢?

4. 修改html页面,IDEA不自动部署的问题

首先禁用掉当前模板引擎的缓存,比如:spring.thymeleaf.cache=false,页面修改之后按Ctrl+F9重新Build Project

5. org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter 已废弃

自5.0版本开始,MVC相关配置可直接实现 org.springframework.web.servlet.config.annotation.WebMvcConfigurer

  1. import com.example.demo.interceptor.CommonInterceptor;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  5. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  6.  
  7. @Configuration
  8. public class MyWebConfig implements WebMvcConfigurer {
  9.  
  10. @Autowired
  11. private CommonInterceptor commonInterceptor;
  12.  
  13. /**
  14. * 配置拦截器
  15. * @param registry
  16. */
  17. @Override
  18. public void addInterceptors(InterceptorRegistry registry) {
  19. registry.addInterceptor(commonInterceptor).addPathPatterns("/**").excludePathPatterns("/login");
  20. }
  21. }

6. 查看SpringBoot默认的配置类

在application.properties里面配置debug=true,在启动的时候就会打印开启的默认配置类。

7. maven打包SpringBoot项目后,java -jar命令报错,找不到主清单属性

  1. <plugin>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-maven-plugin</artifactId>
  4. <version>${spring.boot.version}</version>
  5. <!--解决打包后,执行java -jar 命令,找不到主清单属性-->
  6. <executions>
  7. <execution>
  8. <phase>package</phase>
  9. <goals>
  10. <goal>repackage</goal>
  11. </goals>
  12. </execution>
  13. </executions>
  14. </plugin>

8. Java解析HTML/XML字符串

  1. <dependency>
  2. <groupId>dom4j</groupId>
  3. <artifactId>dom4j</artifactId>
  4. <version>1.6.1</version>
  5. </dependency>

代码

  1. import org.dom4j.Document;
  2. import org.dom4j.DocumentException;
  3. import org.dom4j.DocumentHelper;
  4. import org.dom4j.Element;
  5.  
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class Test {
  10.  
  11. public static void main(String[] args) throws DocumentException {
  12. parse(create());
  13. }
  14.  
  15. private static String create(){
  16. Document document = DocumentHelper.createDocument();
  17. Element rootElement = document.addElement("response");
  18. Map<String,String> postMap = new HashMap<>();
  19. postMap.put("code", "200");
  20. postMap.put("msg", "操作成功!");
  21. for (String key : postMap.keySet()) {
  22. Element element = rootElement.addElement(key);
  23. element.setText(postMap.get(key));
  24. }
  25. String xml = document.getRootElement().asXML();
  26. System.out.println("Create Result:" + xml);
  27. return xml;
  28. }
  29.  
  30. private static void parse(String data) throws DocumentException {
  31. Document document = DocumentHelper.parseText(data);
  32. Element rootElement = document.getRootElement();
  33. System.out.println("==============Parse Result ==============");
  34. System.out.println(rootElement.element("code").getText());
  35. System.out.println(rootElement.element("msg").getText());
  36. }
  37. }

输出

9. 后端传递Long,前端精度丢失解决

  1. import com.fasterxml.jackson.annotation.JsonFormat;
  2. import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  3. import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
  4.  
  5. public class User {
  6.  
  7. /**
  8. * 方法一
  9. */
  10. @JsonFormat(shape = JsonFormat.Shape.STRING)
  11. private Long userId;
  12.  
  13. /**
  14. * 方法二
  15. */
  16. @JsonSerialize(using = ToStringSerializer.class)
  17. private Long orderId;
  18.  
  19. }

10. Integer对象转Comparable对象(来自JDK源码)

  1. Integer x = 10;
  2. Comparable<Integer> key = (Comparable<Integer>) x;
  3. System.out.println(x.compareTo(1));

11. Optional的使用

  1. List<String> list = null;
  2. // 无论list是否为空,都会执行orElse
  3. List<String> strings = Optional.ofNullable(list).orElse(new ArrayList<>());
  4. // 只有list为空,才会执行orElseGet
  5. List<String> strings2 = Optional.ofNullable(list).orElseGet(ArrayList::new);

12. 解析Excel

引入依赖

  1. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
  2. <dependency>
  3. <groupId>org.apache.poi</groupId>
  4. <artifactId>poi</artifactId>
  5. <version>4.1.2</version>
  6. </dependency>
  7. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
  8. <dependency>
  9. <groupId>org.apache.poi</groupId>
  10. <artifactId>poi-ooxml</artifactId>
  11. <version>4.1.2</version>
  12. </dependency>

代码

  1. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  2. import org.apache.poi.ss.usermodel.Cell;
  3. import org.apache.poi.ss.usermodel.Row;
  4. import org.apache.poi.ss.usermodel.Sheet;
  5. import org.apache.poi.ss.usermodel.Workbook;
  6. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  7.  
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.IOException;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. public class Main {
  15.  
  16. public static void main(String[] args) throws Exception {
  17. File file = new File("excel.xlsx");
  18. readExcel(file);
  19. }
  20.  
  21. private static void readExcel(File file) throws IOException {
  22. FileInputStream in = new FileInputStream(file);
  23. List<String> codes = new ArrayList<>();
  24. Workbook wb = null;
  25. // 解析后缀
  26. String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
  27. // 根据后缀判断文件类型
  28. if ("xls".equals(prefix)){
  29. wb = new HSSFWorkbook(in);
  30. }else if ("xlsx".equals(prefix)){
  31. wb = new XSSFWorkbook(in);
  32. }
  33. if (wb != null){
  34. // sheet数量
  35. int numberOfSheets = wb.getNumberOfSheets();
  36. // 遍历sheet
  37. for (int i = 0; i < numberOfSheets; i++){
  38. Sheet sheet = wb.getSheetAt(i);
  39. // 遍历标题行(第0行)
  40. Row title = sheet.getRow(0);
  41. System.out.println("===============");
  42. for (int c = 0; c < title.getLastCellNum(); c++){
  43. Cell cell = title.getCell(c);
  44. System.out.print(selectCellType(cell) + "\t");
  45. }
  46. System.out.println("\n===============");
  47. // 遍历数据行(第1行开始)
  48. for (int j = 1; j <= sheet.getLastRowNum(); j++){
  49. Row row = sheet.getRow(j);
  50.  
  51. for (int c = 0; c < row.getLastCellNum(); c++){
  52. Cell cell = row.getCell(c);
  53. System.out.print(selectCellType(cell) + "\t");
  54. }
  55. System.out.println();
  56. }
  57. }
  58. }
  59. }
  60.  
  61. private static Object selectCellType(Cell cell){
  62. switch (cell.getCellType()){
  63. case BLANK:
  64. return "";
  65. case STRING:
  66. return cell.getStringCellValue();
  67. case BOOLEAN:
  68. return cell.getBooleanCellValue();
  69. case NUMERIC:
  70. return cell.getNumericCellValue();
  71. case FORMULA:
  72. return cell.getCellFormula();
  73. default:
  74. return "";
  75. }
  76. }
  77.  
  78. }

测试:

13. 按照逗号分隔的 String与List 互转

依赖

  1. <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
  2. <dependency>
  3. <groupId>org.apache.commons</groupId>
  4. <artifactId>commons-lang3</artifactId>
  5. <version>3.10</version>
  6. </dependency>

代码

  1. import org.apache.commons.lang3.StringUtils;
  1. String text = "A,B,C,D,E";
  2. // --------------String转List
  3. List<String> stringList = Arrays.asList(text.split(","));
  4. // --------------List转String
  5. String join = StringUtils.join(stringList, ",");
  6. System.out.println(stringList + "\t\t" + join);

测试:

前端

1. string转number

  1. <script>
  2. $(document).ready(function(){
  3. var p = +$('p').text();
  4. $('div').text(p+1);
  5. });
  6. </script>
  7. </head>
  8. <body>
  9. <div></div>
  10. <p>1</p>
  11. </body>
  12. </html>

输出2而不是11

2. JQuery警告,低效的选择器用法

比如:

  1. $('#resultData :checked');

会警告

Inefficient jQuery usage less... (Ctrl+F1)
Checks that jQuery selectors are used in an efficient way. It suggests to split descendant selectors which are prefaced with ID selector and warns about duplicated selectors which could be cached

应改成:

  1. $('#resultData').find(':checked');

3. Comparison $.trim($(t[9]).val()) == "" may cause unexpected type coercion less...

比如:判断表单内容去除空格后是否为空

  1. $.trim($(t[0]).val()) == ""

会警告

应改为:

  1. $.trim($(t[0]).val()) === ""

4. new Boolean(value) 和 Boolean(value)的区别

前者是作为构造函数构造一个Boolean实例,得到的是一个对象;后者是作为普通函数调用,得到的是函数返回值false/true

5. Ajax请求,传递的数组参数名称多了一个[]

利用JQuery的$.param(params,true)来解决

  1. var myObject = {
  2. a: {
  3. one: 1,
  4. two: 2,
  5. three: 3
  6. },
  7. b: [1,2,3]
  8. };
  9. var recursiveEncoded = $.param(myObject);
  10. var recursiveDecoded = decodeURIComponent($.param(myObject));
  11.  
  12. console.log(recursiveEncoded);
  13. console.log(recursiveDecoded);
  14.  
  15. var shallowEncoded = $.param(myObject, true);
  16. var shallowDecoded = decodeURIComponent(shallowEncoded);
  17.  
  18. console.log(shallowEncoded);
  19. console.log(shallowDecoded);

6. Input 文件域重复上传,不触发change事件

  1. <input type="file" id="upload">
  2.  
  3. $("#upload").change(function(){
  4. // 上传或者其它操作
  5. // ....
  6. // 最后将value置为空
  7. $(this).val('');
  8. });

也可以用一个新的input替代当前的input。

后端&前端零碎知识点和注意问题的更多相关文章

  1. web开发前端面试知识点目录整理

    web开发前端面试知识点目录整理 基本功考察 关于Html 1. html语义化标签的理解; 结构化的理解; 能否写出简洁的html结构; SEO优化 2. h5中新增的属性; 如自定义属性data, ...

  2. 中级前端必备知识点(2.5w+月薪)进阶 (分享知乎 : 平酱的填坑札记 关注专栏 用户:安大虎)

    前端已经不再是5年前刚开始火爆时候的那种html+css+js+jquery的趋势了,现在需要你完全了解前端开发的同时,还要具备将上线.持续化.闭环.自动化.语义化.封装......等概念熟练运用到工 ...

  3. webdriver零碎知识点

    #零碎知识点,用于记录平时遇到的比较杂的知识点 driver.current_url 获取当前url phantomjs 实现无浏览器界面自动化测试(driver = webdriver.Phanto ...

  4. 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事

      一.条件分支语句 条件分支语句,也叫作条件判断语句,就是根据某种条件执行某些语句,不执行某些语句. JS中有三种语法是可以表示条件分支的 1.1 if……else…… 条件分支的主力语法,这个主力 ...

  5. Android零碎知识点 1

    Android零碎知识点 1   Android在2.3版本上开始支持KeyEvent.KEYCODE_PAGE_DOWN以及KeyEvent.KEYCODE_PAGE_UP的操作.   Androi ...

  6. 程序迭代时测试操作的要点(后端&前端)

    今晚直播课内容简介,视频可点击链接免费听 <程序迭代时测试操作的要点(后端&前端)> ===== 1:迭代时后台涉及的操作有哪些?如何进行 a.更新war包:用于访问web\app ...

  7. web前端面试知识点整理

    一.HTML5新特性 本地存储 webStorage websocket webworkers新增地理位置等API对css3的支持canvas多媒体标签新增表单元素类型结构标签:header nav ...

  8. 史上最全的Java高级技术点,全是Java高级进阶技术,几乎包含了Java后端的所有知识点

    史上最全的Java高级技术点,全是Java高级进阶技术,几乎包含了Java后端的所有知识点 1

  9. 一个新手后端需要了解的前端核心知识点之position(一)

    以下内容是基于观看慕课网视频教程总结的知识点,边打代码边总结,符合自己的思维习惯.不是针对新手入门 我做程序的初衷是想做一个网站出来.HTML语言当然重要啊,缺什么就百度什么,很浪费时间,还是好好的打 ...

随机推荐

  1. Linux中的磁盘练习

    查看磁盘接口类型 ide dh[a-z] scsi sd[a-z] 添加磁盘 先添加一个磁盘 cd /dev/ ls sd* 可以看到先添加的磁盘 磁盘分区 .fdisk /dev/sdb n (添加 ...

  2. MySQL 练习题目 二刷 - 2019-11-4 5:55 am

    建表的过程 create table student( sid int not null primary key, sname ) not null, sborn date, ssex ) not n ...

  3. shell札记

    1.echo变量名的技巧 #! /bin/bash read -p "please input value a: " a declare -i ai=a echo -e " ...

  4. HHHOJ #153. 「NOI模拟 #2」Kotomi

    抽代的成分远远大于OI的成分 首先把一个点定为原点,然后我们发现如果我们不旋转此时答案就是所有位置的\(\gcd\) 如果要选择怎么办,我们考虑把我们选定的网格边连同方向和大小看做单位向量\(\vec ...

  5. Linux环境下安装Redis

    记录一下Linux环境下安装Redis,按顺序执行即可,这里下载的是Redis5,大家可根据自己的需求,修改版本号就好了,亲测可行. 1.下载Redis安装包cd /usr/local/wget ht ...

  6. R包 survival 生存分析

    https://cran.r-project.org/web/packages/survival/index.html

  7. Git 自救指南:这些坑你都跳得出吗?

    阅读本文大概需要 2 分钟. 菜单栏中添加我微信,私聊[加群]拉你入微信学习交流群 Git 虽然因其分布式管理方式,不完全依赖网络,良好的分支策略,容易部署等优点,已经成为最受欢迎的源代码管理方式. ...

  8. Windows版:Nginx部署React项目并访问Spring Boot后台数据

    一, 打包react项目 1,在工作空间目录下create-react-app test-arrange 创建项目test-arrange 2,在新建的项目中写好请求与页面 3,打包, 在项目目录下 ...

  9. [Beta]Scrum Meeting#10

    github 本次会议项目由PM召开,时间为5月15日晚上10点30分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客整理文档 撰写博客整理文档 swoip 为适应新功能调整布局前 ...

  10. 搭建基于 Anaconda 管理的多用户 JupyterHub 平台

    搭建基于 Anaconda 管理的多用户 JupyterHub 平台 情况:计算工作站放在实验室,多个同学需要接入使用,且需要各自独立的环境,并使用 Jupyter notebook 平台以方便协作. ...