springboot 整合mybatis 基于注解开发 传入对象

spring boot 整合 mybatis 基于注解开发 传入对象的时候。

当传入的对象的属性没赋值的时候,也就是为null  就会报错如下。

在写sql的时候指定 jdbcType  就可以了

@Insert("insert into tb_operation_record(cnickid) values(#{cnickid,jdbcType=VARCHAR})")
int addPerson (Person p); 

nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException

java.sql.SQLException: 无效的列类型: 1111
    at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3900)


JDBC Type    Java Type  
CHAR                 String  
VARCHAR              String  
LONGVARCHAR          String  
NUMERIC              java.math.BigDecimal  
DECIMAL              java.math.BigDecimal  
BIT                  boolean  
BOOLEAN              boolean  
TINYINT              byte  
SMALLINT             short  
INTEGER              int  
BIGINT               long  
REAL                 float  
FLOAT                double  
DOUBLE               double  
BINARY               byte[]  
VARBINARY            byte[]  
LONGVARBINARY        byte[]  
DATE                 java.sql.Date  
TIME                 java.sql.Time  
TIMESTAMP            java.sql.Timestamp  
CLOB                 Clob  
BLOB                 Blob  
ARRAY                Array

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合MyBatis可以使用注解开发,以下是基本的步骤: 步骤1:添加依赖 在pom.xml文件中添加Spring Boot和MyBatis的依赖: ```xml <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <!-- 数据库驱动,根据自己使用的数据库选择对应的驱动 --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> </dependencies> ``` 步骤2:配置数据源 在application.properties或application.yml文件中配置数据库连接信息: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver ``` 步骤3:创建实体类和Mapper接口 创建对应的实体类和Mapper接口,使用注解指定SQL语句和参数映射关系。例如: ```java public interface UserMapper { @Select("SELECT * FROM users WHERE id = #{id}") User findById(@Param("id") Long id); // 其他方法... } ``` 步骤4:创建MyBatis配置类 创建一个MyBatis的配置类,用于注入Mapper接口。例如: ```java @Configuration @MapperScan("com.example.mapper") public class MyBatisConfig { } ``` 步骤5:运行Spring Boot应用程序 在启动类上添加`@SpringBootApplication`注解,然后运行Spring Boot应用程序。 现在,你可以在其他类中注入并使用Mapper接口了。例如: ```java @Service public class UserService { private final UserMapper userMapper; public UserService(UserMapper userMapper) { this.userMapper = userMapper; } public User findUserById(Long id) { return userMapper.findById(id); } // 其他方法... } ``` 以上就是使用注解开发的Spring Boot整合MyBatis的基本步骤。你可以根据实际需求进行扩展和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值