java - Spring Boot 未加载正确的模板,无法调试
问题描述
我是 Spring Boot 新手,一直在关注本指南: https ://spring.io/guides/gs/serving-web-content/
控制器看起来像这样:
`package hello;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class GreetingController {
@GetMapping("/greeting")
public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}
}`
因为它返回一个字符串“greeting”,它会寻找greeting.html。不知道怎么做,但我相信因为 Maven 的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
从这一点来看,一切都很好。我可以看到位于 src/main/resources/templates/greeting.html 中的 greeting.html 模板
现在我开始创建新模板并尝试以相同的方式访问它们,似乎一切都失败了。
我接下来所做的是将greeting() 的返回字符串更改为“greeting2”,以确保它确实是映射视图greeting.html 的那个。但奇怪的是在那之后我仍然可以访问greeting.html。
我认为这是缓存问题,所以我清除了浏览器缓存并仍然遇到这种情况。
我什至更改了 Controller 方法返回视图的方式并使用了 ModelAndView 对象,但仍然没有运气。
我迷路了,请帮助。谢谢
另外....我无法调试。尝试在 Application.java 中作为 Java 应用程序调试
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
并在我的控制器处放置断点,它不会进入那些行。
解决方案
推荐阅读
- wordpress - Woocommerce Checkout 页面输入字段显示奇怪
- java - 如何使用 CDI 使单例实例随处可见?
- python - 烧瓶 webapp 中的 404 错误无法找到原因
- wordpress - 以百分比而不是总税值显示税率 - woocommerce
- r - 使用 MODIStsp_extract() 从栅格中提取点
- c++ - 私有 const 成员函数的成员检测
- drools - 在多线程环境中使用 Single KieSession 实例安全吗?
- jquery - 如何防止数据表翻页?
- gatsby - 基于 gatsby starter blog 在 Netlify 上为我的 Gatsby 应用程序部署失败
- powershell - Powershell 命令作为 Ansible 中的变量