标签:node RequestParam value 端传 参时 参数 ResponseEntity 注解 page
1.@PathVariable用法
@GetMapping("spu/updatesaleable/{id}")//注意此处注解加上参数
public ResponseEntity<Void> updatezhuangtai(@PathVariable("id")Long id){//此处注解也需要加上参数
this.goodsService.updatesaleable(id);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
所对应的前端
updatesaleable(id){
this.$message.confirm("确认要改变状态吗?")
.then(() => {
this.$http.get("/item/spu/updatesaleable/" + id)//注意传参方法为("/**/**/"+参数)
.then(() => {
this.$message.success("修改成功");
this.getDataFromServer();
})
})
}
2.@RequestParam用法
@RequestParam注解主要有哪些参数:
value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入;
required:是否必须,默认是true,表示请求中一定要有相应的参数,否则将报404错误码;
defaultValue:默认值,表示如果请求中没有同名参数时的默认值
@GetMapping("page")//此处注解无参数
public ResponseEntity<PageResult<Brand>> queryBrandsByPage(
@RequestParam(value = "key", required = false)String key,
@RequestParam(value = "page", defaultValue = "1")Integer page,
@RequestParam(value = "rows", defaultValue = "5")Integer rows,
@RequestParam(value = "sortBy", required = false)String sortBy,
@RequestParam(value = "desc", required = false)Boolean desc
){
PageResult<Brand> pageResult = this.brandService.queryBrandsByPage(key, page, rows, sortBy, desc);
if (CollectionUtils.isEmpty(pageResult.getItems())){
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(pageResult);
}
所对应的前端
getDataFromServer() { // 从服务的加载数的方法。
// 发起请求
this.$http.get("/item/brand/page", {
params: {
key: this.search, // 搜索条件
page: this.pagination.page,// 当前页
rows: this.pagination.rowsPerPage,// 每页大小
sortBy: this.pagination.sortBy,// 排序字段
desc: this.pagination.descending// 是否降序
}
}).then(({data}) => { // 这里使用箭头函数
this.brands = data.items;
this.totalBrands = data.total;
// 完成赋值后,把加载状态赋值为false
this.loading = false;
})
}
@PostMapping//此处无参数
public ResponseEntity<Void> saveBrand(Brand brand, @RequestParam("cids")List<Long> cids){ //此处有(”参数“)
this.brandService.saveBrand(brand,cids);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
对应前端
addBrand() {
// 修改标记
this.isEdit = false;
// 控制弹窗可见:
this.show = true;
// 把oldBrand变为null
this.oldBrand = null;
}
3.@RequestBody用法
@PostMapping("add")//此处无参数
public void toAdd(@RequestBody Map<String,Map<String,Category>> map){ //不写(”参数“)
Map<String,Category> params=map.get("params");
Category node = params.get("node");
this.categoryService.add(node);
}
对应后端
methods: {
handleAdd(node) {
this.$http.post("/item/category/add",{
params:{
node:node
}
})
console.log("add .... ");
console.log(node);
}
标签:node,RequestParam,value,端传,参时,参数,ResponseEntity,注解,page 来源: https://blog.csdn.net/lihuan666/article/details/100164841
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。