Jfinal data operation module db.record v 0.0.4 released

  

update content

Add to:

    public static void initAlias(String configName,String jdbcURL, String jdbcUser, String jdbcPassword) {
		init(configName,"com.mysql.cj.jdbc.Driver",jdbcURL,jdbcUser,jdbcPassword,null,null,false);
	}
	
	public static void initAlias(String configName,String jdbcDriver, String jdbcURL, String jdbcUser, String jdbcPassword) {
		init(configName,jdbcDriver,jdbcURL,jdbcUser,jdbcPassword,null,null,false);
	}

Fix: Error initializing data source name

 

Summary:

By record (map) the data table manner, non orm orm like, semi-like operation.

This class library based on jfinal V1.9 transformation, write some simple function of time is particularly suitable for use, for example, be carried forward data, such as initial data, compared orm do not need to do a bunch of, like, compared to save sql do not need to engage in some insert update.

Several tables of data query returns a record by sql statement, to direct the like (not write sql) to save or update to a new table. This is particularly easy

apache dbutils has been good enough to support the database, but still a bit complicated, of course, also be based on dbutils achieve operation of jfinal

Compared Spring jdbcTemplate it is certainly less dependent than N

Compared jdbc operation it is certainly a lot easier

db.record

Table data record (map) is operated, non-orm orm like, as the operation of the present semi-library based on transformation jfinal V1.9

Use maven

<dependency>
	<groupId>com.liucf</groupId>
	<artifactId>db.record</artifactId>
	<version>0.0.4</version>
</dependency>

Examples

1. Initialize the Db

//初始化数据连接
Db.init("jdbc:mysql://host:port/test?characterEncoding=utf-8&autoReconnect=true&autoReconnectForPools=true&serverTimezone=GMT%2B8","root", "xxx");
//打印sql日志
Db.use().setShowSql(true);

2. query data

//简单查询
List<Record> baskets = Db.find("select * from base_basket");
for (Record record : baskets) {
	System.out.println(record.getStr("id"));
	System.out.println(record.toJson());
}

//根据id查询
Record record = Db.findById("base_basket", "001")

//查询首条数据
Db.findFirst("select * from base_basket where id = ?", "001")

//分页查询 count参数决定是否统计总行数
Page<Record> p = Db.paginate(1, 2, "select * from base_basket where id>?", false, "1000");
p.getList();
p.getPageNumber();
p.getPageSize();
p.getTotalPage();
p.getTotalRow();

3. Add

Record r = new Record();
r.set("id", "ddddd");
Db.save("base_basket", r);

4. Update

Record r = new Record();
r.set("id", "ddddd");
Db.update("base_basket", r);
//主键名称非id
//Db.update("base_basket", "id", r);

4. Delete

Db.deleteById("base_basket", "001");
//Db.update("delete from base_basket");

5. Transaction

Db.tx(new TransactionWrap() {
		@Override
		public boolean run() throws SQLException {
			try {
				Record r = new Record();
				r.set("id", "ddddd");
				Db.save("base_basket", r);
				
				r.set("id", "ddddd");
				r.set("remarks", "remarks");
				Db.update("base_basket", "id", r);
			} catch (Exception e) {
				return false;
			}
			return true;
		}
	});

Guess you like

Origin www.oschina.net/news/107038/db-record-0-0-4-released