javafx框架tornadofx批量生成桌面版CRUB程序

2019-09-03 18:35:52 浏览数 (2)

演示地址

javafx框架tornadofx批量生成桌面版CRUB程序,采用tornadofx制作界面,jfinal active record操作数据库,jfinal enjoy模板引擎生成相关代码,只演示了简单桌面版CRUB程序,更完善的程序需要对模板代码进行设计。

代码语言:txt复制
import java.sql.Connection
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.StdOutSqlLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.transactions.TransactionManager
import tornadofx.*

class CRUD_GUI : App(MainTap::class){
var n=0
override fun init() {
if(n==0){
run{
newDb()
}
n =1
}
        super.init()
    }
}

class MainTap() : View("CRUD_GUI") {

    override val root = tabpane {

        #for(v:views)
        tab("#(v)") {
            isClosable=false
            add(#(v)Editor())
        }
        #end
    }
}

// create db and table
fun newDb() {
    // "connect" a database file called data.sqlite in the current working directory
    // (creates the file if id does not exist)
    Database.connect("jdbc:sqlite:file:data.sqlite", driver = "org.sqlite.JDBC")
    // this isolation level is required for sqlite, may not be applicable to other DBMS
    TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE

    transaction {
    addLogger(StdOutSqlLogger)
    // create the table
	#for(c:claLowName)
    SchemaUtils.create(#(c ??)zz)
	#end

    // add some entries
    ###(claUpName ??).new {
    ###for(col : cols)
    ###if(for.first)
    ###continue
    ###end
    ###(col.attrName ??) ="#(col.attrName ??) #(for.index)"
    ###end
    ###}
    }

    // new transaction to check the results
    transaction {
        #(claUpName ??).all().forEach { println(it) }
    }
}

0 人点赞