首页 > 编程语言 > 详细

spring-boot+mybatis整合简写

时间:2017-09-10 21:28:54      阅读:783      评论:0      收藏:0      [点我收藏+]

spring与mybatis整合,代码将变得非常优雅!

主要使用的jar包是mybatis-spring-boot-starter.jar,其maven依赖如下,加入到pom.xml文件中

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>

创建实体类对象:student

创建mapper接口,打上@Mapper注解

@Mapper
public interface StudentMapper {
@Insert("insert into student(s_id,s_name) values(#{id},#{name})")
void createStudent(Student student);

@Select("select * from student")
@Results({ @Result(property = "id", column = "s_id"), @Result(property = "name", column = "s_name") })
List<Student> getAllStudents();
}

使用增删改查注解添加sql语句,映射到抽象方法中,如果方法中使用了list,则使用results和result注解映射list

 

spring-boot+mybatis整合简写

原文:http://www.cnblogs.com/lenghui/p/7502104.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!