类似于linux字符操作,如果被单引号包裹的字符不会被替换。
如果需要输出单引号,又要替换其中的字符,需要使用双单引号来表示单引号!
public class MessageFormatTest {
@Test
public void testPatternUncorrect(){
String UPDATE_SQL = "update t_handle_time a set a.start_time=sysdate where table_name = 'dynamic_{0}'";
Assert.assertEquals("update t_handle_time a set a.start_time=sysdate where table_name = dynamic_{0}",
MessageFormat.format(UPDATE_SQL, "test"));
}
@Test
public void testPatternCorrect(){
String UPDATE_SQL = "update t_handle_time a set a.start_time=sysdate where table_name = ''dynamic_{0}''";
Assert.assertEquals("update t_handle_time a set a.start_time=sysdate where table_name = 'dynamic_test'",
MessageFormat.format(UPDATE_SQL, "test"));
}
}