Java中字符串中的转义引号

Java中字符串中的转义引号,java,Java,我在下面的字符串中成功地转义了引号 <Test sample=\"5\" couponCode=\"\"><WeatherApp>" + "<Temp><UpdateInfo><WeatherDetail>" + "<Release batchNo=\"\"/>" + "</WeatherDetail></UpdateInfo></

我在下面的字符串中成功地转义了引号

        <Test sample=\"5\" couponCode=\"\"><WeatherApp>"
        + "<Temp><UpdateInfo><WeatherDetail>"
        + "<Release batchNo=\"\"/>"
        + "</WeatherDetail></UpdateInfo></Temp>"    
        + "</WeatherApp></Test>
”
+ ""
+ ""
+ ""    
+ "
我的问题是,假设我想用DTO.getVal()替换这个字符串中的一个值,我该怎么做

例如-

        <Test sample="dto.getVal()" couponCode=\"\"><WeatherApp>"
        + "<Temp><UpdateInfo><WeatherDetail>"
        + "<Release batchNo=\"\"/>"
        + "</WeatherDetail></UpdateInfo></Temp>"    
        + "</WeatherApp></Test>
”
+ ""
+ ""
+ ""    
+ "

我已经用多种方法做了这件事,到目前为止还没有成功。你能告诉我吗?

只需使用字符串连接:
\”“+dto.getVal()+“\”
“
+ ""
+ ""
+ ""    
+ "

使用+连接字符串和变量。执行以下操作:sample=“+dto.getVal()+”优惠券
 <Test sample=\""+dto.getVal()+"\" couponCode=\"\"><WeatherApp>"
        + "<Temp><UpdateInfo><WeatherDetail>"
       + "<Release batchNo=\"\"/>"
       + "</WeatherDetail></UpdateInfo></Temp>"    
        + "</WeatherApp></Test>