Created
May 2, 2017 15:10
-
-
Save ghusta/22adc9a1eb1f76841867d41ac47f33b8 to your computer and use it in GitHub Desktop.
Spring Data JPA JpaRepository Freemarker Template for Hibernate Tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Généré par Hibernate Tools ${version} le ${date} | |
* avec FreeMarker ${.version} | |
*/ | |
${pojo.getPackageDeclaration()} | |
import ${pojo.getQualifiedDeclarationName()}; | |
<#assign classbody> | |
<#assign pkType = pojo.getJavaTypeName(clazz.identifierProperty, true) /> | |
<#assign entityName = pojo.getDeclarationName() /> | |
/** | |
* Repository Spring Data JPA pour l'entité {@link ${entityName}}. | |
* | |
* @see JpaRepository | |
*/ | |
@${pojo.importType("javax.annotation.Generated")}(value = "Généré par Hibernate Tools ${version}", date = "${.now?iso_local}") | |
@${pojo.importType("org.springframework.stereotype.Repository")} | |
@SuppressWarnings("serial") | |
public interface ${entityName}Repository | |
extends ${pojo.importType("org.springframework.data.jpa.repository.JpaRepository")}<${pojo.getDeclarationName()}, ${pkType}> | |
{ | |
<#-- Générer un finder JPA pour cette property --> | |
<#foreach property in pojo.getAllPropertiesIterator()><#if c2j.hasMetaAttribute(property, "gen-finder")> | |
<#assign propertyJavaType = pojo.getJavaTypeName(property, jdk5) /> | |
// Finder Spring Data JPA pour : ${property.name} | |
${pojo.importType("java.util.List")}<${entityName}> findBy${property.name?cap_first}(${propertyJavaType} ${property.name}); | |
/** | |
* Lecture d'une page. | |
* | |
* @param ${property.name} critère recherche (égalité). | |
* @param pageable Requête page. | |
* @return {@link Page} de résultat, avec données annexes (nombre total de pages / résultats). | |
*/ | |
${pojo.importType("org.springframework.data.domain.Page")}<${entityName}> findBy${property.name?cap_first}(${propertyJavaType} ${property.name}, ${pojo.importType("org.springframework.data.domain.Pageable")} pageable); | |
/** | |
* Lecture d'une page. | |
* <p> | |
* As you also can see, simply returning a List is possible as well. | |
* In this case the additional metadata required to build the actual Page instance will not be created (which in turn means that the additional count query that would have been necessary not being issued) but rather simply restricts the query to look up only the given range of entities. | |
* </p> | |
* @param ${property.name} critère recherche (égalité). | |
* @param pageable Requête page. | |
* @return Liste de résultat, sans données annexes sur la {@link Page}. | |
*/ | |
List<${entityName}> findBy${property.name?cap_first}(${propertyJavaType} ${property.name}, ${pojo.importType("org.springframework.data.domain.Pageable")} pageable); | |
${pojo.importType("java.util.List")}<${entityName}> findBy${property.name?cap_first}(${propertyJavaType} ${property.name}, ${pojo.importType("org.springframework.data.domain.Sort")} sort); | |
</#if> | |
<#if c2j.hasMetaAttribute(property, "gen-finder-like")> | |
/** | |
* Find avec clause SQL LIKE. | |
* | |
* @param ${property.name} critère recherche (like) : peut contenir des caractères génériques comme '%' ou '_'. | |
* @return Liste de résultats. | |
*/ | |
${pojo.importType("java.util.List")}<${entityName}> findBy${property.name?cap_first}Like(${propertyJavaType} ${property.name}); | |
</#if> | |
</#foreach> | |
} | |
</#assign> | |
${pojo.generateImports()} | |
${classbody} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use with :