后端&前端零碎知识点和注意问题
后端
1. Spring自带的MD5加密工具类
import org.springframework.util.DigestUtils; 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是个枚举类
<if test="requestMethod!=null and requestMethod!='' ">
REQUEST_METHOD=#{requestMethod , jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler},
</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
import com.example.demo.interceptor.CommonInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration
public class MyWebConfig implements WebMvcConfigurer { @Autowired
private CommonInterceptor commonInterceptor; /**
* 配置拦截器
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(commonInterceptor).addPathPatterns("/**").excludePathPatterns("/login");
}
}
6. 查看SpringBoot默认的配置类
在application.properties里面配置debug=true,在启动的时候就会打印开启的默认配置类。

7. maven打包SpringBoot项目后,java -jar命令报错,找不到主清单属性
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<!--解决打包后,执行java -jar 命令,找不到主清单属性-->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
8. Java解析HTML/XML字符串
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
代码
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element; import java.util.HashMap;
import java.util.Map; public class Test { public static void main(String[] args) throws DocumentException {
parse(create());
} private static String create(){
Document document = DocumentHelper.createDocument();
Element rootElement = document.addElement("response");
Map<String,String> postMap = new HashMap<>();
postMap.put("code", "200");
postMap.put("msg", "操作成功!");
for (String key : postMap.keySet()) {
Element element = rootElement.addElement(key);
element.setText(postMap.get(key));
}
String xml = document.getRootElement().asXML();
System.out.println("Create Result:" + xml);
return xml;
} private static void parse(String data) throws DocumentException {
Document document = DocumentHelper.parseText(data);
Element rootElement = document.getRootElement();
System.out.println("==============Parse Result ==============");
System.out.println(rootElement.element("code").getText());
System.out.println(rootElement.element("msg").getText());
}
}
输出

9. 后端传递Long,前端精度丢失解决
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; public class User { /**
* 方法一
*/
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long userId; /**
* 方法二
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long orderId; }
10. Integer对象转Comparable对象(来自JDK源码)
Integer x = 10;
Comparable<Integer> key = (Comparable<Integer>) x;
System.out.println(x.compareTo(1));
11. Optional的使用
List<String> list = null;
// 无论list是否为空,都会执行orElse
List<String> strings = Optional.ofNullable(list).orElse(new ArrayList<>());
// 只有list为空,才会执行orElseGet
List<String> strings2 = Optional.ofNullable(list).orElseGet(ArrayList::new);
12. 解析Excel
引入依赖
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
代码
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; public class Main { public static void main(String[] args) throws Exception {
File file = new File("excel.xlsx");
readExcel(file);
} private static void readExcel(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
List<String> codes = new ArrayList<>();
Workbook wb = null;
// 解析后缀
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
// 根据后缀判断文件类型
if ("xls".equals(prefix)){
wb = new HSSFWorkbook(in);
}else if ("xlsx".equals(prefix)){
wb = new XSSFWorkbook(in);
}
if (wb != null){
// sheet数量
int numberOfSheets = wb.getNumberOfSheets();
// 遍历sheet
for (int i = 0; i < numberOfSheets; i++){
Sheet sheet = wb.getSheetAt(i);
// 遍历标题行(第0行)
Row title = sheet.getRow(0);
System.out.println("===============");
for (int c = 0; c < title.getLastCellNum(); c++){
Cell cell = title.getCell(c);
System.out.print(selectCellType(cell) + "\t");
}
System.out.println("\n===============");
// 遍历数据行(第1行开始)
for (int j = 1; j <= sheet.getLastRowNum(); j++){
Row row = sheet.getRow(j); for (int c = 0; c < row.getLastCellNum(); c++){
Cell cell = row.getCell(c);
System.out.print(selectCellType(cell) + "\t");
}
System.out.println();
}
}
}
} private static Object selectCellType(Cell cell){
switch (cell.getCellType()){
case BLANK:
return "";
case STRING:
return cell.getStringCellValue();
case BOOLEAN:
return cell.getBooleanCellValue();
case NUMERIC:
return cell.getNumericCellValue();
case FORMULA:
return cell.getCellFormula();
default:
return "";
}
} }
测试:

13. 按照逗号分隔的 String与List 互转
依赖
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
代码
import org.apache.commons.lang3.StringUtils;
String text = "A,B,C,D,E";
// --------------String转List
List<String> stringList = Arrays.asList(text.split(","));
// --------------List转String
String join = StringUtils.join(stringList, ",");
System.out.println(stringList + "\t\t" + join);
测试:

前端
1. string转number
<script>
$(document).ready(function(){
var p = +$('p').text();
$('div').text(p+1);
});
</script>
</head>
<body>
<div></div>
<p>1</p>
</body>
</html>
输出2而不是11
2. JQuery警告,低效的选择器用法
比如:
$('#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
应改成:
$('#resultData').find(':checked');
3. Comparison $.trim($(t[9]).val()) == "" may cause unexpected type coercion less...
比如:判断表单内容去除空格后是否为空
$.trim($(t[0]).val()) == ""
会警告

应改为:
$.trim($(t[0]).val()) === ""
4. new Boolean(value) 和 Boolean(value)的区别
前者是作为构造函数构造一个Boolean实例,得到的是一个对象;后者是作为普通函数调用,得到的是函数返回值false/true。
5. Ajax请求,传递的数组参数名称多了一个[]
利用JQuery的$.param(params,true)来解决
var myObject = {
a: {
one: 1,
two: 2,
three: 3
},
b: [1,2,3]
};
var recursiveEncoded = $.param(myObject);
var recursiveDecoded = decodeURIComponent($.param(myObject));
console.log(recursiveEncoded);
console.log(recursiveDecoded);
var shallowEncoded = $.param(myObject, true);
var shallowDecoded = decodeURIComponent(shallowEncoded);
console.log(shallowEncoded);
console.log(shallowDecoded);

6. Input 文件域重复上传,不触发change事件
<input type="file" id="upload">
$("#upload").change(function(){
// 上传或者其它操作
// ....
// 最后将value置为空
$(this).val('');
});
也可以用一个新的input替代当前的input。
后端&前端零碎知识点和注意问题的更多相关文章
- web开发前端面试知识点目录整理
web开发前端面试知识点目录整理 基本功考察 关于Html 1. html语义化标签的理解; 结构化的理解; 能否写出简洁的html结构; SEO优化 2. h5中新增的属性; 如自定义属性data, ...
- 中级前端必备知识点(2.5w+月薪)进阶 (分享知乎 : 平酱的填坑札记 关注专栏 用户:安大虎)
前端已经不再是5年前刚开始火爆时候的那种html+css+js+jquery的趋势了,现在需要你完全了解前端开发的同时,还要具备将上线.持续化.闭环.自动化.语义化.封装......等概念熟练运用到工 ...
- webdriver零碎知识点
#零碎知识点,用于记录平时遇到的比较杂的知识点 driver.current_url 获取当前url phantomjs 实现无浏览器界面自动化测试(driver = webdriver.Phanto ...
- 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事
一.条件分支语句 条件分支语句,也叫作条件判断语句,就是根据某种条件执行某些语句,不执行某些语句. JS中有三种语法是可以表示条件分支的 1.1 if……else…… 条件分支的主力语法,这个主力 ...
- Android零碎知识点 1
Android零碎知识点 1 Android在2.3版本上开始支持KeyEvent.KEYCODE_PAGE_DOWN以及KeyEvent.KEYCODE_PAGE_UP的操作. Androi ...
- 程序迭代时测试操作的要点(后端&前端)
今晚直播课内容简介,视频可点击链接免费听 <程序迭代时测试操作的要点(后端&前端)> ===== 1:迭代时后台涉及的操作有哪些?如何进行 a.更新war包:用于访问web\app ...
- web前端面试知识点整理
一.HTML5新特性 本地存储 webStorage websocket webworkers新增地理位置等API对css3的支持canvas多媒体标签新增表单元素类型结构标签:header nav ...
- 史上最全的Java高级技术点,全是Java高级进阶技术,几乎包含了Java后端的所有知识点
史上最全的Java高级技术点,全是Java高级进阶技术,几乎包含了Java后端的所有知识点 1
- 一个新手后端需要了解的前端核心知识点之position(一)
以下内容是基于观看慕课网视频教程总结的知识点,边打代码边总结,符合自己的思维习惯.不是针对新手入门 我做程序的初衷是想做一个网站出来.HTML语言当然重要啊,缺什么就百度什么,很浪费时间,还是好好的打 ...
随机推荐
- Lexicographical Substring Search SPOJ - SUBLEX (后缀数组)
Lexicographical Substrings Search \[ Time Limit: 149 ms \quad Memory Limit: 1572864 kB \] 题意 给出一个字符串 ...
- Bounding Box回归
简介 Bounding Box非常重要,在rcnn, fast rcnn, faster rcnn, yolo, r-fcn, ssd,到今年cvpr最新的yolo9000都会用到. 先看图 对于上图 ...
- BZOJ 4555:[TJOI2016&HEOI2016]求和(第二类斯特林数+NTT)
题目链接 \(Description\) 求 \[\sum_{i=0}^n\sum_{j=0}^iS(i,j)2^jj!\]对998244353取模后的结果. \(n<=10^5\) \(Sol ...
- 【JZOJ5553】【20190625】谜
题目 给出一个\(2\times n\)个点的二分图的邻接矩阵\(M\) 以及\(m\)个行替换元,\(k\)个列替换元 \(q\)次询问:op u v 表示用第v个行/列替换元去替换矩阵的第u行/列 ...
- GoCN每日新闻(2019-11-10)
GoCN每日新闻(2019-11-10) 1. Go Netpoll I/O多路复用构建原生网络模型之源码深度解析 https://taohuawu.club/go-netpoll-io-multip ...
- modis数据处理的坑(MOD02,mod03,mod04,MCD19A2)
一直以来处理modis产品都是用的 modis conversion toolkit(MCTK),用 IDL 来跑感觉好像也没什么问题,好像并没有去验证结果到底对不对,因为用的气溶胶数据 MOD04_ ...
- [Shell]多姿势反弹shell
客户端监听本地: nc -nvlp 4444 从原生的 shell 环境切换到 linux 的交互式 bash 环境: python -c 'import pty; pty.spawn("/ ...
- putty WinScp 免密登录远程 Linux
该方法的原理是预先生成一对公钥和私钥,私钥以文件的形式保存在本地,公钥保存在远程机器上.这样每次登录只需指定私钥文件,远程机器通过比对公钥和私钥来验证登录的合法性. Putty 免密登录 第一步 生成 ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- Mysql中联合索引的最左匹配原则(百度)
创建联合索引时列的选择原则 经常用的列优先(最左匹配原则) 离散度高的列优先(离散度高原则) 宽度小的列优先(最少空间原则) 在Mysql建立多列索引(联合索引)有最左前缀的原则,即最左优先.如果我们 ...