默认contenType下

在ajax中不写contentType的情况下

contentType:"application/x-www-form-urlencoded;charset=UTF-8" (默认)

总结以下例证:

当ajax为默认的application/x-www-form-urlencoded时,能够处理简单的JSON(单层),遇到复杂的嵌套JSON的情况就不能处理了(含数组情况);

这种情况下要处理嵌套JSON的内容,必须将其转化成传统的key=value的形式后放入ajax的data中。

相对而言,在简单的JSON情况下,后台的controller中直接在方法上写形参即可,亦可用vo对象接收;而在复杂参数的情况下,必须使用vo对象来进行值接收,再写在形参上是行不通的。

1.当为简单JSON时

以下传输的json中4个字段都为字符串

ajax

// 例如:
// -----------------right-begin-----------------
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd';
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data: {
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award},
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// -----------------right-end-----------------

controller

// -----------------right-begin-----------------
// 以下1.2均可 // 1.用单独的字段来接收
@PostMapping("/api/admin/about-JK/edit-JK-text")
// 顺便补充,如果前台json传过来的名称中有和参数名称不对应的情况
// 例如:profession_scale,只需要在参数前加
// @RequestParam("profession_scale") String professionScale
// 但是只能是用单个参数接收的时候可以用,但是如果是vo对象接收,就没有办法了!
// 还是只能修改ajax中data的key
public JsonData editAboutJKTextAdmin(
String history, String professionScale,String constructionScale,
String award) {
JsonData json = aboutJKService.editAboutJKText(aboutJKVo); return json;
} // 2.用vo对象来接受
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
JsonData json = aboutJKService.editAboutJKText(aboutJKVo); return json;
} // -----------------right-end-----------------

vo

// -----------------right-begin-----------------
@Data //lombok
@AllArgsConstructor //lombok
@NoArgsConstructor //lombok
public class AboutJKVo implements Serializable {
private String history;
private String professionScale;
private String constructionScale;
private String award;
}
// -----------------right-end-----------------

2.当为复杂JSON的时候

意为多重嵌套的JSON,最典型的即含有数组的JSON

ajax

// 1.
// ------------------- error-begin -------------------
// 服务器直接 500
var carouselLink = new Array();
carouselLink.push('1.jpg');
carouselLink.push('2.jpg');
carouselLink.push('3.jpg');
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd';
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data: {
"carouselLink": carouselLink,
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award},
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// ------------------- error-end -------------------
// 如果还要使用默认contentType为application/x-www-form-urlencoded;charset=UTF-8
// 以上的ajax已经行不通了!
// 那应该怎么写?
// 使用application/x-www-form-urlencoded兼容度最高的key=value形式
// 2.
// ------------------- right-begin -------------------
var carouselLink = new Array();
carouselLink.push('1.jpg');
carouselLink.push('2.jpg');
carouselLink.push('3.jpg');
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd';
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:
"carouselLink="+carouselLink+"&history=" + history+
"&professionScale="+ professionScale +
"&constructionScale="+ constructionScale +"&award=" + award,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// ------------------- right-end -------------------

controller

// 3.
// ------------------- error-begin -------------------
// 1.用单独的字段来接收
// 服务器也是直接 500
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(
List<String> carouselLink,
String history, String professionScale,String constructionScale,
String award) {
System.out.println(carouselLink + history +
professionScale + constructionScale + award); return null;
}
// ------------------- error-end -------------------
// 当key=value中有了list之后,controller内便不能直接用参数接收了!
// 只能通过vo对象来接收
// 4.
// -----------------right-begin-----------------
// 2.用vo对象来接受
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}
// -----------------right-end-----------------

vo

// -----------------right-begin-----------------
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AboutJKVo implements Serializable {
private List<String> carouselLink;
private String history;
private String professionScale;
private String constructionScale;
private String award;
}
// -----------------right-end-----------------

结果

1 和 3 组合 500 NoSuchMethodException

1 和 4 组合 500 java.lang.NumberFormatException: For input string: ""

2 和 3 组合 500 NoSuchMethodException

2 和 4 组合 success!

contentType为application/json时

在ajax中声明 contentType的类型:

contentType: "application/json"

总结以下例证

1.当ajax声明contentType: "application/json"之后,与之对应,不能再像默认contentType为application/x-www-form-urlencoded的时候一样,直接传递json对象了,必须传递json字符串!

通过JSON.stringify() 去将json对象转化成json字符串。

