This may be an obvious answer to some of you, but I am trying to print out tables of data using string formatting. However, whenever I use \n
the code isn't printed on a new line in browser, but it is printed correctly to terminal using System.out.println
. This is basically what I have:
package com.example.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Test {
public static void main(String[] args) {
SpringApplication.run(Test.class, args);
}
@GetMapping("/problem")
public String problem(@RequestParam(value = "no", defaultValue = "0") int no){
String ret = "";
switch(no){
case 0:
ret += "all problems";
break;
case 1:
ret += ("Problem \n" +
"1");
break;
default:
break;
}
System.out.println(ret);
return ret;
}
}
I would like for "Problem" and "1" to print on separate lines, just as an example. Please let me know what I'm doing wrong, or if this is totally off-base then I'd like to know what I should look into.
Thanks!