content:
- Experience JBOOT (1) -- Hello, Jboot
- Experience JBOOT (2)--Database
- Experience JBOOT (3)--RPC
- Experience JBOOT (4) -- jboot-admin articles
- Create a database (in the example, the database name is demo, the username and password are also demo, and there is a table in the database called user)
-
Create a jboot.properties file under resources with the following configuration:
jboot.datasource.type=mysql jboot.datasource.url=jdbc:mysql://localhost/demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull jboot.datasource.user=demo jboot.datasource.password=demo
- Modify MyController.java created in the previous section and change it to:
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); } }
-
Create an index.html template file in the resource directory:
<!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>
-
Rerun the program to see the results