java - How to display entities on page? Getting instead [Entity of type ... with id: 1] -


my objective display random texts database onto web page. firstly, don't know why data aren't saved , why, instead of content [entity of type sec.helloweb.hellomessage id: n].

how display actual text/content of class , not "entity" on web page?

controller

@controller public class hellowebwithdatabasecontroller {      @autowired     private hellomessagerepository hellomessagerepository;      @requestmapping("/")     public string listall(model model) {          hellomessage mess = new hellomessage();         mess.setcontent("lol");         hellomessage mes = new hellomessage();         mes.setcontent("boo");         hellomessagerepository.save(mes);         hellomessagerepository.saveandflush(mess);         model.addattribute("message", hellomessagerepository.findall());         return "home";     } } 

hellomessagerepository

package sec.helloweb;  import org.springframework.data.jpa.repository.jparepository;  public interface hellomessagerepository extends jparepository<hellomessage, long> {  } 

hellomessage

@entity @table(name = "messages") public class hellomessage extends abstractpersistable<long> {      @column(name = "message")     private string content;      public string getcontent() {         return content;     }      public void setcontent(string content) {         this.content = content;     }  } 

home.html

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">     <head lang="en">         <meta charset="utf-8" />         <title>message</title>     </head>     <body>          <h2 th:text="${message}">testing</h2>             <p> testing ground</p>     </body> </html> 

http://i.imgur.com/7qtqs1j.png

the message attribute contains list, in order display each message content need iterate on message list:

<h2 th:each="item : ${message}" th:text="${item.content}"></h2>  

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -