在构建一个系统时,前端和后台总是需要对接,在springmvc架构里,这种对接一般发生在Controller层中。方法参数绑定首先支持Java所有基本类型(包括: byte、short、int、long、float、double、char、string、boolean),以及基本类型对应封装高级类(包括:StringBuilder、StringBuffer),也包含 了我们自己定义的各种JavaBean类型。接受的方式有很多,但是也要在接受数据时也要体现面向对象的思想。
一、简单传入
以用户登陆为例,在前台传入数据,做一个传入的例子。
前台传入数据的形式为 username=10&password=10
<html>
<head>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
//简单形式的传参
$.ajax({
type: "POST",
url: "http://localhost:8080/test/requesetParamGet",
contentType: "application/x-www-form-urlencoded",
data:"username=10&password=10",
dataType: "json",
success: function (result) {
if (result.code == 0) {
console.log(result)
} else {
}
}
});
</script>
</head>
</html>
在这种情况下,如何在后台进行接受呢