springboot-2.3 mybatis

一 .添加依赖

springboot-2.3 mybatis_第1张图片

二.动态sql

1.直接在方法名上写sql(不推荐)
springboot-2.3 mybatis_第2张图片
2.使用Provider
springboot-2.3 mybatis_第3张图片
或者Provider中使用new SQL()编写
springboot-2.3 mybatis_第4张图片

在mapper中调用
springboot-2.3 mybatis_第5张图片

3.使用xml (推荐)
application.properties中配置xml路径:

#mybatis配置
mybatis.mapper-locations=classpath:com/study/springboot/mapper/*.xml

编写xml






	
		
		
		
	

	
		insert into Cat(cat_name,cat_age)
		values(#{catName},#{catAge})  
	 
	
	
		DELETE FROM Cat WHERE id=${id}
	
	
	
	

mapper添加对应方法
springboot-2.3 mybatis_第6张图片
最后controller调用service调用mapper

ohter

xml语法
springboot-2.3 mybatis_第7张图片
springboot-2.3 mybatis_第8张图片
springboot-2.3 mybatis_第9张图片
springboot-2.3 mybatis_第10张图片
choose相当于java中的switch语法

springboot-2.3 mybatis_第11张图片
springboot-2.3 mybatis_第12张图片
springboot-2.3 mybatis_第13张图片

你可能感兴趣的:(springBoot)