【发布时间】:2019-03-21 15:24:54
【问题描述】:
大家好,我是 Spring Boot 新手。我被困在我的学习道路中间。我有两个控制器(@Controller),其中定义了一些方法。我正在将表单数据提交到索引控制器中的方法,并且如果表单提交成功(成功登录),则希望移动到主控制器中的方法。在加载索引控制器的http://localhost:9090/method 时,它会正确加载所有静态内容,但是当我重定向return "redirect:/dashboard/index" 时,它会导航到http://localhost:9090/dashBoard/index。而/dashboard/index方法如下
@Controller
public class HomeController {
@GetMapping(value = "/dashBoard/index")
public String hello(Model model, @RequestParam(value = "name", required = false, defaultValue = "World") String name) {
model.addAttribute("name", name);
return "index";
}
}
此方法返回“索引”,即.jsp 页面,但重定向到此方法会更改静态内容路径,例如http://localhost:9090/dashBoard/assets/images/avatar/1.jpg
似乎在静态内容的路径中附加/dashBoard/。我不明白该怎么做,请帮忙。我正在添加我的项目属性和结构,请查看
application.properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.resources.static-locations=file:/var/www/static,classpath:static
spring.mvc.static-path-pattern=/resources/**
server.port=9090
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57InnoDBDialect
spring.jackson.serialization.fail-on-empty-beans=false
main class
[@SpringBootApplication
@EnableAutoConfiguration
public class SchoolpageApplication extends SpringBootServletInitializer {
public static void main(String\[\] args) {
SpringApplication.run(SchoolpageApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SchoolpageApplication.class);
}
}
【问题讨论】:
标签: spring-boot