SpringBoot整合MybatisPlus调用接口403

今天写登录接口的时候遇到了一些问题,控制台不报错打印以下信息,但是用apifox调用接口的时候就403,

JDBC Connection [HikariProxyConnection@967625212 wrapping com.mysql.cj.jdbc.ConnectionImpl@3054f1b2] will not be managed by Spring
==>  Preparing: SELECT id,user_name,nick_name,password,type,status,email,phonenumber,sex,avatar,create_by,create_time,update_by,update_time,del_flag FROM user WHERE del_flag=0 AND (user_name = ?)
==> Parameters: xcc(String)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6481e5c7]

然后我挨个文件检查了一遍感觉还是没有问题,然后检查表的字段,我还在想能不能是字母大小写或者是写错了呢,显然也不是。

最终,我想起来,用easycode生成代码的时候我把表名前缀去掉了,我数据库里面写的是sys_user,但是查询FROM user,看到这我也真是服了,我感觉我就是个智者(shabi)。

找到问题,我们就可以把数据库表名前缀去掉,或者在entity类中加个注解把表名前缀加上。

有的时候遇到bug就一心像解决它,而不分析它,导致盲目的去找bug,效率特低。

下面是一个简单的示例代码,演示了如何在Spring Boot中使用Mybatis Plus框架调用Oracle存储过程。 1. 首先,需要在pom.xml文件中添加MyBatis Plus和Oracle JDBC驱动程序的依赖项: ``` <dependencies> <!-- MyBatis Plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.2</version> </dependency> <!-- Oracle JDBC driver --> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>19.3.0.0</version> </dependency> </dependencies> ``` 2. 编写Mybatis Plus配置类,配置Oracle数据源,并添加对应的Mapper扫描路径: ``` @Configuration @MapperScan("com.example.demo.mapper") public class MybatisPlusConfig { @Bean public DataSource dataSource() { // TODO: replace with your own Oracle connection information String url = "jdbc:oracle:thin:@localhost:1521:orcl"; String username = "your_username"; String password = "your_password"; return new DriverManagerDataSource(url, username, password); } @Bean public SqlSessionFactory sqlSessionFactory() throws Exception { MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean(); factoryBean.setDataSource(dataSource()); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*.xml")); return factoryBean.getObject(); } @Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } } ``` 3. 编写存储过程的Mapper接口: ``` @Mapper public interface MyStoredProcedureMapper { @Options(statementType = StatementType.CALLABLE) @Select("{call your_procedure_name(#{inputParam1, mode=IN}, #{inputParam2, mode=IN}, #{outputParam1, mode=OUT, jdbcType=NUMERIC}, #{outputParam2, mode=OUT, jdbcType=VARCHAR})}") void callMyStoredProcedure(@Param("inputParam1") String inputParam1, @Param("inputParam2") String inputParam2, @Param("outputParam1") Integer outputParam1, @Param("outputParam2") String outputParam2); } ``` 注意,这里的@Select注解中使用了Oracle的存储过程调用语法,其中包含了输入参数、输出参数的定义,需要根据实际情况进行修改。 4. 在业务逻辑中调用存储过程: ``` @Service public class MyService { @Autowired private MyStoredProcedureMapper myStoredProcedureMapper; public void callMyStoredProcedure() { String inputParam1 = "your_input_param1"; String inputParam2 = "your_input_param2"; Integer outputParam1 = null; String outputParam2 = null; myStoredProcedureMapper.callMyStoredProcedure(inputParam1, inputParam2, outputParam1, outputParam2); // TODO: use the output parameters returned by the stored procedure } } ``` 注意,在调用存储过程时,需要传入输入参数,并且需要定义输出参数的变量,以便在存储过程执行完成后读取输出参数的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sout快乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值