All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jquicker-core.1.0.0.source-code.demo.sql Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
#namespace("com.jquicker.dao.demo") /*命名空间,必须且只能在第一行*/
#mapping("com.jquicker.entity.Test") /*实体映射,可以不定义*/

-- #dataSource("xxxx")

-- 支持关键字:if/else if/else/for

-- 变量申明必须在#sql("")之前
#var entity = "com.jquicker.entity.Test"

#sql("insert_demo1")
INSERT INTO test (id, code, name, remark) VALUES (?, ?, ?, ?);

#sql("insert_demo2")
INSERT INTO test (id, code, name, remark) VALUES (#(id), #(code), #(name), #(remark));

#sql(id="insert_demo3")
INSERT INTO test (id, code, name, remark) VALUES (
#for(item : list, after = ", "){
	item.id, item.code, item.name, item.remark
}
)


#sql(id="update_demo1", paramType="Map")/**/
UPDATE test SET name = #(name) WHERE id = #(id)

#sql(id="update_demo2")
UPDATE test SET id = id 
#if(name){
	, name = #(name)
}
WHERE id = #{id)


#sql(id="select_demo")
SELECT * FROM test WHERE 1 = 1
#if(name){
	AND name = #(name)
}
#else if(code != null && code != ""){
	AND code = #(code)
}
#if(state == 1){
	AND 1 = 1
}
#else if(state == 2){
	AND 2 = 2
}
#else {
	AND 1 = 2
}


#sql(id="select_demo1")
SELECT * FROM test WHERE 1 = 1
AND id IN(
#for(item : list, before = ', '){
	item
}
)

#sql(id="select_demo2")
SELECT * FROM test WHERE 1 = 1
AND id IN(
#for(item : listObj, after = ", "){
	item.id
}
)

-- 关联查询示例:
#sql(id="join_demo1", relation="one-to-one", alias="xxx")/* 怎么解决多表同名字段? */
SELECT t1.id, t1.name, t1.memo, t2.id, t2.t1_id, t2.name xxx_name FROM t1 
LEFT JOIN t2 ON t2.t1_id = t1.id
WHERE 1 = 1

-- 关联查询示例:同一文件中,oneToMany的namespace可省略,property为“一方”实体中对象的“多方”属性名,若是返回map,则会以property为key储存
-- columns为执行关联查询语句时传入的参数字段
#sql(id="join_demo2")
#relation(type="one-to-many", query="join_demo2_join", property="t2List", columns="id", namespace="")
SELECT t1.id, t1.name, t1.memo, t2.id, t2.t1_id, t2.name xx_name FROM t1 
LEFT JOIN t2 ON t2.t1_id = t1.id
WHERE 1 = 1

#sql(id="join_demo2_join", paramType=${entity})
SELECT t2.id, t2.t1_id, t2.name t2
WHERE t2.t1_id = #(id)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy