springboot整合mybatis

新增maven依赖

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

在application.properties配置文件中配置xml的位置

mybatis.mapper-locations=classpath:mapper/*.xml

即将xml文件放在resource目录下的mapper文件夹中。

Mapper

@Mapper
public interface PersonMapper {
    
    public void insert(Person person);
    
    public List<Person> query();
    
}

对应的xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.dao.mybatis.PersonMapper">
    
    <insert id="insert" parameterType="com.example.demo.bean.Person">
        insert into person(name,age) values(#{name},#{age})
    </insert>
    
    <select id="query" resultType="com.example.demo.bean.Person">
        select * from person
    </select>

</mapper>

 

posted @ 2019-10-05 23:12  xtu熊大  阅读(197)  评论(0编辑  收藏  举报