How to show String new lines on gsp grails file?

后端 未结 3 1790
独厮守ぢ
独厮守ぢ 2021-01-28 02:51

I\'ve stored a string in the database. When I save and retrieve the string and the result I\'m getting is as following:

This is my new object

3条回答
  •  轮回少年
    2021-01-28 03:49

    Firstly make sure the string contains \n to denote line break. For example :

    String test = "This is first line. \n This is second line";
    

    Then in gsp page use:

    ${raw(test?.replace("\n", "
    "))}

    The output will be as:

    This is first line.
    This is second line.
    

提交回复
热议问题