search

Home  >  Q&A  >  body text

Java正则表达式

一条sql如下:select * from user where id = #{user.id}
问题:用Java字符串的replaceAll将#{user.id}替换成具体指,但是具体正则表达式怎么写?

大家讲道理大家讲道理2892 days ago412

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:33:42

    sql.replaceAll("\\#\\{.*\\}", "111");

    ?

    reply
    0
  • 阿神

    阿神2017-04-18 09:33:42

    If you want to replace sql, just replace it directly. You can do it without regular expression. Normally, the #{user.id} that appears in your sql needs to be replaced with your variable value. If you use regular expression, the performance will be too low.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:33:42

    Just splice it together

    "select * from user where id = "+变量

    reply
    0
  • Cancelreply