2.与之对应,controller需要注意的是:

  • controller中,跟在@RequestBody后的参数,和ajax传递过来的json字符串,必须是严格的json层级对应情况!

    • 情况一:假如ajax传输的json字符串为'[1, 2, 3]' 与之对应,controller的形参中,就必须有一个List<Integer> list 去接收它。

    • 情况二:假如ajax传输的json字符串为'{"names":["aaa", "bbb", "ccc"]}',那么controller的形参中,就必须是一个vo对象,并且对象中有一个叫做names的List<String>。

    • 总:只要外部有{},则controller应该用vo对象接收,直接是'aaa'字符串,或者['aaa', 'bbb']数组,则必须用一个对应的String 类型,或者List<string>类型来接收。

  • @RequestBody在一个controller层方法中,只能出现一次。

    • 如果一个方法形参中出现多个@RequestBody,将会注入失败。
    • 如果只有一个String类型的参数,但是ajax传输过来的是一个复杂json,那么这个复杂json将以字符串的形式被全部注入到那个String类型的参数中,这是一种极端情况。

3.补充,建议:可能是jquery的版本问题,在我原来使用3.x版本的jquery时,出现过复杂json无法注入vo对象的情况,原因是jquery默认会调用jQuery.param深度序列化参数,以适应如PHP和Ruby on Rails框架,但servelt api无法处理。但这里我使用的jquery-2.1.1并未出现此状况。

但稳妥起见,建议在ajax中加上参数traditional:true,来保障json的解析正常!

1.restful风格下传递复杂json

ajax

// 1.
// ------------------- error-begin -------------------
var carouselLink = new Array();
carouselLink.push('1.jpg');
carouselLink.push('2.jpg');
carouselLink.push('3.jpg');
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd';
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:{
"carouselLink": carouselLink,
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award},
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// ------------------- right-end ------------------- // 2.
// -----------------right-begin-----------------
var carouselLink = new Array();
carouselLink.push('1.jpg');
carouselLink.push('2.jpg');
carouselLink.push('3.jpg');
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd'; var dataJSON = {
"carouselLink": carouselLink,
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award} var dataJSONStr = JSON.stringify(dataJSON);
console.log(dataJSON)
console.log(dataJSONStr)
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
data: dataJSONStr,
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// -----------------right-end-----------------

controller

// 3.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(List<String> carouselLink, String history,
String professionScale, String constructionScale,
String award) {
System.out.println(carouselLink +
history +
professionScale +
constructionScale + award);
return null;
}
// ------------------- error-end ------------------- // 4.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody List<String> carouselLink,
@RequestBody String history,
@RequestBody String professionScale,
@RequestBody String constructionScale,
@RequestBody String award) {
System.out.println(carouselLink +
history +
professionScale +
constructionScale + award);
return null;
}
// ------------------- error-end ------------------- // 5.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}
// ------------------- error-end ------------------- // 6.
// -----------------right-begin-----------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}
// -----------------right-end-----------------

vo

// -----------------right-begin-----------------
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AboutJKVo implements Serializable {
private List<String> carouselLink;
private String history;
private String professionScale;
private String constructionScale;
private String award;
}
// -----------------right-end-----------------

结果

1 和 3 组合 500 NoSuchMethodException

1 和 4 组合 400 JSON parse error: Unrecognized token 'carouselLink'

1 和 5 组合 无报错,但

AboutJKVo(carouselLink=null, history=null, professionScale=null, constructionScale=null, award=null)

1 和 6 组合 400 badRequest!

2 和 3 组合 500 NoSuchMethodException

2 和 4 组合 400 JSON parse error

2 和 5 组合 无报错,但

AboutJKVo(carouselLink=null, history=null, professionScale=null, constructionScale=null, award=null)

2 和 6 组合 success!

2.restful风格下传递简单json

ajax

// 1.
// ------------------- error-begin -------------------
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd';
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:{
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award},
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// ------------------- error-end ------------------- // 2.
// -----------------right-begin-----------------
var history = 'aaa';
var professionScale = 'bbb';
var constructionScale = 'ccc';
var award = 'ddd'; var dataJSON = {
"history": history,
"professionScale": professionScale,
"constructionScale": constructionScale,
"award": award} var dataJSONStr = JSON.stringify(dataJSON);
console.log(dataJSON)
console.log(dataJSONStr)
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
data: dataJSONStr,
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});
// -----------------right-end-----------------

controller

