我正在尝试用spring-boot来解析一个简单的index.html文件。如果我输入localhost:8080/index.html,它就会解析,否则我会得到白色错误页。
我把它发布在GIT上;这是一个非常简单的应用程序:Git Hub Link
问题似乎出在模型上:
表单模型:
@Entity
@Table(name="applicant")
public class FormModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
@Email
private String email;
@Size(min=2, max=200)
private String description;
public String getName() {
return name;
}
@Required
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
@Required
public void setEmail(String email) {
this.email = email;
}
public String getDescription() {
return description;
}
@Required
public void setDescription(String description) {
this.description = description;
}
}
家庭控制器:
@RestController
public class Home {
@RequestMapping(value = "/", method = {RequestMethod.GET, RequestMethod.POST} )
public ModelAndView index(){
ModelAndView modelAndView = new ModelAndView("/index.html");
return modelAndView;
}
}
发布于 2017-09-25 09:28:23
在看了源代码之后
您的标题问题的答案是:
index
,但不能解析/index.html
。来自Thymeleaf的TemplateResolver负责加载HTML标记。默认情况下,它将模板名称(如index
)转换为资源名称(如classpath:/templates/index.html
或WEB-INF/templates/index.html
)。像这样的东西应该是有效的:
ModelAndView modelAndView = new ModelAndView("index");
但它不会为您解决太多问题,因为您还有其他几件事要做
@
$
,看看html实际上使用的是xml格式,所以你不能只使用你的html并在里面添加一些胸腺叶的形式。您需要为每个<hr/>
、<br/>
等添加结束标记。../static/js/some.js
这样的超文本链接,但是你应该使用/js/some.js
来获取更多信息你可以使用如何解析静态文件吗
以下是一些修复后的存储库:https://github.com/varren/Portfolio
https://stackoverflow.com/questions/46396205
复制相似问题