search

Home  >  Q&A  >  body text

java - How to modify mybatis if it exists in the database, and add if it does not exist

I want to implement an insertion function. Before inserting, it is judged whether there is the same data as the key field in the database. If so, perform the modification operation. If not, perform the insert operation. I would like to ask for advice: Is there any way to do it? You can query and judge by yourself, can you complete the whole process by calling directly? Is there a similar method in mybatis?

给我你的怀抱给我你的怀抱2775 days ago603

reply all(3)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-17 10:06:15

    There is on duplicate key update in mysql, just create a unique index for the key field

    reply
    0
  • 黄舟

    黄舟2017-05-17 10:06:15

    mybatis应该没有这样的条件控制, 只能看数据库有没有类似的条件控制, 如果是oracle可以用merge into using (subquery) on (condition) when matched then update (update statement) when not matched then insert (insert statement)

    reply
    0
  • 怪我咯

    怪我咯2017-05-17 10:06:15

    Can I use mysql’s replace into?

    reply
    0
  • Cancelreply