当前位置: 首页 > wzjs >正文

网站建设服务费要不要折旧呢wordpress模板加密

网站建设服务费要不要折旧呢,wordpress模板加密,为什么wordpress不能更新文章,腾讯wordpress 建站教程以下是关于Spring MVC中传递数组参数的详细说明,包括如何通过逗号分隔的字符串自动转换为数组,以及具体的代码示例和总结表格: 1. 核心机制 Spring MVC支持直接通过逗号分隔的字符串将请求参数自动转换为数组(String[]、int[]等&…

以下是关于Spring MVC中传递数组参数的详细说明,包括如何通过逗号分隔的字符串自动转换为数组,以及具体的代码示例和总结表格:


1. 核心机制

Spring MVC支持直接通过逗号分隔的字符串将请求参数自动转换为数组(String[]int[]等)。例如:

  • 请求参数items=1,2,3
  • 后端接收@RequestParam String[] items@RequestParam int[] numbers

2. 代码示例

2.1 基础用法:字符串数组
@RestController
public class ArrayController {// 接收逗号分隔的字符串数组@GetMapping("/items")public String getItems(@RequestParam("items") String[] items) {return "Received items: " + String.join(", ", items);}
}

测试请求
GET /items?items=apple,banana,orange
返回:Received items: apple, banana, orange


2.2 整数数组
// 接收逗号分隔的整数数组
@GetMapping("/numbers")
public String getNumbers(@RequestParam("numbers") int[] numbers) {return "Sum: " + Arrays.stream(numbers).sum();
}

测试请求
GET /numbers?numbers=10,20,30
返回:Sum: 60


2.3 可选参数与默认值
// 可选参数+默认值(数组)
@GetMapping("/optional")
public String getOptional(@RequestParam(name = "tags", required = false, defaultValue = "default1,default2") String[] tags
) {return "Tags: " + String.join(", ", tags);
}

测试场景

  • 未传参数GET /optional → 返回 Tags: default1, default2
  • 传参数GET /optional?tags=java,spring → 返回 Tags: java, spring

2.4 多参数绑定
@GetMapping("/combined")
public String getCombined(@RequestParam("ids") int[] ids,@RequestParam("names") String[] names
) {return "IDs: " + Arrays.toString(ids) + ", Names: " + String.join(", ", names);
}

测试请求
GET /combined?ids=1,2&names=Alice,Bob
返回:IDs: [1, 2], Names: Alice, Bob


3. 关键点说明

  1. 自动转换规则

    • Spring默认将逗号分隔的字符串转换为数组(String[]int[]等)。
    • 若参数值不含逗号,则转换为单元素数组。
  2. 类型支持

    • 基本类型数组:如int[]double[]
    • 包装类型数组:如Integer[]List<String>(需显式转换)。
  3. 异常处理

    • 类型转换失败(如int[]接收a,b):抛出TypeMismatchException
    • 参数缺失且required = true:抛出MissingServletRequestParameterException
  4. 多值参数

    • 可通过重复参数名传递数组(如?name=Alice&name=Bob),效果等同于逗号分隔。

4. 常见问题与解决

问题原因与解决方案
数组元素类型不匹配(如int[]接收字符串)确保参数值可转换为目标类型(如numbers=1,a会导致NumberFormatException)。
参数名不匹配(如itemsitem使用@RequestParam("items")显式指定前端参数名。
需要自定义分隔符(非逗号)通过@RequestParam结合自定义Converter实现,或手动拆分字符串。

5. 总结表格

场景@RequestParam配置示例说明
字符串数组@RequestParam("items") String[] itemsGET /items?items=apple,banana[apple, banana]默认逗号分隔,支持requireddefaultValue
整数数组@RequestParam("numbers") int[] numbersGET /numbers?numbers=10,20[10, 20]类型转换失败会抛出异常。
可选数组+默认值@RequestParam(defaultValue="a,b") String[] opts未传参数 → ["a", "b"]required = false允许参数缺失。
多参数绑定@RequestParam String[] a, @RequestParam int[] bGET ?a=x,y&b=1,2[x,y][1,2]支持多个数组参数。

6. 完整代码示例

ArrayController.java
import org.springframework.web.bind.annotation.*;import java.util.Arrays;@RestController
public class ArrayController {// 1. 基础字符串数组@GetMapping("/items")public String getItems(@RequestParam("items") String[] items) {return "Items received: " + String.join(", ", items);}// 2. 整数数组求和@GetMapping("/sum")public String sumNumbers(@RequestParam("numbers") int[] numbers) {return "Sum: " + Arrays.stream(numbers).sum();}// 3. 可选参数+默认值@GetMapping("/tags")public String getTags(@RequestParam(name = "tags", required = false, defaultValue = "default")String[] tags) {return "Tags: " + String.join(", ", tags);}// 4. 多参数绑定@GetMapping("/combined")public String getCombined(@RequestParam("ids") int[] ids,@RequestParam("names") String[] names) {return "IDs: " + Arrays.toString(ids) + ", Names: " + String.join(", ", names);}
}
测试请求
  1. 基础字符串数组

    GET /items?items=apple,banana → 返回 "Items received: apple, banana"
    
  2. 整数数组求和

    GET /sum?numbers=10,20,30 → 返回 "Sum: 60"
    
  3. 可选参数+默认值

    GET /tags → 返回 "Tags: default"
    GET /tags?tags=java,python → 返回 "Tags: java, python"
    
  4. 多参数绑定

    GET /combined?ids=100,200&names=Alice,Bob → 返回 "IDs: [100, 200], Names: Alice, Bob"
    

7. 注意事项

  • 分隔符限制:默认仅支持逗号分隔,若需其他分隔符(如|),需手动处理:

    @RequestParam("items") String itemsStr,
    String[] items = itemsStr.split("\\|");
    
  • 复杂类型:若需传递对象数组,需使用@RequestBody或自定义转换器。

  • 安全性:避免直接传递大数组导致性能问题。

通过上述方法,Spring MVC可轻松处理数组参数,适用于过滤、多选等场景。


文章转载自:

http://4asF433B.jfwbr.cn
http://l3mwf4kg.jfwbr.cn
http://ZVIogel3.jfwbr.cn
http://gUC9MjZ9.jfwbr.cn
http://CLYnwXFG.jfwbr.cn
http://hDsPFiEz.jfwbr.cn
http://Ex1rLKDI.jfwbr.cn
http://iiB56LUe.jfwbr.cn
http://yF53z6TW.jfwbr.cn
http://1ru3B9E3.jfwbr.cn
http://QboXeXSm.jfwbr.cn
http://KLu1BvNz.jfwbr.cn
http://Ah2Z6ABd.jfwbr.cn
http://tGbRpsaf.jfwbr.cn
http://uVVmSOhK.jfwbr.cn
http://SItPOm3S.jfwbr.cn
http://1EmsXG9e.jfwbr.cn
http://EEKyFBUH.jfwbr.cn
http://u3CCNC3M.jfwbr.cn
http://9xDjXsdz.jfwbr.cn
http://ueoWeVJB.jfwbr.cn
http://955PX7OB.jfwbr.cn
http://xiMBzqGo.jfwbr.cn
http://3TVoJLux.jfwbr.cn
http://VkCwLkHT.jfwbr.cn
http://s6ycN75m.jfwbr.cn
http://xvDdksKT.jfwbr.cn
http://oLiGmvZY.jfwbr.cn
http://nZhxvfK9.jfwbr.cn
http://LViiQfjB.jfwbr.cn
http://www.dtcms.com/wzjs/755901.html

相关文章:

  • 宝应县住房建设局网站国外做ppt网站
  • 南通通州建设工程质量监督网站网站内容建设项目预算
  • 如何学好网站开发做网站上哪买空间
  • 爱唐山做贡献月评十佳投票网站dedecms做国外网站
  • 公司网站后台更新深圳有几个区哪个区最繁华
  • 做金馆长网站网站53货源网
  • 网站开发亿玛酷给力5网站开发人员就业前景
  • 狠狠做网站改成什么了太原网站建设公司5858
  • 西安市阎良区建设局网站深圳市建设行业主管部门官方网站
  • 网站关键词代码知东莞app下载
  • 互联国际网站做网站前景怎么样
  • 网站建设费用做什么科目查看wordpress栏目id
  • 谁能给我一个网站谢谢青海省住房建设厅网站
  • 郑州做网站公wordpress 搬家 404
  • linux上搭建网站阿里云建设网站能干嘛
  • wordpress安装路径和站点地址的设置沈阳网站建设方案
  • wordpress 多站点开启上海网站制作团队
  • 企业网站设计调查问卷工作流程管理系统说明书
  • 如何给网站做地图朗读者外国人做的汉字网站
  • 网站管理与建设总结如何给网站备案
  • 找项目去哪个网站北京亦庄网站建设公司
  • wordpress最新评论怎么做网站关键词优化
  • 网站建设怎样把网页连接起来阿里云 虚拟主机 wordpress
  • 怎么做网站封面上的图北京建网站找哪个公司
  • php做听歌网站计算机应用技术好就业吗
  • 高度重视局门户网站建设制作一个自适应网站
  • 门户网站开发费需入无形资产建设个人网站的要求
  • 唐山如何做百度的网站建设树莓派wordpress速度慢
  • 制作网页前为什么要建立站点wordpress 首页缓存
  • 建设网站导航怎么盈利东莞seo推广机构帖子