RestFul风格Postman传参测试
一、传递单个参数
以根据id删除为例
controller层:
@CrossOrigin
@RestController
@RequestMapping("/job")
public class JobController {
@Autowired
private JobService jobService;
//删除
@DeleteMapping("/delete/{id}")
public String removeJob(@PathVariable("id") String id) {
jobService.removeJob(id);
return "success";
}
}
Postman测试:
二、传递多个参数
以post请求登录传递用户名密码为例
Postman测试:
三、传递对象
以post请求添加数据为例
controller层:
@CrossOrigin
@RestController
@RequestMapping("/job")
public class JobController {
@Autowired
private JobService jobService;
//插入
@PostMapping("/insert")
public String saveJob(@RequestBody Job job) {
jobService.saveJob(job);
return "success";
}
}
Job:
@Setter
@Getter
@ToString
public class Job {
private String id ;
private String name ;
private String remark ;
}
Postman测试:
四、传递Map类型参数
以post请求查询数据为例
controller层:
@CrossOrigin
@RestController
@RequestMapping("/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* 查询
* @param condition
* @return
*/
@PostMapping("/select")
public List<Employee> selectEmployee(@RequestBody Map condition){
return employeeService.selectEmployee(condition);
}
}
EmployeeMapper.xml
<!-- select操作-->
<select id="selectEmployee" parameterType="Map" resultMap="employeeResultMap">
select e.*,d.name as dept,j.name as job from employee_inf e,dept_inf d,job_inf j
where e.deptid=d.id and e.jobid=j.id
<if test="name != null and name != '' ">
and e.name like concat('%',#{name},'%')
</if>
<if test="dept != null and dept != '' ">
and e.deptid = #{dept}
</if>
<if test="job != null and job != '' ">
and e.jobid = #{job}
</if>
order by e.id
</select>
<resultMap id="employeeResultMap" type="Employee">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="deptid" column="deptid" />
<result property="jobid" column="jobid" />
<result property="cardid" column="cardid" />
<result property="address" column="address" />
<result property="postcode" column="postcode" />
<result property="tel" column="tel" />
<result property="phone" column="phone" />
<result property="qqnum" column="qqnum" />
<result property="email" column="email" />
<result property="sex" column="sex" />
<result property="party" column="party" />
<result property="birthday" column="birthday" />
<result property="race" column="race" />
<result property="education" column="education" />
<result property="speciality" column="speciality" />
<result property="hobby" column="hobby" />
<result property="remark" column="remark" />
<result property="createdate" column="createdate" />
<association property="dept" javaType="Dept">
<id property="id" column="deptid"/>
<result property="name" column="dept"/>
</association>
<association property="job" javaType="Job">
<id property="id" column="jobid"/>
<result property="name" column="job"/>
</association>
</resultMap>
Postman测试:
五、传递List类型参数
传递List类型参数目前还没遇到,网上查到的例子,需要的话自测。
看网上例子和Map参数的区别就是,内容框里写数组