pom.xml的<build>标签内,增加
<!-- 如果不添加此节点mybatis的mapper.xml文件不会被引用 --> <resources> <!-- src/main/java目录下的配置文件 --> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <!-- src/main/resources目录下的配置文件 --> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>
小心别给路径搞错了,注意有几层目录
/* * 配置mapper.xml所在路径 */ //.properties mybatis.mapper-locations=classpath:com/*/mapper/xml/*.xml //.yml mybatis: mapper-locations=classpath:com/*/mapper/xml/*.xml
@Mapper public interface UserDao { void userInsert(Users user); }
建议放在如图位置
<?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.wx.mapper.UserDao"> <insert id="userInsert" parameterType="com.wx.entity.Users"> insert into users (name,age,sex,address) values(#{name},#{age},#{sex},#{province}) </insert> </mapper>
具体mapper.xml的写法很容易找到,不写了
原文:https://www.cnblogs.com/wx23/p/15137137.html