1. Édition de Windows 7 Enterprise
2. Idée 14
3. JDK 1.8
4. Maven 3.5.2
5. Mariadb
6. Sqlyog
Ajouter des paramètres.xml dans le répertoire confr dans le répertoire Maven au contenu suivant:
1. L'utilisation du référentiel d'Alibaba Cloud est beaucoup plus rapide que le site officiel.
<Mirror> <id> Nexus-Aliyun </id> <Mirrorof> Central </ Mirrorof> <Name> Nexus Aliyun </name> <url> http://maven.aliyun.com/nexus/content/groups/public </url> </mirror>
2. Configuration globale JDK
<! - Configuration globale JDK, settings.xml -> <pilaf> <id> jdk18 </id> <cactivation> <cactiveByDefault> true </ ActiveByDefault> <Jdk> 1.8 </Jdk> </Cactivation> <PERTERTIES> <MAVEN.COMPILERS> <maven.compiller.target> 1.8 </maven.compiller.target> <maven.compiller.compillerVersion> 1.8 </maven.compiller.compillerversion> </properties> </sroperties> </ Properties> </pilaf>
1. Paramètres Maven: sélectionnez le répertoire Maven et configurez le fichier et le référentiel local en même temps.
2. Paramètres d'encodage de caractères
Sélectionnez Activer Auto-Import et créez le répertoire de projet comme indiqué ci-dessous:
1. Pom.xml
<? xml version = "1.0" Encoding = "utf-8"?> <project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" XSI: ScheMalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modersversion> 4.0.0 </ Modelversion> <proupId> CN.Temptation </prenidId> <ArtifActid> Studyrboot </ Artifat <version> 1.0-snapshot </ version> <! - Paramètres par défaut pour l'utilisation de Spring Boot -> <parent> <proupId> org.springframework.boot </prôdId> <ArtifActid> Spring-Boot-starter-Parent </ ArtifactId> <Dersion> 2.0.0.Release </Sease> </parent> <predences> <! - Web - WEB -> <Dendence> <GroupId> org.springframework.boot </proupId> <Artifactid> printemps-boot-starter-web </lefactive> </dependency> <! - thymeleaf -> <dependency> <proupId> org.springframework.boot </proupId> <Artifactid> Spring-Boot-starter-thymelealealeaf </ artifactive> <! - mysql ---> <dependency> <proupId> mysql </proupId> <ErtifactId> MySQL-Connector-Java </ Artifactid> <DERVIÈRE> 5.1.21 </DERNIFRIENT> </DENDENCENCE> <! - JPA -> <Dedency> <ProupId> Org.SpringFramework.boot </proupId> <ArtefactId> printemps-boot-starter-data-jpa </retifactid> </dpendance> </dpendance> </randing>
2. Créez une nouvelle application.
# Database Connection Spring.Datasource.url = JDBC: mysql: //127.0.0.1: 3306 / testspring.datasource.usename = rootspring.datasource.password = saspring.datasource.driver-cl-nom = com.mysql.jdbc.Diver printemps.jpa.properties.hibernate.hbm2ddl.auto = mise à jour
3. Créez Springboot Program Startup Class SpringbootApplication.java
package cn.temptation; import org.springframework.boot.springApplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplicationpublic class SpringbootApplication {public static Void main (string [] args) {// projection de Springboot Démarrages du projet STATIQUE STATIC SpringApplication.Run (SpringbootApplication.Class, Args); }}4. Créer une catégorie de classe d'entité.java
package cn.temptation.model; importer javax.persistence. *; // Tableau de construction de bibliothèque // catégorie de table de drop; //// Créer une catégorie de table // (// catégorid null //); /////// / insert dans les valeurs catégoriques (null, 'mobile'), (null '), (null valeurs (null,' mobile '), (null'), (null valeurs (null, 'mobile'), (null '), (null valeurs (null,' mobile '), (null'), (null 'Clothing'), (null, 'chaussures'); ///// Select * From category; @ entity @ table (name = "catégorie") classe publique Catégorie {@id @generatedValue (Strategy = GenerationType.Identity) @Column (name = "catégoryId") Private Integer categoryId; @Column (name = "catégoryName") Private String categoryName; public entier getCategoryId () {return categoryId; } public void setCategoryId (Integer categoryId) {this.categoryId = categoryId; } public String getCategoryName () {return categoryName; } public void setCategoryName (String categoryName) {this.categoryName = catégorieName; }}5. Créer une catégorie d'interface Daodao.java
package cn.temptation.dao; import cn.temptation.model.category; import org.springframework.data.jpa.repository.jParepository; interface publique Catégoriedao étend JParePository <catégories, Integer> {}6. Créez la classe Contrôle CatégorieController.java
package cn.temptation.web; import Cn.Temptation.dao.categorydao; import Cn.Temptation.Model.category; import org.springframework.beans.factory.annotation.page; import; org.springframework.data.domain.pageRequest; import org.springframework.data.domain.pagable; import org.springframework.data.domain.sort; import org.springframework.sterreeotype.Controller; import org.springframework.web.bind.annotation.requerson org.springframework.web.bind.annotation.requestParam; import org.springframework.web.servlet.modelandView; import java.util.list; @ControllerPublic CatégoryController {@Autowired Private catégorydao catégoriedao; / ** * une requête UNPAGE * * @return * /// @RequestMapping ("/ catégorieList") // ModelAndView categoryList () {// list <category> list = categorydao.findall (); /// modelandView Mav = new ModelandView ("catégorieList"); // mav.addobject ("list", list); // return mav Query de pagination * * @return * / @RequestMapping ("/ catégorieList") public ModelAndView categoryList (@RequestParam (value = "start", defaultValue = "0") Integer start, @RequestParam (value = "limite", defaultValue = "2") Integer limite) {start = start <0? 0: démarrer; SORT SORT = NOUVEAU SORT (SORT.DEFAULT_DIRECTION, "CATECTORYID"); Pagable pagable = new PageRequest (start, limite, tri); Page <catégories> page = catégoriedao.findall (pagable); // system.out.println (page.getNumber ()); // system.out.println (page.getNumberOfElements ()); // system.out.println (page.getSize ()); // system.out.println (page.getTotoLelements ()); // System.out.println (page.getTotalPages ()); // System.out.println (Page.Sifirst ()); // System.out.println (page.islast ()); ModelAndView mav = new ModelAndView ("catégorieList"); mav.addObject ("page", page); retourner mav; } / ** * Nouvelle vue dans la catégorie * @return * / @RequestMapping ("/ catégorieInit") Public String categoryInit () {return "categoryInit"; } / ** * Nouvelle opération dans la catégorie * @param modèle * @return * / @requestmapping ("/ catégorieinsert") Public String categoryInsert (catégorie modèle) {catégoriedao.save (modèle); retourner "Redirection: catégorieList"; } / ** * catégorie Supprimer l'opération * @param catégorieid * @return * / @requestmapping ("/ catégoriedElete") public String categoryDelete (Integer categoryId) {catégoriedao.deleteById (catégorieId); retourner "Redirection: catégorieList"; } / ** * Catégorie View d'édition * @param categoryId * @return * / @requestmapping ("/ catégoryEdit") public ModelAndView categoryEdit (Integer categoryId) {catégorie modèle = catégoriedao.getOne (catégorieId); ModelAndView mav = new ModelAndView ("catégorieEdit"); mav.addObject ("catégorie", modèle); retourner mav; } / ** * Opération d'édition de catégorie * @param modèle * @return * / @RequestMapping ("/ catégoryupdate") Public String categoryupdate (catégorie modèle) {catégoriedao.save (modèle); retourner "Redirection: catégorieList"; }}7. Créez un nouveau répertoire de modèles sous le répertoire des ressources et créez une page de présentation: Page de liste de catégories (catégorieList.html), catégorie nouvelle page (catégorieinit.html), page d'édition de catégorie (catégorieedit.html)
Page CatégoryList (catégorieList.html)
<! Doctype html> <html lang = "en"> <éadf> <meta charset = "utf-8"> <tle-title> Liste de catégorie </title> <style> Table, th, td {border: 1px Solid Green; Border-Collapse: s'effondrer; } </ style> </ head> <body> <a th: href = "@ {/ categoryInit}"> add </a> <pable> <tr> <th> Catégorie numéro </ th> <th> Nom de catégorie </th> <th> Opération </th> </tr> <! - Pas de pages Transversal -> <! <tr th: chaque = "item: $ {page.content}"> <td th: text = "$ {item.categoryId}"> Catégorie numéro </ td> <td th: text = "$ {item.categoryName}"> Nom de catégorie </ td> <td> <a th: href = "@ {/ catégoryedit (catégorieid = $ {item.categoryId})}"> edit </a> <a th: href = "@ {/ categoryDelete (catégorieID = $ {item.categoryId})}"> delete </a> </td> </td> </r> </bout> th: href = "@ {/ catégorieList (start = 0)}"> [home] </a> <a th: if = "$ {pas page.isfirst ()}" th: href = "@ {/ categoryList (start = $ {page.totalpage-1})}"> [page précédente] </a> <a th: if = "$ {non}. th: href = "@ {/ catégorieList (start = $ {page.number + 1})}"> [page suivante] </a> <a th: href = "@ {/ categoryList (start = $ {page.totalpages-1})}"> [dernière page] </a> </v> </ body> </html>Nouvelle page pour la catégorie (catégorieinit.html)
<! Doctype html> <html lang = "en"> <éread> <meta charset = "utf-8"> <itle> nouvelle catégorie </ title> </ head> <body> <form action = "categoryInsert" method = "post"> <label for = "txtcategoryName"> catégorie de nom: </ label> <entrée type = "Text" id = "txtcategory" name = "categoryName" /> <br/> <input type = "soume" value = "soumi"> </ form> </body> </html>
Page d'édition de catégorie (catégoriesedit.html)
<! Doctype html> <html lang = "en"> <éadf> <meta charset = "utf-8"> <tight> catégorie édition </ title> </ head> <body> <form action = "categoryupdate" méthode = "post"> <entrée type = "HIDDEN" id = "txtcategoryid" name = "catégorieid" th: field = "$ {category.categoryId}" /> <br/> <label for = "txtcategoryName"> Nom de catégorie: </vabe> <input type = "text" id = "txtcategoryName" name = "catégorieName" th: field = "$ {catégory.categoryName}" /> <br/> <put type = "soumets" value = "soumi"> </ form> </ body> </html>Résumer
Ce qui précède est l'idée + Maven + Springboot + JPA + la mise en œuvre de thymeleaf de crud et de pagination qui vous est présentée par l'éditeur. J'espère que ce sera utile à tout le monde. Si vous avez des questions, veuillez me laisser un message et l'éditeur répondra à tout le monde à temps. Merci beaucoup pour votre soutien au site Web Wulin.com!