// 3.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(String history, String professionScale,
String constructionScale,
String award) {
System.out.println(history +
professionScale +
constructionScale + award);
return null;
}
// ------------------- error-end ------------------- // 4.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody String history,
@RequestBody String professionScale,
@RequestBody String constructionScale,
@RequestBody String award) {
System.out.println(history +
professionScale +
constructionScale + award);
return null;
}
// ------------------- error-end ------------------- // 5.
// ------------------- error-begin -------------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}
// ------------------- error-end ------------------- // 6.
// -----------------right-begin-----------------
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}
// -----------------right-end-----------------

vo

// -----------------right-begin-----------------
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AboutJKVo implements Serializable {
private String history;
private String professionScale;
private String constructionScale;
private String award;
}
// -----------------right-end-----------------

结果

1 和 3 组合 无报错,但 4个参数全为null

1 和 4 组合 400 badRequest @RequestBody需要的参数无法注入

1 和 5 组合 无报错,但 4个参数全为null

1 和 6 组合 JSON parse error

2 和 3 组合 无报错,但4个参数全为null

2 和 4 组合 400 badRequest @RequestBody需要的参数无法注入

2 和 5 组合 无报错,但 4个参数全为null

2 和 6 组合 success!

3.restful风格下传递list

ajax

// 1.
var list = new Array();
list.push('1.jpg');
list.push('2.jpg');
list.push('3.jpg'); $.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:list,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
}); // 2.
var list = new Array();
list.push('1.jpg');
list.push('2.jpg');
list.push('3.jpg'); $.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:{'list':list},
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
}); // 2.+
var list = new Array();
list.push('1.jpg');
list.push('2.jpg');
list.push('3.jpg');
var dataJSON = {'list':list}
var dataJSONStr = JSON.stringify(dataJSON);
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data: dataJSONStr,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
}); // 3.
var carouselLink = new Array();
carouselLink.push('1.jpg');
carouselLink.push('2.jpg');
carouselLink.push('3.jpg'); var list = JSON.stringify(carouselLink);
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:list,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});

controller

// 4.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(List<String> list) {
System.out.println(list); return null;
} // 5.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody List<String> list) {
System.out.println(list); return null;
} // 6.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
} // 7.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}

vo

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AboutJKVo implements Serializable {
private List<String> list;
}

结果

1 和 4 500 NoSuchMethodException

1 和 5 400 JSON parse error

1 和 6 无报错,但为null

1 和 7 400 JSON parse error

2 和 4 500 NoSuchMethodException

2 和 5 400 JSON parse error

2 和 6 无报错,但为null

2 和 7 400 JSON parse error

3 和 4 500 NoSuchMethodException

3 和 5 success!

3 和 6 无报错,但为null

3 和 7 400 JSON parse error

2+ 和 4 500 NoSuchMethodException

2+ 和 5 400 JSON parse error

2+ 和 6 无报错,但为null

2+ 和 7 success!

4.restful下传递单参

ajax

// 1.
var professionScale = 'aaa' $.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data: professionScale,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
}); // 2.
var professionScale = 'aaa' $.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data:{'professionScale':professionScale},
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
}); // 3.
var professionScale = 'aaa' var dataJSON = {'professionScale':professionScale}
var dataJSONStr = JSON.stringify(dataJSON);
$.ajax({
url:"/api/admin/about-JK/edit-JK-text",
contentType:'application/json',
type: "POST",
// 期待服务器返回的类型:json、jsonp、text ... 此参数加上最好
dataType: "json",
data: dataJSONStr,
dataType: "json",
success: function (res) {
if (res.code == 0) {
console.log(res);
} else {
console.log(res);
}
},
error: function () {
console.log('请求系统异常');
}
});

controller

// 4.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(String professionScale) {
System.out.println(professionScale); return null;
} // 5.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody String professionScale) {
System.out.println(professionScale); return null;
} // 6.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
} // 7.
@PostMapping("/api/admin/about-JK/edit-JK-text")
public JsonData editAboutJKTextAdmin(@RequestBody AboutJKVo aboutJKVo) {
System.out.println(aboutJKVo); return null;
}

vo

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AboutJKVo implements Serializable {
private String professionScale;
}

结果

1 和 4 无报错,但为null

1 和 5 success!

1 和 6 无报错,但为null

1 和 7 JSON parse error: Unrecognized token 'aaa'

2 和 4 无报错,但为null

2 和 5 错误的值 professionScale = "professionScale=aaa"

2 和 6 无报错,但为null

2 和 7 JSON parse error: Unrecognized token 'professionScale'

3 和 4 无报错,但为null

3 和 5 错误的值 professionScale = "{"professionScale":"aaa"}"

3 和 6 无报错,但为null

3 和 7 success!

