学堂 学堂 学堂公众号手机端

mybatis中timestamp赋值的方法是什么

lewis 3年前 (2022-03-04) 阅读数 5 #技术

在MyBatis中,可以使用#{parameterName, jdbcType=TIMESTAMP}的方式来给timestamp类型的参数赋值。例如:

<insert id="insertUser" parameterType="User">
    INSERT INTO user (id, username, created_at) 
    VALUES (#{id}, #{username}, #{createdAt, jdbcType=TIMESTAMP})
</insert>

在上面的例子中,createdAt是一个java.sql.Timestamp类型的属性,通过jdbcType=TIMESTAMP指定了它的数据类型为TIMESTAMP。当使用该参数进行插入操作时,MyBatis会自动将java.sql.Timestamp类型的值转换为数据库中的TIMESTAMP类型。


版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门