默认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. 使用宝塔配置laravel站点时,遇到open_basedir restriction in effect. 原因与解决方法

    今天一位朋友在linux服务器部署thinkphp5的时候PHP报了这个错误,如下: Warning: require(): open_basedir restriction in effect. F ...

  2. synchronized锁代码块(七)

    synchronized同步代码块 用关键字synchronized声明方法在某些情况下是有弊端的,比如A线程调用同步方法执行一个较长时间的任务,那么B线程必须等待比较长的时间.这种情况下可以尝试使用 ...

  3. 深入刨析tomcat 之---第8篇 how tomcat works 第11章 11.9应用程序,自定义Filter,及注册

    writed by 张艳涛, 标签:全网独一份, 自定义一个Filter 起因:在学习深入刨析tomcat的学习中,第11章,说了调用过滤链的原理,但没有给出实例来,自己经过分析,给出来了一个Filt ...

  4. SpringCloud升级之路2020.0.x版-3.Eureka Server 与 API 网关要考虑的问题

    本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ 之前我们提到了 ...

  5. ECShop 2.x/3.x SQL注入/任意代码执行漏洞

    poc地址:https://github.com/vulhub/vulhub/blob/master/ecshop/xianzhi-2017-02-82239600/README.zh-cn.md 生 ...

  6. Fast Run:提高 MegEngine 模型推理性能的神奇功能

    作者:王博文 | 旷视 MegEngine 架构师 一.背景 对于深度学习框架来说,网络的训练/推理时间是用户非常看中的.在实际生产条件下,用户设计的 NN 网络是千差万别,即使是同一类数学计算,参数 ...

  7. noip模拟30[毛毛毛探探探]

    \(noip模拟30\;solutions\) 所以说,这次被初中的大神给爆了????? 其实真的不甘心,这次考场上的遗憾太多,浪费的时间过多,心情非常不好 用这篇题解来结束这场让人伤心的考试吧 \( ...

  8. Jmeter分布式压测实战及踩坑处理(含参数化)

    项目中使用Jmeter进行大并发压测时,单机受限内存.CPU.网络IO,会出现服务器压力还没有上 去,但压测服务器由于模拟的压力太大死机的情况.JMeter的集群模式可以让我们将多台机器联合起来 一起 ...

  9. 3D网页小实验-基于多线程和精灵动画实现RTS式单位行为

    一.实验目的: 1.在上一篇的"RTS式单位控制"的基础上添加逻辑线程,为每个单位实现ai计算: 2.用精灵动画为单位的行为显示对应的动作效果. 二.运行效果: 1.场景中的单位分 ...

  10. 史上最详细的Android消息机制源码解析

    本人只是Android菜鸡一个,写技术文章只是为了总结自己最近学习到的知识,从来不敢为人师,如果里面有不正确的地方请大家尽情指出,谢谢! 606页Android最新面试题含答案,有兴趣可以点击获取. ...