Vor kurzem habe ich Spring Boot gelernt. Das Erlernen eines Frameworks ist nichts anderes als zu verwenden, um das zu tun, was ich zuvor getan habe. Die beiden sind unterschiedlich. Lassen Sie mich Ihnen sagen, was ich mithilfe erlebt habe.
Sprechen wir zuerst über Spring Boot, Mikroframework. Die schnelle Entwicklung entspricht der Nullkonfiguration. Aus Sicht eines Meisters: Spring Boot entspricht einem Rahmen des Frameworks, das viele Integrationen entspricht. Fügen Sie einfach die Abhängigkeiten hinzu, zu denen man ausreicht. Auf diese Weise werden Sie die Konfiguration nicht selbst sehen. Für Entwickler, die es gewohnt sind, Konfigurationen zu verwenden, sind sie möglicherweise immer noch ein wenig unbekannt mit den Entwicklern, die gerade Spring Boot verwendet haben. Sie müssen nichts anpassen. Sie sehen die Konfiguration nicht. Ich fühle mich mit der allgemeinen Architektur des Projekts ein wenig nicht vertraut. Außerdem mit Thymeleaf im Springstiefel. Nehmen wir das einfachste Beispiel, um zu veranschaulichen, dass JSP HelloWorld zeigt, Thymeleaf zeigt HelloWorld. Die beiden unterscheiden sich von der Konfiguration der POM -Dateieinführungsabhängigkeiten und Attributdateien. Wenn Sie JSP verwenden, führen Sie die Abhängigkeiten von Thymeleaf nicht ein. Führen Sie natürlich keine JSP -Abhängigkeiten ein, wenn Sie Thymeleaf verwenden. Es kann Konflikte verursachen. Spring Boot Official empfiehlt die Verwendung von Thymeleaf. Ich persönlich fühle, dass es gut ist, lass uns das Projekt starten!
1. Erstellen Sie zuerst ein Meaven -Projekt und sehen Sie die Gesamtstruktur des gebauten Projekts an
Erstellen Sie eine Projektstruktur und verwenden Sie pom.xml. Diese Demo verwendet nur Thymeleaf. Es sind keine Datenbankabhängigkeiten und es sind nur wenige Abhängigkeiten erforderlich.
<project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Springboot_bootstrap</groupId> <artifactId>Springboot_bootstrap</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <gruppe> org.springframework.boot </Groupid> <artifactId> Spring-Boot-Starter-Parent </artifactId> <version> 1.4.7.Release </Version> <RelativePath/> <!-SOOKUP-Elternteil aus der Repository-> </parent> <Propions> <project.build.sourceencoding> utf-8 </project.build.SourceCoding> <projekts <Supructid> org.springFramework.boot </GroupId> <artifactId> Spring-Boot-Starter </artifactId> </abhängig> <abhängig> <gruppe> org.springFramework <gruppeId> org.springframework.boot </GroupId> <artifactId> Spring-Boot-Starter-thymeleaf </artifactID> </abhängig> </abhängig> <build> <PLUGINS> <CROUPSID> org.springFramework </plugins> </build> </project>
Erstellen Sie die Datei application.Properties in SRC /Main /Ressource
server.port = 8080 server.Session.timeout = 10 server.tomcat.uri-coding = utf-8 Spring.Thymeleaf.prefix = classPath:/ views/ fing.thymeleaf.suffix = .html Spring.Thymeleaf.mode = html5 Spring.Thymeleaf.encoding = utf-8. Spring.Thymeleaf.content-type = text/html Spring.Thymeleaf.cache = false
Portprogramm schreiben
Paket com.zanghan.youyu; import org.springframework.boot.springApplication; import org.springframework.boot.autoconfigure.springbootApplication; @SpringbootApplication public class yoyuApplication {public static void main (String [] args) {Springapplication.run (yoyuApplication.class, args); }} Controller Jump Bootstrap -Schnittstelle
Paket com.zanghan.youyu.controller; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class logincontroller {@RequestMapping ("/") public String index () {return "/index"; }}Wo kann man Bootstrap JS CSS einführen? Setzen Sie es in den statischen Ordner, die Seite ist in den Ansichten platziert
Die Interface index.html wird im Ordner Ansicht unter SRC/Main/Ressource gespeichert. Warum ist es keine Tepmates? Da der Inhalt in der Eigenschaftskonfigurationsdatei mit Ansichten geschrieben ist, können das Präfix und das Suffix von Thymeleaf geändert werden.
<! DocType html> <html xmlns = "http://www.w3.org/1999/xhtml" xmlns: th = "http://www.thymeleaf.org" xmlns: sec = "http://www.thymeleaf.org/thymeleaf-extras-splingsecurity3"> <head> <meta charset = "utf-8"/> <meta http-achh. Initial-Scale = 1 "/> <title> MES-Plattform </title> <!-bootstrap-> <link th: href ="@{bootstrap/bootstrap/css/bootstrap.min.css} "rel =" styleSheet "/> <! th: href = "@{bootstrap/font-awesome/css/font-awesome.min th:href="@{Bootstrap/sidebar-menu/sidebar-menu.css}" rel="stylesheet" /> <link th:href="@{Bootstrap/ace/css/ace-rtl.min.css}" rel="stylesheet" /> <link th: href = "@{bootstrap/ace/css/ace-skins.min.css}" rel = "styleSheet"/> <script th: src = "@{bootstrap/jquery.9.min.js}" th: src = "@{bootstrap/bootstrap/js/bootstrap.min.js}"> </script> <script th: src = "@{Bootstrap/SideBar-Menu/SideBar-Menu.js}"> </script> <script> <script> < th: src = "@{bootstrap/bootstrap/js/bootstrap-tab.js}"> </script> <!-[wenn lt ie 9]> <script src = "/scripts/html5shiv.js"> </script Src = "/scripts/reagieren Typ = "text/css"> Körper {Schriftgröße: 12px; } .nav> li> {padding: 5px 10px; } .tab-content {padding-top: 3px; } </style> </head> <body> <div id = "navbar"> <ul> <a id = "Menü-Toggler" href = "#"> <i style = "font-size: 20px; margin-links: -18px; margin-top: 8px; Display: small; ; <a href="#"> <i></i> Settings</a> </li> <li> <a href="#"> <i></i> Profile</a> </li> <li></li> <li> <a href="/Home/Logout"> <i></i> Exit</a> </li> </ul> </li> </li> </li> </ul> </div> </div> <div id = "main-container"> <div> <div id = "SideBar"> <div id = "SideBar"> <div id = "Sidebar-Collapse" style = "display: keine;"> <i data-icon1 = "icon-double-lftle" ^ data-icon2 = "icon-dougle"> </icon2 = "icon-dougle"> <> </icon2 = "icon-dougle"> <-/icon2 = "icon-dougle"> <- id = "Menü"> </ul> </div> <div> <div> <div> <div> <div> <divly = "padding-linft: 5px;"> <ul rollen = "bablist"> <li> <a href = "#index" rollen = "tab" data-toggle = "tab. rollen = "tabpanel" id = "index" style = "Höhe: 100%"> <h2> Willkommen im Backend-Management-System </H2> </div> </div> </div> </div> </div> </div> </div> <script type = "text/javaScript"> //toastr.options.PositionClassClass = 'toastbottom-right'; $ (function () {$ ('#Menü). icon: 'icon-glass', url: '', menus: [{ id: '2', text: 'Coding Management 1', icon: 'icon-glass', url: '', }, { id: '3', text: 'Coding Management 2', icon: 'icon-glass', url: '', },{ id: '4', text: 'Coding Management 3', icon: 'icon-glass', url: '',}]}]}]}]}]}); $ (Kinder) .Removeclass ("Icon-Double-Angle-Links"). $ (Kinder) .Removeclass ("Icon-Double-Angle-Right"). </script> <script th: src = "@{bootstrap/ace/js/ace-extra.min.js}"> </script> <script th: src = "@{bootstrap/ace/js/ace.min.js}"> </script> </body> </html>Erledigen Sie es, führen Sie die Bewerbung aus und geben Sie LOCALHOST ein: 8080
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.