RestFul风格Postman传参测试

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参数的区别就是,内容框里写数组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值