Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 捕捉映射中的GET请求参数<;字符串,字符串>;_Java_Spring_Spring Mvc - Fatal编程技术网

Java 捕捉映射中的GET请求参数<;字符串,字符串>;

Java 捕捉映射中的GET请求参数<;字符串,字符串>;,java,spring,spring-mvc,Java,Spring,Spring Mvc,我试图在SpringMVC端捕捉映射参数中的键值对。在我看来,这很简单,但我现在还不能完全理解。获取以下url www.goudengids.be.localhost:8080/ms/view/sendContactForm.ajah?pageId=711408&listingId=685592&siteId=353009&url=http%3A%2F%2Fwww.goudengids.be.localhost%3A8080%2Fms%2Fms%2Fkbc-bank-ve

我试图在SpringMVC端捕捉映射参数中的键值对。在我看来,这很简单,但我现在还不能完全理解。获取以下url

www.goudengids.be.localhost:8080/ms/view/sendContactForm.ajah?pageId=711408&listingId=685592&siteId=353009&url=http%3A%2F%2Fwww.goudengids.be.localhost%3A8080%2Fms%2Fms%2Fkbc-bank-versicherung-recht-4780%2Fms-353009-preview%2F&moduleId=65920100&mySiteId=353009&pageShortId=1&prefills[Naam]=janneke
最后你会注意到我最近一次尝试得到这个工作前缀[Naam]=janneke。我想在下面的控制器中捕捉到这一点

public String getContactForm(@RequestParam(required = true) Long moduleId, @RequestParam(required = true) String url, @RequestParam(required=false) Map<String,String> prefills, Long mySiteId, Integer pageShortId,
      DefaultPageParameters defaultPageParameters, ModelMap model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {

我找不到一条干净的出路,所以我选择了务实的解决方案

  public String getContactForm(@RequestParam(required = true) Long moduleId, @RequestParam(required = true) String url, @RequestParam(required=false) List<String> prefills, Long mySiteId, Integer pageShortId,
      DefaultPageParameters defaultPageParameters, ModelMap model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {


  private void prefillFieldsWithData(List<String> prefills, ModelMap model, BasicContactFormVo contactFormVo) {
    if(prefills != null && !prefills.isEmpty()){
      Map<String, String> valuesOfCustomFields = new HashMap<String, String>();
      List<ContactFormElementVo> customFormElements = contactFormVo.getCustomFormElements();
      for (String prefillData : prefills) {
        if(prefillData.contains("|")){
          String[] prefillFieldData = prefillData.split("|");
          for (ContactFormElementVo contactFormElementVo : customFormElements) {
            if(contactFormElementVo.getLabel().equals(prefillFieldData[0])){
              valuesOfCustomFields.put("cfe"+contactFormElementVo.getId().toString(), prefillFieldData[1]);
              break;
            }
          }                    
        }
      }
      model.addAttribute("customFieldValues",valuesOfCustomFields);
    }
  }

我认为典型的方法是对每个“prefill”值使用不同的可选的
@RequestParam
。如果我们有固定的值,这会起作用,但在本例中,我们讨论的是不知道可以有多少prefill字段的情况。一个表单只能有两个字段,另一个表单可以有数千个字段(有一些限制)。但是我不能在controllerI中硬编码x变量,我看不到示例请求中的
title
subject
参数。他们从哪里来?啊,从另一个例子看来,他们从哪里来。故事的重点是,这些领域可以是任何东西。此功能处理用户可以为其网站创建的自定义表单。他们可以称之为任何名称,但有时如果他们打开表单,您需要预先填充字段,例如共享一张图片,然后他们单击图片,表单将打开一个带有图片url的图片字段
  public String getContactForm(@RequestParam(required = true) Long moduleId, @RequestParam(required = true) String url, @RequestParam(required=false) List<String> prefills, Long mySiteId, Integer pageShortId,
      DefaultPageParameters defaultPageParameters, ModelMap model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {


  private void prefillFieldsWithData(List<String> prefills, ModelMap model, BasicContactFormVo contactFormVo) {
    if(prefills != null && !prefills.isEmpty()){
      Map<String, String> valuesOfCustomFields = new HashMap<String, String>();
      List<ContactFormElementVo> customFormElements = contactFormVo.getCustomFormElements();
      for (String prefillData : prefills) {
        if(prefillData.contains("|")){
          String[] prefillFieldData = prefillData.split("|");
          for (ContactFormElementVo contactFormElementVo : customFormElements) {
            if(contactFormElementVo.getLabel().equals(prefillFieldData[0])){
              valuesOfCustomFields.put("cfe"+contactFormElementVo.getId().toString(), prefillFieldData[1]);
              break;
            }
          }                    
        }
      }
      model.addAttribute("customFieldValues",valuesOfCustomFields);
    }
  }
http://www.goudengids.be.localhost:8080/ms/view/sendContactForm.ajah?pageId=711408&listingId=685592&siteId=353009&url=http%3A%2F%2Fwww.goudengids.be.localhost%3A8080%2Fms%2Fms%2Fkbc-bank-versicherung-recht-4780%2Fms-353009-preview%2F&moduleId=65920100&mySiteId=353009&pageShortId=1&prefills=Naam|janneke%20zag%20eens%20pruimen&prefills=E-mail|maan