springboot新的開發模式:css
1.jpa持久化規範,hibernate是具體的持久化實現。html
2.orm對象關係映射,經過orm將內存中的數據持久化到數據庫或者磁盤中永久保存。java
3.jsp配置注意事項,需創建war項目,同時引入servlet,jstl,tomcat配置等,配置springMVC前綴,後綴,編寫control。不建議使用jsp。mysql
4.推薦使用thymelefe模板引擎技術事項jsp的功能,自帶相似於jstl標籤的功能。web
5.文件夾解析:src/main/java/---java代碼包括,entity,dao,service,controller基本的3層結構,另外能夠增長數據邏輯處理層做爲4層結構。在各層的外部添加啓動服務application添加 @SpringBootConfiguration註解spring
src/main/resource---資源文件,主要包括public,static,templates(放html模板),resource,application.properties。springboot啓動原理:經過註解映射查找application啓動,而後依次掃描/META-INF/resources,/resources,/static,/public。通常模式將js,css放於static下,html放於templates下sql
注意:@RestController = @Controller + @ResponseBody,返回string或者json格式數據用@RestController數據庫
頁面跳轉用:@Controllerapache
返回json,string格式數據用:@ResponseBodyjson
6.pom.xml
<!-- 繼承父包,springboot會自動爲下面的配置選擇合適的版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath></relativePath>
</parent>
<!-- 配置編碼以及JDK版本-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<!-- spring-boot配置依賴 -->
<dependencies>
<!-- spring-boot的啓動 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- spring-boot的web服務-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring-boot的測試 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--thymeleaf模板jar,是很不錯的html數據傳遞取值,相似jsp的jstl-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- spring-boot的JPA依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--mysql驅動-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>provided</scope> <optional>true</optional> </dependency>
</dependencies>
<!--maven的插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<!--配置中央庫-->
<repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
7.application.properties
#================SERVER CONFIGURATION (ServerProperties)=================#
server.port=8080
server.address=127.0.0.1
#server.session-timeout=3600 # session timeout in seconds
#server.context-parameters.*= # Servlet context init parameters, e.g.server.context-parameters.a=alpha
#server.context-path= # the context path, defaults to '/'
#server.servlet-path= # the servlet path, defaults to '/'
#================hibernate Config=================#
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#================jpa mapping=================#
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
#================sringMVC Config=================#
#http.mappers.json-pretty-print=false # pretty print JSON
#http.mappers.json-sort-keys=false # sort keys
#spring.mvc.locale= # set fixed locale, e.g. en_UK
#spring.mvc.date-format= # set fixed date format, e.g. dd/MM/yyyy
#spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE
#spring.view.prefix=/WEB-INF/
#spring.view.suffix=.jsp
#spring.resources.cache-period= # cache timeouts in headers sent to browser
#spring.resources.add-mappings=true # if default mappings should be added
#================THYMELEAF (ThymeleafAutoConfiguration) =================#
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
#spring.thymeleaf.cache=true # set to false for hot refresh
#================LOGGING=================#
#logging.path=/logs
#logging.file=logging.log
#logging.config= # location of config file (default classpath:logback.xmlfor logback)
#logging.level.*= # levels for loggers, e.g."logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN,ERROR, FATAL, OFF)