axiosHelper
let res = await this.api.post(
'/api/projects/select',
{ id: this.id}
);
let _this = this;
_this.axiosHelper
.post(url, this.id ? project : this.ruleForm)
.then((response) => {
// this.hideLoading();
if (response.status == 200) {
console.log(response);
if (response.data.code !== 0) {
_this.$message.error({
message: response.data.msg,
});
return;
}
_this.$message.success({
message: '保存成功',
});
_this.isAddProject = false;
_this.$emit('closeDialog');
_this.$emit('updateChildProject');
_this.resetForm();
} else {
_this.$message({
message: '提交失败',
type: 'error',
});
}
})
.catch((err) => {
// this.hideLoading();
_this.$message({
message: '提交失败,' + err.response.data.message,
type: 'error',
});
});
通用
function submit(val) {
var dataObj = {};
dataObj.departGuid = $("#departGuid").val();
dataObj.states = 0;
$.ajax({
url: ctx + "beforehand/wholeDepartment/submit",
type: "post",
data: JSON.stringify(dataObj),
dataType: "json",
contentType: 'application/json',
success: function (result) {
$.modal.alertSuccess('提交审核成功,下一步' + nextStatesName);
error: function () {
$.modal.alertWarning("操作失败");
}
});
}
@PostMapping("/evaluationSubmit")
@ResponseBody
public AjaxResult evaluationSubmit(@RequestBody WholeDepartment wholeDepartment) {
return wholeDepartmentService.evaluationSubmit(wholeDepartment);
}
传输方式一,只有一个参数get (@PathVariable)
- JS
updateUrl: prefix + "/edit/{id}",
ctx + "beforehand/evaluationInfo/export1/" + id
- 控制器
@GetMapping("/edit/{evaluationTargetCompletionGuid}")
public String edit(@PathVariable("evaluationTargetCompletionGuid") String evaluationTargetCompletionGuid, ModelMap mmap)
传输方式二,多个参数get (@RequestParam)
访问路径
http://localhost:8071/direct?msg=%27%E5%95%8A%E5%95%8A%E5%95%8A%27&code=6
控制器
@GetMapping("/direct")
public String sendEmail(@RequestParam Map<String,Object> params){
String msg = params.get("msg").toString();
rabbitTemplate.convertAndSend("EmailExchange","EmailRoutingKey",msg);
return "OK";
}
传输方式三,只有一个参数 post
- JS
function fileDown(path){
$.ajax({
url: ctx + "beforehand/projectFile/fileDown?filePath="+path,
type: "post",
success: function (result) {
alert('控制器成功');
},
error: function () {
alert("控制器错误");
}
});
}
- 控制器
public String Down( String filePath) {
传输方式四 Post dataObj
- JS
function fileDown(path){
dataObj = {};
dataObj.filePath = path;
$.ajax({
url: ctx + "beforehand/projectFile/fileDown",
type: "post",
data: JSON.stringify(dataObj),
dataType: "json",
contentType: 'application/json',
success: function (result) {
alert('控制器成功');
},
error: function () {
alert("控制器错误");
}
});
}
- 控制器
public String Down( @RequestBody ProjectFile projectFile ) {
@RequestParam和@RequestBody的区别
由于spring的RequestParam注解接收的参数是来自于requestHeader中,即请求头,也就是在url中,格式为xxx?username=123&password=456,而RequestBody注解接收的参数则是来自于requestBody中,即请求体中。
传数组
后端用数组类型接收
前端:http://localhost:8591/api/promotion/push/pickcenter/1,3
@PostMapping("/pickcenter/{useType}")
public ResponseEntity<Map> pickcardcenter(@PathVariable("useType") int[] useTypeArray){