java mybaits常用代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java mybaits常用代码相关的知识,希望对你有一定的参考价值。
//insertList返回更新后的id
@Insert("insert into table3 (id, name) values(null, #{name})")
@Options(useGeneratedKeys=true, keyProperty="idName")
int insertTable3(SomeBean myBean);
//创建表
@Update("CREATE TABLE IF NOT EXISTS `${tablename}`(\n" +
" `id` int(11) NOT NULL AUTO_INCREMENT,\n" +
" `tcid` varchar(255) DEFAULT NULL,\n" +
" `callid` varchar(255) DEFAULT NULL,\n" +
" `channel` varchar(255) DEFAULT NULL,\n" +
" `scid` int(11) DEFAULT NULL,\n" +
" `rid` int(11) DEFAULT NULL,\n" +
" `value` varchar(255) DEFAULT NULL,\n" +
" `inittime` datetime DEFAULT NULL,\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `scidindex` (`scid`) USING BTREE,\n" +
" KEY `ridindex` (`rid`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8;")
void createTable(@Param("tablename") String tablename);
//动态表名的insertList
@Insert({"<script> " +
"INSERT INTO `${tablename}` " +
"(tcid, callid, channel, scid, rid, value, inittime) VALUES " +
"<foreach collection ='list' item='correctmarklog' index= 'index' separator =','>(" +
"#{correctmarklog.tcid}," +
"#{correctmarklog.callid}," +
"#{correctmarklog.channel}," +
"#{correctmarklog.scid}," +
"#{correctmarklog.rid}," +
"#{correctmarklog.value}," +
"#{correctmarklog.inittime}" +
")</foreach >" +
"</script>"})
@Options(useGeneratedKeys = true)
void insertList(@Param("tablename") String tablename, @Param("list") List list);
以上是关于java mybaits常用代码的主要内容,如果未能解决你的问题,请参考以下文章
java springmvc mybaits maven shiro mysql整合
[mybaits][逆向工程]
[mybaits][逆向工程]
JAVA-MyBaits对应XML的两种使用方式
MyBaits基本概念和原理
MyBaits基本概念和原理