Springboot 页面显示 - Go语言中文社区

Springboot 页面显示


并非是那种传授并分享知识的,只想在个人博客上把自己学的东西记录下来。


上一篇写的是如何创建项目的,这一篇是将IDEA的HTML内容显示在浏览器上。因为一步步学过来,pom.xml中添加的依赖越来越多,已经分不清显示HTML只需要精简到哪些依赖,这里我随便找两个比较简短的pom.xml依赖,就不回去仔细测试哪些是多余的了。另外我后期博客中,包的形式大致是这样的
另外我想说明一下,其实src下的webapp和web.xml是完全没用到的,只是以前习惯把webapp目录创建出来,众看官可以忽略或者不创建webapp

以前用的SSM框架比较多,现在使用Springboot这种轻便的框架还真有点不习惯。
以前是各种插件,各种pom.xml,web.xml依赖

现在基本就只pom.xml,resources下的application.properties为主,甚至dao跟service都简化很多(目前也只是刚学不久,纯属个人愚见)

聊完这些多余的,我们接着进入正题
首先添加pom.xml依赖,上面说了,我只是随意找了个简短的,反正后面都会用到,也不分只要哪些依赖就能实现了

[html] view plain copy
 print?
  1. <span style="font-size:18px;"><strong><!--spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加。-->  
  2.   <parent>  
  3.     <groupId>org.springframework.boot</groupId>  
  4.     <artifactId>spring-boot-starter-parent</artifactId>  
  5.     <version>1.4.0.RELEASE</version>  
  6.   </parent>  
  7.   
  8.   <properties>  
  9.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  10.     <!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->  
  11.     <java.version>1.8</java.version>  
  12.   </properties>  
  13.   
  14.   <dependencies>  
  15.   
  16.     <!--spring-boot-starter-web: MVC,AOP的依赖包....-->  
  17.     <dependency>  
  18.       <groupId>org.springframework.boot</groupId>  
  19.       <artifactId>spring-boot-starter-web</artifactId>  
  20.       <!--<version></version>由于我们在上面指定了 parent(spring boot)-->  
  21.     </dependency>  
  22.   
  23.     <!-- 添加fastjson 依赖包. -->  
  24.     <dependency>  
  25.       <groupId>com.alibaba</groupId>  
  26.       <artifactId>fastjson</artifactId>  
  27.       <version>1.2.15</version>  
  28.     </dependency>  
  29.   
  30.     <!-- 添加MySQL数据库驱动依赖包. -->  
  31.     <dependency>  
  32.       <groupId>mysql</groupId>  
  33.       <artifactId>mysql-connector-java</artifactId>  
  34.     </dependency>  
  35.   
  36.     <!-- 添加Spring-data-jpa依赖. -->  
  37.     <dependency>  
  38.       <groupId>org.springframework.boot</groupId>  
  39.       <artifactId>spring-boot-starter-data-jpa</artifactId>  
  40.     </dependency>  
  41.   
  42.     <!-- 添加thymeleaf的依赖. -->  
  43.     <dependency>  
  44.       <groupId>org.springframework.boot</groupId>  
  45.       <artifactId>spring-boot-starter-thymeleaf</artifactId>  
  46.     </dependency>  
  47.   
  48.   </dependencies></strong></span>  

application.properties文件(这里没用到mysql,我也没去删了)

[html] view plain copy
 print?
  1. <span style="font-size:18px;"><strong>#开发过程建议关闭缓存  
  2. spring.thymeleaf.cache=false  
  3.   
  4. ########################################################  
  5. ###datasource -- 指定mysql数据库连接信息  
  6. ########################################################  
  7. spring.datasource.url = jdbc:mysql://localhost:3306/test  
  8. spring.datasource.username = root  
  9. spring.datasource.password = 123  
  10. spring.datasource.driverClassName = com.mysql.jdbc.Driver  
  11. spring.datasource.max-active=20  
  12. spring.datasource.max-idle=8  
  13. spring.datasource.min-idle=8  
  14. spring.datasource.initial-size=10  
  15.   
  16. ########################################################  
  17. ### Java Persistence Api --  Spring jpa 的配置信息  
  18. ########################################################  
  19. # Specify the DBMS  
  20. spring.jpa.database = MYSQL  
  21. # Show or not log for each sql query  
  22. spring.jpa.show-sql = true  
  23. # Hibernate ddl auto (create, create-drop, update)  
  24. spring.jpa.hibernate.ddl-auto = update  
  25. # Naming strategy  
  26. #[org.hibernate.cfg.ImprovedNamingStrategy  #org.hibernate.cfg.DefaultNamingStrategy]  
  27. spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy  
  28. # stripped before adding them to the entity manager)  
  29. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect  
  30.   
  31. </strong></span>  

启动类:AppLication

[html] view plain copy
 print?
  1. <span style="font-size:18px;"><strong>package com.zking;  
  2.   
  3. import org.springframework.boot.SpringApplication;  
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;  
  5.   
  6. /**  
  7.  * Created by Administrator on 2017/5/5.  
  8.  */  
  9.   
  10. @SpringBootApplication  
  11. public class AppLication {  
  12.     public static void main(String[] args) {  
  13.         SpringApplication.run(AppLication.class, args);  
  14.     }  
  15.   
  16. }  
  17. </strong></span>  

以及controller跟index页面
[html] view plain copy
 print?
  1. <span style="font-size:18px;"><strong>package com.zking.controller;  
  2.   
  3. import org.springframework.stereotype.Controller;  
  4. import org.springframework.web.bind.annotation.RequestMapping;  
  5.   
  6. /**  
  7.  * Created by Administrator on 2017/5/11.  
  8.  */  
  9.   
  10.   
  11. @Controller  
  12. public class IndexController {  
  13.   
  14.     @RequestMapping("/index")  
  15.     public String index() {  
  16.         return "index";  
  17.     }  
  18.   
  19. }  
  20. 版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
    原文链接:https://blog.csdn.net/gebitan505/article/details/78195618
    站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-06-06 09:26:02
  • 阅读 ( 1274 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