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參數的區別就是,內容框裏寫數組

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章