1. Windows 7 Enterprise Edition
2. Idee 14
3. JDK 1.8
4. Maven 3.5.2
5. Mariadb
6. Sqlyog
Fügen Sie in das Conf -Verzeichnis im Maven -Verzeichnis den folgenden Inhalt hinzu:
1. Die Verwendung von Alibaba Clouds Repository ist viel schneller als die offizielle Website.
<Mirror> <ID> Nexus-Aliyun </id> <Mirrorof> zentral </mirrorof> <name> nexus aliyun </name> <URL> http://maven.aliyun.com/nexus/content/groups/public </url> </minor>
2. Globale JDK -Konfiguration
<!-Globale JDK-Konfiguration, Settings.xml-> <profile> <ID> JDK18 </id> <ActiveByDefault> TRUE </activeByDefault> <jdk> 1.8 </jdk> </activation> <properties> <maven.compiler.source> 1.8 </maven.compiler.Sources> <maven.compiler.target> 1.8 </maven.compiler.target> <maven.compiler.comPilerversion> 1.8 </maven.compiler.comPilerversion> </properties> </properties> </profile> </profile>
1. Maven -Einstellungen: Wählen Sie das Maven -Verzeichnis und konfigurieren Sie gleichzeitig die Datei und das lokale Repository.
2. Einstellungen für Charaktercodierungseinstellungen
Wählen Sie Auto-Import aktivieren und erstellen Sie das Projektverzeichnis wie unten gezeigt:
1. Pom.xml
<? XSI: Schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion> 4.0.0 </modelversion> </Groupid> cn.temption </Groupid> </Groupid> </Groupid> </Groupid> </Groupid> </Groupid> </Groupid> </artifactInation> studySting> artifption </Groupid> </artifactId> </Groupid> </artifactId> </Groupid> </artifactIntion> </Groupid> </artifactInation> studys <version> 1.0-Snapshot </Version> <!-Standardeinstellungen für die Verwendung von Spring Boot-> <Eltern> <gruppe> org.springFramework <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- MySQL ---> <De vorstellen> <GroupId> Mysql </Groupid> <artifactID> Mysql-connector-Java </artifactid> <version> 5.1.21 </Version> </abhängig> <!-jpa-> <depecing> <gruppe org.springframework.boot </Groupid> </Groupid> <artifactid> Spring-Boot-Starter-Data-jpa </artifactid> </abhängig> </abhängigkeiten> </project>
2. Erstellen Sie eine neue Anwendung.
# Database connection spring.datasource.url=jdbc:mysql://127.0.0.1:3306/testspring.datasource.username=rootspring.datasource.password=saspring.datasource.driver-class-name=com.mysql.jdbc.Driver# JPA configuration spring.jpa.properties.hibernate.hbm2ddl.auto = update
3. Erstellen Sie Springboot -Programm Startup -Klasse SpringbootApplication
Paket cn.temptation; import org.springframework.boot.springapplication; import org.springframework SpringApplication.run (SpringbootApplication.Class, Args); }}
4. Erstellen Sie Entitätsklassenkategorie
Paket cn.temptation.model; importieren javax.persistence. (Null, 'Schuhe'); //////////ex * aus der Kategorie; @entity @table (name = "kategorie") öffentliche Klassenkategorie {@ID @generatedValue (Strategy = GenerationType.Identity) @Column (name = "categoryId") private Integer categoryId; @Column (name = "categoryName") private String categoryName; public Integer getCategoryId () {return categoryId; } public void setCategoryId (Integer categoryId) {this.categoryId = categoryId; } public String getCategoryName () {return categoryName; } public void setCategoryName (String categoryName) {this.categoryName = categoryName; }}5. DAO Interface CategoryDao.java erstellen
Paket cn.temptation.dao; import cn.temptation
6. Erstellen Sie die Controller Class CategoryController.java
Paket cn.temptation.web; import cn.temptation.dao.categorydao; import cn.temptation org. org.springframework.web.bind.annotation.Requestparam; import org.springframework.web.servlet.moDelandView; import Java.util.list; @ControllerPublic Class CategoryController {@autowired private categoryDao CategoryDao; /** * Abfragestelle * * @return * /// @RequestMapping ("/categoryList") // public modelAndView categoryList () {// list <category> list = categoryDao.findall (); ////modellandview mav = new modelandview ("categorylist") mav.addobject ("//// mav.addobject", "// mav.addobject". /** * Pagination Query * * @return */@RequestMapping ("/categoryList") public modelAndview categoryList (@RequestParam (value = "start", defaultValue = "0") Ganze start, @Requestparam (value = "limit", DefaultValue = "2")) Inteteger Limit) {Start = Start <0? 0: Start; Sortieren sort = new sort (sort.default_direction, "categoryId"); Pageable lehbar = neuer pageRequest (Start, Grenz, Sortieren); Seite <Gegategorie> page = categorydao.findall (lehnte); // system.out.println (page.getNumber ()); // system.out.println (page.getNumberoFelements (); // system.out.println (page.getSIZE ()); System.out.println (page.gettotalpages ()); // system.out.println (page.isfirst ()); // system.out.println (page.islast ()); ModelAndView mav = new ModelAndView ("CategoryList"); mav.addObject ("Seite", Seite); MAV zurückgeben; }/*** Neue Ansicht in Kategorie* @return*/@RequestMapping ("/categoryInit") public String categoryInit () {return "categoryInit"; }/** * Neue Operation in Kategorie * @param modell * @return */@RequestMapping ("/categoryInsert") public String categoryInsert (Kategoriemodell) {categoryDao.save (Modell); return "Redirect: CategoryList"; }/** * Kategorie löschen Operation * @param categoryId * @return */@RequestMapping ("/categoryDelete") public String categoryDelete (Integer categoryId) {categoryDao.deletebyId (categoryId); return "Redirect: CategoryList"; }/** * Kategorie -Bearbeitungsansicht * @param categoryId * @Return */@RequestMapping ("/categoryEdit") public modelAndView categoryEdit (Integer categoryId) {category model = categoryDao.getone (categoryId); ModelAndView mav = new ModelAndView ("categoryEdit"); mav.addObject ("Kategorie", Modell); MAV zurückgeben; }/** * Kategorie Bearbeitungsoperation * @param modell * @return */@RequestMapping ("/categoryUpdate") public String categoryUpDate (Kategoriemodell) {categoryDao.save (Modell); return "Redirect: CategoryList"; }}7. Erstellen Sie ein neues Vorlagenverzeichnis im Ressourcenverzeichnis und erstellen Sie eine Präsentationsebene: Kategorieliste (CategoryList.html), Kategorie Neue Seite (categoryInit.html), Kategorie bearbeiten (categoryEdit.html)
Seite CategoryList (CategoryList.html)
<! DocType html> <html Lang = "en"> <kopf> <meta charset = "utf-8"> <title> Kategorieliste </title> <style> Tabelle, td, td {Border: 1PX Solid Green; Grenzkollapse: Zusammenbruch; } </style> </head> <body> <a th: href = "@{/categoryInit}"> add </a> <Tabelle> <tr> <Th> Kategorie-Nummer </th> <Th> Kategorie Name </th> <Th> Operation </th> </tr> <! TRAVERSAL-> <tr. TH: Jeweils = "Element: $ {page.content}"> <td th: text = "$ {item.categoryId}"> Kategoriennummer </td> <td th: text = "$ {item.categoryName}"> Kategorienname </td> <td> <a th:href="@{/categoryedit(categoryid=${item.categoryid})}">Edit</a> <a th:href="@{/categorydelete(categoryid=${item.categoryid})}">Delete</a> </td> </td> </tr></table><div> <a th: href = "@{/categoryList (start = 0)}"> [home] </a> <a th: if = "$ {nicht Seite th: href = "@{/categoryList (start = $ {page.number+1})}"> [Nächste Seite] </a> <a th: href = "@{/categoryList (start = $ {page.totalpages-1})}"Neue Seite für Kategorie (categoryInit.html)
<! DocType html> <html Lang = "en"> <head> <meta charset = "utf-8"> <title> Neue Kategorie </title> </head> <body> <form action = "categoryInsert" methode = "post"> < name = "categoryName"/> <br/> <Eingabe type = "sureichen" value = "subieren"> </form> </body> </html>
Seite Kategorie bearbeiten (categoryEdit.html)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Category Edit</title></head><body><form action="categoryupdate" method="post"> <input type="hidden" id="txtCategoryid" name="categoryid" th: field = "$ {category.categoryId}"/> <br/> <Label für = "txtCategoryName"> Kategorie Name: </label> <input type = "text" id = "txtCategoryName" name = "categoryName" th: field = "$ {category.categoryname}"/> <br/> <einputtyps value = "subieren"> </form> </body> </html>Zusammenfassen
Das oben oben ist die Idee+Maven+Springboot+JPA+Thymeleaf Implementierung von Crud und Pagination, die Ihnen vom Herausgeber vorgestellt wurden. Ich hoffe, es wird für alle hilfreich sein. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht und der Editor wird allen rechtzeitig antworten. Vielen Dank für Ihre Unterstützung auf der Wulin.com -Website!