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 Spring-eleaf缩短url(form-get)参数_Java_Spring_Thymeleaf - Fatal编程技术网

Java Spring-eleaf缩短url(form-get)参数

Java Spring-eleaf缩短url(form-get)参数,java,spring,thymeleaf,Java,Spring,Thymeleaf,当前状态: 所需状态: ?q=dasda&atn=s&fst=ANY 使用q代替查询,使用fst代替filterSoftwareType缩短url 我的My thymeleaf html如下所示,简短示例: <form action="#" class="card card-sm rounded" method="get" th:action="@{${T(com.bisciak.workaround.util.Ut

当前状态:

所需状态: ?q=dasda&atn=s&fst=ANY

使用q代替查询,使用fst代替filterSoftwareType缩短url

我的My thymeleaf html如下所示,简短示例:

<form action="#" class="card card-sm rounded"
                  method="get"
                  th:action="@{${T(com.bisciak.workaround.util.Utils).MAPPING_INDEX}}" th:object="${search}">

     <div class="col">
           <input class="form-control form-control-lg form-control-borderless"
                               placeholder="Search here"
                               style="padding-left: 1rem"
                               th:field="${search.query}" type="search"/>
     </div> etc...
控制器

  @GetMapping(value = Utils.MAPPING_INDEX, params = "atn=s")
 public ModelAndView indexActionSearch(@ModelAttribute(name = "s") Optional<Search> search .....
@GetMapping(value=Utils.MAPPING_INDEX,params=“atn=s”)
public ModelAndView indexActionSearch(@ModelAttribute(name=“s”)可选搜索。。。。。
搜索对象有一些属性,比如查询等等,但是我肯定不想重命名它们!通过代码命名会很糟糕,我只想对URL使用短版本

有人知道怎么做吗?我在输入框上尝试了name属性,但没有用:/。

我还想在表单中保留内容,以便自动生成url。
我还想将其保留为get,而不是post,这样用户就可以通过URL栏上的复制粘贴等轻松共享此链接。使用post,他将看不到这一点。

th:field属性可以轻松地从Java对象构建表单,并且对于要使用相同名称发回的字段,可以将值自动分配回Java对象,当然他是同一类型的,在服务器上

如果您想要不同的名称,那么您没有将其用于预期目的,所以请停止使用它

如果您查看文档,即章节,您会看到
th:fields
的作用:

现在让我们看看如何向表单中添加输入:


…在这种情况下(
input[type=text]
),上面的代码行类似于:


因此,请更改代码以执行此操作:


您是否还需要
id=“q”
取决于您


请注意,如果您使用
th:value=“${search.query}”
,那么就不需要
th:object=“${search}”

该死,它完全按照您所说的那样工作。谢谢,这解决了我的问题!