我需要添加日期到我的实体,让用户设置在web形式。默认情况下,此字段需要填写今天的日期。
1. <input type="date" value="2016-08-01">
显示为默认值设置的正确日期
2. <input type="date" th:value="${startDate}">
显示没有任何值的日期选择器(注意:String startDate=“2016-08-01”;)
3. <input type="date" th:field="${startDate}">
生成400个错误(错误请求)(注意:Date startDate=new Date();)
我的控制器:
@RequestMapping("/project_new")
public String createProject(Model model) {
Project project = new Project ();
List<Role> roles = mRoleService.findAll();
project.setStart(new Date());
model.addAttribute("page_title", "create project");
model.addAttribute("roles", roles);
model.addAttribute("statuses", Status.values());
model.addAttribute("project", project);
return "project_new";
}
@RequestMapping(value = "/project_new", method = RequestMethod.POST)
public String createProject(@ModelAttribute Project project, Model model) {
// Fill id field for project.rolesNeeded
mRoleService.setRolesId(project.getRolesNeeded());
project.fixCollaboratorsAndRoles();
mProjectService.save(project);
return "redirect:/";
}
我的模板:
<form th:action="@{/project_new}" method="post" th:object="${project}">
<div class="project-list single">
<label for="name">Name:</label>
<input type="text" id="name" required="true" th:placeholder="*{name}" th:value="*{name}" th:field="*{name}"/>
<label for="description">Description:</label>
<textarea rows="5" id="description" type="text" required="true" th:placeholder="*{description}" th:value="*{description}" th:field="*{description}"/>
<label for="date-started">Date started:</label>
<input type="date" th:value="${project.start}" th:field="${project.start}" id="date-started"/>
<div>
<label for="project_status">Project Status:</label>
<div class="custom-select">
<span class="dropdown-arrow"></span>
<select th:field="*{status}" id="project_status">
<option th:each="s : ${statuses}" th:value="${s}" th:text="${s}">Active</option>
</select>
</div>
</div>
<div class="roles-collaborators">
<ul class="checkbox-list">
<li th:if="${role.name} ne 'Undefined'" th:each="role : ${roles}">
<input type="checkbox" th:value="${role}" th:field="${project.rolesNeeded}" class="checkbox"/>
<span th:text="${role.name}" th:value="${role}" class="checkbox">Developer</span>
</li>
</ul>
</div>
<div class="actions">
<button type="submit" class="button">Save</button>
<a th:href="@{/}" class="button button-secondary">Cancel</a>
</div>
</div>
</form>
项目实体:
@Entity
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Size (min = 3)
private String name;
@Column(columnDefinition="TEXT")
private String description;
@Column
private Status status;
@Column
private Date start;
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
private List<Role> rolesNeeded;
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
private List<Collaborator> collaborators;
public Date getStart() {
return start;
}
public void setStart(Date start) {
this.start = start;
}
看看带有错误日志的注释,似乎是string
到java.util.date
之间的转换问题。在Thymeleaf GitHub中搜索了一段时间后,我看到了两个问题,可以解释在这种情况下如何进行:
从最后一点开始,我为您的项目类的开始日期添加了一个注释:
// This is "org.springframework.format.annotation.DateTimeFormat"
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date start;
考虑到这一点,您还需要将日期值的th:value
和th:field
属性从${project.start}
更改为*{start}
,正如我在注释中所写的,以及您对name
和description
字段所做的那样。
所以我一直在玩一些数学问题的小游戏。例如,应用程序给出了一个23+47这样的问题,这很好,但当它给出一个9/6这样的问题时,问题就出现了。由于您在EditText中输入了结果,所以我需要正确的输入类型。但是!当我做的时候 它所提供的软键盘,是一个没有分隔符的软键盘,这意味着我不能做逗号。这几乎破坏了比赛:-)我试过像这样的事情 我也试过 但到目前为止还没有工作。 我就是拿不出正确的键盘。 有什么建
当我将输入类型属性设置为数字(Android:输入类型=“数字”)并设置数字属性时,就像这个Android:数字=“0123456789”。输入事件按预期正常工作。即仅以数字形式接收输入。参考屏幕截图 当我将inputType属性设置为text person name(Android:input type = " text person name ")并像这样设置digits属性android:d
function getCarData() { return [ ["Mercedes", "A 160", "01/14/2017", 6999.95], ["Citroen", "C4 Coupe", "12/01/2018", 8330], ["Audi", "A4 Avant", "11/19/2019", 33900], ["Opel", "Astra", "02/02/20
1. Joda Time Joda Time 在很久以前就被认为应该直接收入JDK,因为它吸取了JDK里Date的大量失败教训,如对象应该是不可改的,对字符串与Date类型的转换,时区/Locale的支持,各种日期计算的简便函数等等都不错。 1.1 Joda演示 Joda Time的详细使用见Showcase中的JodaDemo。 1.2 Joda在各种环境中的使用 1.2.1 在Hibernat
Date 方法 返回当天的日期和时间。 语法: Date() 示例: console.log( Date() ); 结果: >>> Fri Sep 06 2013 15:07:31 GMT+0800
描述 (Description) Javascript Date()方法返回今天的日期和时间,不需要调用任何对象。 语法 (Syntax) 其语法如下 - Date() 返回值 (Return Value) 返回今天的日期和时间。 例子 (Example) 请尝试以下示例。 <html> <head> <title>JavaScript Date Method</title>
Date对象是JavaScript语言中内置的数据类型。 使用new Date( )创建日期对象,如下所示。 创建Date对象后,可以使用许多方法对其进行操作。 大多数方法只允许您使用本地时间或UTC(通用或GMT)时间来获取和设置对象的年,月,日,小时,分钟,秒和毫秒字段。 ECMAScript标准要求Date对象能够在1970年1月1日之前或之后的1亿天内以毫秒精度表示任何日期和时间。 这是正
Random.date( format? ) Random.date() Random.date(format) 返回一个随机的日期字符串。 format 可选。 指示生成的日期字符串的格式。默认值为 yyyy-MM-dd。 可选的占位符参考自 Random.time( format? ) Random.time() Random.time( format ) 返回一个随机的时间字符串。 form