标签:ima prefix 动态 username 去除 isp insert XML 创建
mybatis框架中最具特色的便是sql语句中的自定义,而动态sql的使用又使整个框架更加灵活。
/*Table structure for table `user` */ DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `username` varchar(20) NOT NULL, `age` int(3) NOT NULL, `phone` varchar(11) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; /*Data for the table `user` */ insert into `user`(`id`,`name`,`username`,`age`,`phone`,`email`) values (1,‘张三‘,‘zs‘,18,‘15010998046‘,‘4567899@qq.com‘),(2,‘李四‘,‘ls‘,19,‘15019087600‘,‘567657642@qq.com‘),(3,‘王五‘,‘ww‘,20,‘15010898065‘,‘2323248@qq.com‘); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
User实体
UserMapper
UserMapper.xml
UserController
测试
http://localhost:8080/getUser
<select id="getUser" resultType="cn.cnki.ref.pojo.User"> select * from user <where> <if test="id != null">and id=#{id} </if> <if test="age != null">and age=#{age} </if> <if test="name != null">and name=#{name}</if> </where> </select>
trim标签下的四个属性:
prefix:在标签开始添加上该字符串
suffixOverrides:在标签末尾去除上该字符串
suffix:在标签末尾添加上该字符串
prefixOverrides:在标签开始去除上该字符串
Java SSM框架之MyBatis3(八)MyBatis之动态SQL
标签:ima prefix 动态 username 去除 isp insert XML 创建
原文地址:https://www.cnblogs.com/cnki/p/9346333.html