Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring mvc 百里香不';t对使用数据字段的输入使用格式化程序_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Spring mvc 百里香不';t对使用数据字段的输入使用格式化程序

Spring mvc 百里香不';t对使用数据字段的输入使用格式化程序,spring-mvc,spring-boot,thymeleaf,Spring Mvc,Spring Boot,Thymeleaf,我发现在Spring引导应用程序中使用Thymeleaf存在问题 版本: 弹簧靴1.3.4和1.3.3 我的实体: @Entity public class MyEntity { @Id @GeneratedValue private Long id; @Version private int version; @DateTimeFormat(pattern="dd/MM/yyyy") private Calendar calendar; @DateT

我发现在Spring引导应用程序中使用Thymeleaf存在问题

版本:

  • 弹簧靴1.3.4和1.3.3
我的实体:

@Entity
public class MyEntity {

  @Id
  @GeneratedValue
  private Long id;

  @Version
  private int version;

  @DateTimeFormat(pattern="dd/MM/yyyy")
  private Calendar calendar;

  @DateTimeFormat(pattern="dd/MM/yy")
  private Date date;

  @NumberFormat(pattern="#0.00000")
  private Double aDouble;

}
我的控制器:

@RequestMapping(value = "/{myEntity}/edit-form", 
     method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@PathVariable MyEntity myEntity, Model model)  {
    return "myEntity/edit";
}
myEntity/edit.html模板:

    <form class="form-horizontal" method="POST"
      data-th-object="${myEntity}"
      data-th-action="@{/myEntity/{id}(id=*{id})}">
      <input type="hidden" name="_method" value="PUT" />

      <div class="form-group"
        data-th-classappend="${#fields.hasErrors('calendar')}? 'has-error has-feedback'">
        <label for="calendar" class="col-md-3 control-label">Calendar</label>
        <div class="col-md-3">
          <input type="text" class="form-control"
            data-th-field="*{calendar}"/>
          <span data-th-text="*{{calendar}}"></span>
        </div>
      </div>

      <div class="form-group"
        data-th-classappend="${#fields.hasErrors('date')}? 'has-error has-feedback'">
        <label for="date" class="col-md-3 control-label">Date</label>
        <div class="col-md-3">
          <input type="text" class="form-control"
            data-th-field="*{date}"/>
          <span data-th-text="*{{date}}"></span>
        </div>
      </div>

      <div class="form-group"
        data-th-classappend="${#fields.hasErrors('aDouble')}? 'has-error has-feedback'">
        <label for="date" class="col-md-3 control-label">aDouble</label>
        <div class="col-md-3">
          <input type="text" class="form-control"
            data-th-field="*{{aDouble}}"/>
          <span data-th-text="*{{aDouble}}"></span>
        </div>
      </div>

      <div class="form-group">
        <div class="col-md-12">
          <div class="pull-right">
            <button type="submit" class="btn btn-primary">Update</button>
          </div>
        </div>
      </div>
    </form>

历法
日期
最大元素
更新
当我尝试显示此页面时,我得到:


历法
01/01/2016
日期
01/02/16
最大元素
0.10000
更新
对于我使用的日期:

${#dates.format(date, 'dd/MMM/yyyy HH:mm')}
至于数字:

${#numbers.formatDecimal(num,3,2,'COMMA')}
在文档中解释了我使用的日期和。

${#dates.format(date, 'dd/MMM/yyyy HH:mm')}
至于数字:

${#numbers.formatDecimal(num,3,2,'COMMA')}

在文档中对和进行了解释。

已解决。问题出现在requestMapping定义中:

@RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET, 
               produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@PathVariable MyEntity myEntity, Model model) {

    }
需要请求上下文中的
BindingResult
来获取可以将对象值转换为字符串的
PropertyEditor
。因此,在请求映射定义中包括
BindingResult
,所有工作都按预期进行:

@RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET, 
               produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@ModelAttribute MyEntity myEntity, BindingResult result, 
               Model model) {

    }
请注意,必须使用
@modeldattribute
注释对象,并且必须在
@modeldattribute
之后声明


感谢所有试图帮助我的人。

问题解决了。问题出现在requestMapping定义中:

@RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET, 
               produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@PathVariable MyEntity myEntity, Model model) {

    }
需要请求上下文中的
BindingResult
来获取可以将对象值转换为字符串的
PropertyEditor
。因此,在请求映射定义中包括
BindingResult
,所有工作都按预期进行:

@RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET, 
               produces = MediaType.TEXT_HTML_VALUE)
public String editForm(@ModelAttribute MyEntity myEntity, BindingResult result, 
               Model model) {

    }
请注意,必须使用
@modeldattribute
注释对象,并且必须在
@modeldattribute
之后声明


感谢所有试图帮助我的人。

在输入中也使用双括号怎么样。根据,这可能会起作用。我尝试了,但没有任何改变(请参阅double的输入:
data th field=“*{{aDouble}}”
)。谢谢。在输入中也使用双括号怎么样。根据,这可能会起作用。我尝试了,但没有任何改变(请参阅double的输入:
data th field=“*{{aDouble}}”
)。谢谢,这不是一个解决办法。格式应该只在一个地方声明,以确保SpringMVC绑定能够正确处理它。这不是一个解决方案。格式应该只在一个地方声明,以确保SpringMVC绑定能够正确处理它。