对于我的Spring启动和maven项目,我需要自定义静态资源文件夹结构。
通常,index.html位于 src / main / webapp
位置即。
Project
|
src
|
main
|
webapp
|
index.html
我需要它像
Project
|
src
| |
| main
| |
| webapp
|
index.html
即。我需要将Index.html直接放在项目文件夹
下有没有办法实现它?
答案 0 :(得分:0)
尝试创建此bean并指向您在任何地方创建的index.html
[HttpPost]
public async void Post([FromForm]Student student)
{
var form = Request.Form;
var insideStudent = _dbContext.Students.FirstOrDefault(cus => cus.Id == student.Id);
if (insideStudent != null)
{
insideStudent.FirstName = student.FirstName;
insideStudent.LastName = student.LastName;
_dbContext.SaveChanges();
}
else
{
var newStudent = new Student
{
FirstName = student.FirstName,
LastName = student.LastName
};
if(form.Files.Any())
{
using (var stream = new MemoryStream())
{
await form.Files[0].CopyToAsync(stream);
newStudent.Avatar = stream.ToArray();
}
}
_dbContext.Students.Add(newStudent);
_dbContext.SaveChanges();
}
}
然后您将了解如何将index.html作为默认页面
@Bean
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("path to file");
viewResolver.setSuffix(".html");
return viewResolver;
}
我希望我的回答可以帮助你