我踩过的坑希望你们重新踩一遍
1, dao层(Mapper)——>service——>controller(控制层)
| | (impl) |
对应Mapper.xml 注入dao层(Mapper) 注入service
2
出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的解决方法 原因:没有找到方法及Mapper那个包,查看自己的mapper.xml文件,看一下 <mapper namespace="com.bk.Mapper.userMapper"> 是否与项目中mapper包名字一样,大小写敏感。推荐你们使用逆向工程。
application.yml 文件
spring:
datasource:driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/lyb?useUnicode=true&characterEncoding=UTF-8
username: root
password: 7788521
type: com.alibaba.druid.pool.DruidDataSource
connectionProperties: druid.stat.mergeSql=true
mybatis:
typeAliasesPackage: com.bk.entity
mapperLocations: classpath:mapper/*.xml
#config-location: mybatis-config.xml
userMapper.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.bk.Mapper.userMapper">
<resultMap id="BaseResultMap" type="com.bk.entity.User">
<result column="id" jdbcType="DECIMAL" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<insert id="insert" parameterType="com.bk.entity.User">
<selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into user (id, name)
values (#{id,jdbcType=DECIMAL}, #{name,jdbcType=VARCHAR})
</insert>
<select id="selectAll" resultMap="BaseResultMap">
select id, name
from user
</select>
</mapper>