ajax前后台通信验错的更多相关文章

  1. flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法

    flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...

  2. ajax 异步 通信 小例子 servlet与 jsp异步 get

    get  请求参数通过 url那里写进去,然后send(null) html文件和 servlet进行通信 通过ajax 进行通信 <!DOCTYPE html PUBLIC "-// ...

  3. ajax jsonp请求报错not a function的解决方案

    概述 最近工作中使用ajax,有时会报json4 is not a function的错误,有时又不会报错.找了很久,网上说是因为多次请求同一个资源导致的,但是我检查了自己的代码,对于重复资源并没有重 ...

  4. 火狐浏览器调试ajax异步页面时报错NS_ERROR_UNEXPECTER

    第一个直观的结论就是ajax调用出错,如果其他浏览器却调用没报错,而且正常返回值了,那么就是Firefox浏览器的问题了: 如果其他浏览器也没余完全正常执行,而是出现和我上一篇ajax向后台请求数据, ...

  5. javascript使用web proxy来实现ajax cross-domain通信

    在现代浏览器中,都强加了对javacript代码的访问限制,比如一个页面的js无法向非同源的url实现ajax请求,获得数据.在这时,是浏览器端会报错: No 'Access-Control-Allo ...

  6. ajax 异步 通信 小例子 servlet与 jsp异步 post方法

    post请求 url后面加参数 接收不到的,必须 放到send("use"=user)形式 还要加上 xhr.setRequestHeader("Content-Type ...

  7. LigerUI用Post\Get\Ajax前后台交互方式的写法

    parms 参数统一 json格式的数据 url 访问后台的url 设置同步参数 [javascript] view plain copy   $.ajaxSetup({ async : false} ...

  8. ajax post 请求报错Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade

    jquery ajax跨域请求,webapi webconfig配置 前台代码(放了一部分) function CheckIn(roomno) { $.ajax({ url: 'https://www ...

  9. Websocket实现前后台通信,demo小测试

    新需求大概如下:用户登录系统,登录成功之后建立websocket连接,实现通信 总体思路:前端不是我负责,只是简单的做个功能,先实现登录,把用户标识存入HttpSeesion,再建立websocket ...

随机推荐

  1. 剑指offer-子树结构

    描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构)   求解思路: 首先肯定是找到树A中等于树B根节点的节点. A和B按照同样的遍历顺序比较,如果全相同A ...

  2. 离散数学-传递闭包(POJ3275)

    就是n的元素给定m个关系求他们之间的关系. eg.  ∵a>b and b>c ∴a>c emmmm 若要知道n个元素的绝对关系,则需知道C(n,2)个关系. 例题:POJ3275 ...

  3. Splay与FHQ-Treap

    两个一起学的,就放一块了. 主要是用来存板子. Splay //This is a Splay Tree. #include <cstdio> #include <cstring&g ...

  4. sql语句优化原理

    前言 网上有很多关于sql语句优化的文章,我这里想说下为什么这样...写sql语句,能够提高查询的效率. 1 sql语句优化原理 要想写出好的sql,就要学会用数据库的方式来思考如何执行sql,那么什 ...

  5. CAS 原理 应用

    原子CAS操作 原子操作指令里,有原子加,原子减,cas到底是什么呢? 首先看一段代码, bool compare_and_swap(int *accum, int *dest, int newval ...

  6. element UI表格行高、padding等设置报错问题

    element UI里面表格的行高需要自己调整高度和设置padding,直接写style是不行的,里面有 : 1.row-style (行的 style) 2.header-row-styl   (表 ...

  7. 大数据学习(12)—— Hive Server2服务

    什么是Hive Server2 上一篇我们启动了hive --service metastore服务,可以通过命令行来访问hive服务,但是它不支持多客户端同时访问,参见官网说明:HiveServer ...

  8. Scrapy入门到放弃04:下载器中间件,让爬虫更完美

    前言 MiddleWare,顾名思义,中间件.主要处理请求(例如添加代理IP.添加请求头等)和处理响应 本篇文章主要讲述下载器中间件的概念,以及如何使用中间件和自定义中间件. MiddleWare分类 ...

  9. 记录21.07.20 —— js语言回顾

    js语言回顾 1.语法 a并没有声明,也可以输出,不会报错. 添加一条语句 则需要声明,称之为严谨语法 2.数组 2.1数组遍历三种方法 for-in与for-of forEach forEach调用 ...

  10. 剑指 Offer 32 - II. 从上到下打印二叉树 II

    剑指 Offer 32 - II. 从上到下打印二叉树 II 从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行. 例如: 给定二叉树: [3,9,20,null,null,1 ...