import com.intellij.database.model.DasTable
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
import java.text.SimpleDateFormat
packageName = "com.example.demo"
FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
SELECTION.filter { it instanceof DasTable }.each { generate(it, dir) }
}
def generate(table, dir) {
def className = javaName(table.getName(), true)
new File(dir, className + "Dao.java").withPrintWriter("utf-8") { out -> generate(out, table, className) }
}
def generate(out, table, className) {
out.println "package ${packageName}.pojo.dao;"
out.println ""
out.println "import ${packageName}.pojo.entity.${className}Entity;"
out.println "import org.springframework.data.jpa.repository.JpaRepository;"
out.println ""
out.println "/**"
out.println " * @ClassName ${className}Dao"
out.println " * @Description Automatic script generation"
out.println " * @Author"
out.println " * @Date ${new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())}"
out.println " * @Version 1.0"
out.println " */"
out.println "public interface ${className}Dao extends JpaRepository<${className}Entity, Object>{"
out.println ""
out.println "}"
}
def javaName(str, capitalize) {
def s = com.intellij.psi.codeStyle.NameUtil.splitNameIntoWords(str)
.collect { Case.LOWER.apply(it).capitalize() }
.join("")
.replaceAll(/[^\p{javaJavaIdentifierPart}[_]]/, "_")
capitalize || s.length() == 1 ? s : Case.LOWER.apply(s[0]) + s[1..-1]
}
POJO-jpa-lombok-Dto.groovy
最新推荐文章于 2021-09-16 17:18:06 发布