insert into game_data (game_id, team_id, user_id, score, assists, yellow_card, red_card, extra) values #for(x : data) #(for.index == 0 ? "" : ",") (#(x.game_id), #(x.team_id), #(x.user_id), #(x.score), #(x.assists), #(x.yellow_card), #(x.red_card), #(x.extra ?? "null")) #end on duplicate key update score = values(score), assists = values(assists), yellow_card = values(yellow_card), red_card = values(red_card), extra = values(extra)
执行之后的SQL
insert into game_data (game_id, team_id, user_id, score, assists, yellow_card, red_card, extra) values (3, 34, 27, 3, 1, 0, 0, 测试) , (3, 34, 17, 1, 2, 0, 0, null) on duplicate key update score = values(score), assists = values(assists), yellow_card = values(yellow_card), red_card = values(red_card), extra = values(extra)
问题:使用模板中的for时,当有中文如何添加双引号。
项目:JFinal
jfinal 的 sql 管理本质上就做了一件事情:利用模板引擎生成 sql 语句,并将问号占位的参数统一放入一个 list,sql 与 参数被封装在了 SqlPara 对象之中
SqlPara 中存放的 sql + paras,转交给 JDBC 执行就完事了