目錄:html
在resources下建立jboot.properties文件,配置內容以下:java
jboot.datasource.type=mysql jboot.datasource.url=jdbc:mysql://localhost/demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull jboot.datasource.user=demo jboot.datasource.password=demo
package io.jboot.hello; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import io.jboot.Jboot; import io.jboot.web.controller.JbootController; import io.jboot.web.controller.annotation.RequestMapping; import java.util.List; /** * Created by Tom on 2018/3/13. */ @RequestMapping("/") public class HelloController extends JbootController { public void index(){ List<Record> users = Db.find("select * from user"); setAttr("users", users); render("index.htlm"); } public static void main(String[] args){ Jboot.run(args); } }
在resource目錄下創建一個index.html模板文件:
mysql
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用戶信息</title> </head> <body> <h3>用戶信息:</h3> #for (user : users) #(user.username) <br> #end </body> </html>
從新運行程序,就能夠看到結果了
web