SpringMvc请求
Get请求会暴露传入的参数
post请求需要下载软件
点击安装
下载完成后登录,新建目录params目录
新建接口
新建post接口
选择post输入地址然后发送,观看后台
http://localhost:8081/ssm/param/login?name=&age=18 :get请求容易暴露个人信息
选择body,解决乱码
//解决post中文乱码问题
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
return new Filter[]{characterEncodingFilter};
新建pojo,新建User,生成属性
输入
package com.heima.pojo;
public class User {
private int id;
private String name;
private int password;
private String addr;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPassword() {
return password;
}
public void setPassword(int password) {
this.password = password;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", password=" + password +
", addr='" + addr + '\'' +
'}';
}
}
嵌套结果
新建dept
package com.heima.pojo;
public class Dept {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Dept{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
新建控制类RespController
package com.heima.controller;
import com.heima.pojo.Dept;
import com.heima.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/resp")
public class RespController {
@RequestMapping("/user")
public User getUser(){
User user = new User();
user.setId(10);
user.setName("张红");
user.setPassword("666");
user.setAddr("上饶");
Dept dept = new Dept();
dept.setId(100);
dept.setName("销售部");
user.setDept(dept);
return user;
}
}
结果点击网址发送
整个项目结构