码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot项目结构介绍

时间:2017-07-16 19:19:21      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:pos   enc   soft   mil   artifact   文件夹   width   rest   pre   

  一项目结构介绍

  springboot框架本身对项目结构并没有特别的要求,但是按照最佳的项目结构可以帮助我们减少可能遇到的错误问题。结构如下:

  技术分享

  (1)应用主类SpringbootApplication应该放于根目录下springboot下,通常我们会在主类中做一些框架配置 扫描等配置,SpringbootApplication放在根目录下可以可以帮助程序减少手工配置来加载到我们希望被Spring加载的内容。

  (2)实体(entity)与数据库访问层(Repository)位于domain包下。

  (3)逻辑层位于service包下。

  (4)Web层位于web包下。

  (5)图片文件放于static文件夹下。

  (6)html文件放于templates文件夹下。

  (7)application.properties 文件主要配置一些数据库连接等信息。

  第一篇我们使用RestController(spring4.0新特性)返回一个json(在spring4.0之前我们要返回一个json结果,需要使用@Controller与@ResponseBody配合使用)如果返回值是一个html文件,则需要将html文件放到templates文件夹下。

  在pom.xml文件中引入

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

  代码如下:

  技术分享

SpringBoot项目结构介绍

标签:pos   enc   soft   mil   artifact   文件夹   width   rest   pre   

原文地址:http://www.cnblogs.com/gdpuzxs/p/7191247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!