Store data in action, the code is as follows:
@Controller // Add to IOC container//@RequestMapping(value="/topic") public class TopicAction { @Resource(name = "topicServiceImpl") private TopicService topicService; /** * Home page display */ @RequestMapping(value="/index") public String index(Model model){ List<Topic> topicList = (); ("topics", topicList); ("Encapsulatedmodel="+model); return ""; } }
How to get data in jsp page?
First, we need to figure out what type of data we passed? Then parse the data and display the data.
Use the el expression ${topics} to obtain the data as follows:
Copy the codeThe code is as follows:
[Topic [id=0, time=2016-12-05 08:29:02.0, title=html Baidu Encyclopedia, contents=null, isTuiJian=0, good=15, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-05 08:29:04.0, title=JSP introduction, contents=null, isTuiJian=0, good=2, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-05 08:28:59.0, title=test, contents=null, isTuiJian=0, good=3, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-05 08:28:52.0, title=test2, contents=null, isTuiJian=0, good=0, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-13 09:29:30.0, title=classic songs, contents=null, isTuiJian=0, good=3, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-05 08:28:56.0, title=test4, contents=null, isTuiJian=0, good=0, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-05 09:02:19.0, title=tst2, contents=null, isTuiJian=0, good=30, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-08 14:45:47.0, title=Minecraft, contents=null, isTuiJian=0, good=3, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-08 19:39:15.0, title=Your world, contents=null, isTuiJian=0, good=0, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-09 14:17:17.0, title=test, contents=null, isTuiJian=0, good=0, user=null, replyList=[], type=null], Topic [id=0, time=2016-12-09 14:19:21.0, title=My contents=null, isTuiJian=0, good=0, user=null, replyList=[], type=null]]
Obviously not the data we want.
Use this ${topics[1].title} to get the data as follows:
Here you can add a for loop outside ${topics[1].title} to output each piece of data.
Here is my personal conclusion.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.