ITeye博客

MessageFormat的pattern中含有单引号的问题

winse · 2013-03-18 09:42 · java · 编程语言 · Markdown

类似于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"));
	}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。