1、项目搭建

创建项目并引入相关pom依赖
相关pom文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.2.5.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>cn.ither</groupId>
  12. <artifactId>es-jd</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>es-jd</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. <elasticsearch.version>7.6.1</elasticsearch.version>
  19. </properties>
  20. <dependencies>
  21. <dependency>
  22. <groupId>org.springframework.boot</groupId>
  23. <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-web</artifactId>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-devtools</artifactId>
  36. <scope>runtime</scope>
  37. <optional>true</optional>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.springframework.boot</groupId>
  41. <artifactId>spring-boot-configuration-processor</artifactId>
  42. <optional>true</optional>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.projectlombok</groupId>
  46. <artifactId>lombok</artifactId>
  47. <optional>true</optional>
  48. </dependency>
  49. <dependency>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-starter-test</artifactId>
  52. <scope>test</scope>
  53. <exclusions>
  54. <exclusion>
  55. <groupId>org.junit.vintage</groupId>
  56. <artifactId>junit-vintage-engine</artifactId>
  57. </exclusion>
  58. </exclusions>
  59. </dependency>
  60. </dependencies>
  61. <build>
  62. <plugins>
  63. <plugin>
  64. <groupId>org.springframework.boot</groupId>
  65. <artifactId>spring-boot-maven-plugin</artifactId>
  66. </plugin>
  67. </plugins>
  68. </build>
  69. </project>

2.yml相关配置

  1. server:
  2. port: 8080
  3. #关闭thymeleaf缓存
  4. spring:
  5. thymeleaf:
  6. cache: false

application.properties配置

  1. server.port=9090
  2. #关闭thymeleaf缓存
  3. spring.thymeleaf.cache=false

3.引入静态资源

十一、京东搜索项目实战 - 图1

4.编写控制器访问index.html页面

  1. @Controller
  2. public class IndexController {
  3. @GetMapping("/")
  4. public String idnex(){
  5. return "index";
  6. }
  7. }

访问页面
image.png