1. Windows 7 Enterprise Edition
2. Ideia 14
3. JDK 1.8
4. Maven 3.5.2
5. Mariadb
6. Sqlyog
Adicionar configurações.xml no diretório conf no diretório maven ao seguinte conteúdo:
1. O uso do repositório da Alibaba Cloud é muito mais rápido que o site oficial.
<linpor> <d> nexus-aliyun </d> <flinferof> Central </flinferof> <name> nexus Aliyun </name> <url> http://maven.aliyun.com/nexus/content/groups/public </url> </espelho>
2. Configuração do JDK global
<!-Configuração global do JDK, Settings.xml-> <filid> <d> jdk18 </dod> <tivtation> <litiveByDefault> true </titiveByDefault> <ndk> 1.8 </jdk> </tivation> <Perperies> <Maven.compiler.Source> 1./////Ativation.com <ililer.com.iler.com <////ativação> <ililer.com. <Maven.compiler.target> 1.8 </Maven.compiler.target> <Maven.compiler.compilerversion> 1.8 </Maven.compiler.compilerversion> </souperts> </souperies> </silyer.com </filerversion
1. Configurações do Maven: selecione o diretório maven e configure o arquivo e o repositório local ao mesmo tempo.
2. Configurações de codificação de caracteres
Selecione Ativar auto-import e crie o diretório do projeto, como mostrado abaixo:
1. Pom.xml
<? xml versão = "1.0" coding = "utf-8"?> <Projeto xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.ww3.org/2001/xmlschaMance xsi: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <lodelversion> 4.0.0 </modelversion> <vroupId> cn.etttation <rorpursion> 4.0.0 </modelversion> <vroupId> cn.etttation <rorpursion> 4.0.0 </modelversion> <vroupId> cn.etttation <rorpursion> 4.0.0 </modelversion> <vroupId> cn.etttation <rorpursion> 4.0.0 </modelversion> <vroupId> cn.tement <Versão> 1.0-SNAPSHOT </Version> <!-Configurações padrão para usar a bota de primavera-> <airment> <puperid> org.springframework.boot </foupid> <stifactId> spring-boot-starter-parter </Artifactid> <versão 2.0.0.Release </sipers> </dependências <roupidId> org.springframework.boot </roupiD> <TRATIFACTID> Spring-boot-starter-web </stutifactId> </pendesicency> <!-tymEleaf-> <pendency> <purrentId> org.springframework.boot </grupo> <TristifactId> spring-BoTarter-stern mysql ---> <Depencency> <puperid> mysql </groupId> <TRATIFACTID> mysql-conector-java </artifactId> <versão> 5.1.21 </version> </dependency> <!-jpa-> <pendency> <puaded> org.springframesward.boot </grupo <TarfactId> Spring-boot-Starter-Data-JPA </sutifactId> </dependency> </dependências> </Project>
2. Crie um novo aplicativo.Properties no diretório de recursos (é claro, se você gosta de usar o YAML, pode usar o YAML)
# 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. Crie a classe de inicialização do programa de troca de troca SpringbootApplication.java
pacote cn.temptation; importar org.springframework.boot.springApplication; importar org.springframework.boot.autoconfigure.springbootapplication; @springbootapplicationpublic Class SpringbootApplication {public static void main (string [] Springapplication.run (springbootApplication.class, args); }}4. Crie categoria de classe de entidade.java
pacote cn.temptation.model; importar javax.persistence.*; // biblioteca tabela // categoria de tabela de soltar; //// criar categoria de tabela // (// categoryId int auto_increntry Primary Key, // categoryName Varchar (10) não null //); 'Clothing'), (null, 'sapatos'); ///// selecione * na categoria; @entity @tabela (name = "category") categoria de classe pública {@id @generatedValue (estratégia = generationType.Identity) @column (name = "categoryId") private integger categoryid; @Column (name = "categoryName") categoria de sequência privada; public integer getCategoryId () {Return categoryId; } public void setCategoryId (categoryId inteiro) {this.categoryId = categoryId; } public string getCategoryName () {return categoryName; } public void setCategoryName (string categoryName) {this.categoryName = categoryName; }}5. Crie a categoria da interface Dao
pacote cn.temptation.dao; importar cn.temptation.model.category; importar org.springframework.data.jpa.repository.jparepository; interface pública categorydao estende jparepository <category, integger> {}6. Crie a classe do controlador categorycontroller.java
pacote cn.temptation.web; importar cn.temptation.dao.categorydao; importar cn.temptation.model.category; importar org.springframework.bean.factory.annotation.autowired; import org.springframework.data.domain.mport; org.springframework.data.domain.pagerequest; importar org.springframework.data.domain.pageable; importar org.springframework.data.domain.sort; importframeframework.teroType.Controller; import.springfringfringframework.Stereotypey.Controlller; import.springfringfringframework.terotepy.Controlller; import.springfringfringframework.terotepy.Controlller; import.springfringframework.terotipo.Controllan; org.springframework.web.bind.annotation.requestparam; importar org.springframework.web.servlet.modlandview; importar java.util.list; @ControllerPublic CategoryCoryCoryCroller @AUTOUNDIED CategoryDaODaDaDaDaCoryCoryCroller @AUTOUNDIDODED CategorydadoDaDa; /** * Consulta de descomping * * @return * /// @RequestMapping ("/categoryList") // public ModelAndView categoryList () {// List <Category> List = categorydao.findall (); /////modandview Mav = new ModelAndview ("CategyLyList"); /** * Query de paginação * * @RETURN */@RequestMapping ("/categoryList") public ModelAndView CategoryList (@RequestParam (value = "start", defaultValue = "0") Integer Start, @RequestParam (value = "limite", defaultValue = "2") Integer) {Limit) {RequestParam = "Limit", defaultValue = "2") 0, {RequestParam = "limite", defaultValue = "2") 0, {REREQUESTARAM = " 0: Iniciar; Classificação de classificação = new Sort (Sort.Default_Direction, "CategoryId"); Pagável pagável = new PageRequest (start, limite, classificação); Página <category> página = categorydao.findall (pagável); // 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.islTt ()); ModelAndView MAV = new ModelAndView ("CategoryList"); mav.addobject ("página", página); retornar mav; }/** }/ * * retornar "Redirecionar: CategoryList"; }/** * Categoria Excluir operação * @param categoryId * @return */@requestMapping ("/categoryDelete") public string categoryDelete (categoryId categoryId) {categorydao.deletebyId (categoryId); retornar "Redirecionar: CategoryList"; }/** * Edição de categoria Visualização * @param categoryId * @return */@requestmapping ("/categoryedit") public ModelAndView Categoryedit (categoryId Inteiro) {category Model = categorydao.getOne (categoryId); ModelAndView MAV = new ModelAndView ("Categoryedit"); mav.addobject ("categoria", modelo); retornar mav; }/** * Operação de edição de categoria * Modelo @param * @return */@requestmapping ("/categoryUpdate") public string categoryupdate (modelo de categoria) {categorydao.save (modelo); retornar "Redirecionar: CategoryList"; }}7. Crie um novo diretório de modelos no diretório de recursos e crie uma camada de apresentação: página da lista de categoria (categorylist.html), categoria nova página (categoryinit.html), página de edição de categoria (categoryedit.html)
CategoryList Page (categorylist.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> Lista de categoria </title> <yoy> tabela, th, td {borda: 1px verde sólido; colapso da fronteira: colapso; } </style> </ad Head> <body> <a th: href = "@{/categoryinit}"> add </a> <table> <tr> <th> Número da categoria </th> <th> Nome da categoria </th> <th> operação </th> </! traversal-> <tr th: cada = "item: $ {page.content}"> <td th: text = "$ {item.categoryId}"> número da categoria </td> <td th: text = "$ {item.categoryname}"> nome da categoria </td> <t th: href = "@{/categoryedit (categoryId = $ {item.categoryId})}"> edit </a> <a th: href = "@{/categoryDelete (categoryId = $ {item.categyId}}"> delate </a> </td> th: href = "@{/categoryList (start = 0)}"> [home] </a> <a th: if = "$ {não página.isfirst ()}" th: href = "@{/categorylist (start = $ {Page.TotalPage-1})} {(não] th: href = "@{/categoryList (start = $ {page.Number+1})}"> [próxima página] </a>Nova página para categoria (categoryinit.html)
<! Doctype html> <html lang = "pt"> <head> <meta charset = "utf-8"> <title> nova categoria </title> </ad head> <body> <formulário action = "categoryInsert" method = "post"> <bel para = "txtcategoryName"> category Nome: </</> name = "categoryName"/> <br/> <input type = "submit" value = "submit"> </mand> </body> </html>
Página de edição de categoria (categoryedit.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> Editar categoria </ititle> </ad Head> <body> <formulário action = "categoryUpdate" method = "post"> <input type = "hidden" id = "txtCategoryId" Nome = "post"> <tipo "Hidden" id = "" txtcategoryId "Nome =" Post "> <tipo" Hidden "" ida "=" txtCategoryId " th: field = "$ {category.categoryId}"/> <br/> <gravador para = "txtCategoryName"> Nome da categoria: </label> <input type = "text" id = "txtCategoryName" name = "categoryName" th: field = "$ {category.categoryname"/"/" value = "submeter"> </morm> </body> </html>Resumir
O exposto acima é a idéia+maven+springboot+jpa+implementação de tymeleaf de crud e paginação introduzida a você pelo editor. Espero que seja útil para todos. Se você tiver alguma dúvida, deixe -me uma mensagem e o editor responderá a todos a tempo. Muito obrigado pelo seu apoio ao site wulin.com!