程序运行正常,但是进行增删改查就报这个错
意思大概是找不到dao层中的getPaymentById这个方法,我百度了一下大概由这么几种情况:
第一种:mapper.xml文件中的绑定地址错误,namespace后面的地址是否跟自己的dao层地址相同
mapper namespace=“com.atguigu.springcloud.dao.PaymentDao”
第二种:mapper.xml中id值跟dao层中的方法名是否相同,一定要相同
dao层代码
public interface PaymentDao {
public List<Payment> ListPayment();
public int create(Payment payment);
public Payment getPaymentById(int id);
public int delete(int id);
public int update(Payment payment);
}
mapper.xml部分代码
select id="ListPayment",
insert id="create",
select id="getPaymentById",
delete id="delete",
update id="update"
第三种:application.yml 或者是application.properies配置文件中没有mybatis的配置,或者是用的.yml文件格式有问题,冒号‘:’后面需要有一个空格
spring:
application:
nama: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC
username: root
password: 数据库密码
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.atguigu.springcloud.entities
我的错误就是第三种,但不是我的问题,是因为版本更新了的原因,里面的 mapperLocation没有了,需要改成mapper-locations
错误的如下:
正确的如下:
如有问题欢迎指导谢谢
转载请注明出处,支持原创,谢谢!