我搭建了一个ssm框架
现在想尝试把数据库获取到的信息在jsp页面打印出来
++++++++++++++++++++++
controller的代码,for循环那里是测试用的
return 那里,我知道是错的
- @RequestMapping("/all")
- public String findAll(Model model){
-
- List<User> result = userService.findAll();
- model.addAttribute("result", result);
- for(User user : result){
- System.out.println(user);
- }
- System.out.println("|||||");
- return "all";
- }
++++++++++++++++++
前端
- <form>
- <input id="kid" placeholder="请输入id" type="text"><br/><br/>
- <input id="username" placeholder="请输入name" type="text"><br/><br/>
- <input id="btn" value="查询结果" type="submit">
- </form><br/><br/>
-
- <h1>查询结果为:</h1><br/>
- <h1>${result}</h1>
+++++++++++++++++
看了网上的例程,它是跳转到另一个页面,然后通过${result}打印结果,
我现在想在原来的页面打印结果。
+++++++++++++++++++++++++++++++
更新:
+-+-+-+
前端:
- <body>
-
- <form>
- <input id="kid" placeholder="请输入id" type="text"><br/><br/>
- <input id="username" placeholder="请输入name" type="text"><br/><br/>
- <input id="btn" value="查询结果" type="submit">
- </form><br/><br/>
-
- <h1>查询结果为:</h1><br/>
- <h1><c:forEach items="${result}" var="item">
- <td>${item.kid}</td>
- <td>${item.username}</td>
- <td>${item.money}</td>
- </c:forEach>
- </h1>
-
- </body>
++++++++++++++
后端:
- @Controller
- @RequestMapping("/check")
- public class UserController {
- @Autowired
- private IUserService userService;
-
- @RequestMapping("/findall")
- private String findAll(Model model){
- System.out.println("表现层接收数据。。。");
-
- List<User> list = userService.findAll();
- System.out.println(list);
- model.addAttribute("list", list);
- return "lists";
- }
- }
++++++++++++
数据库:
++++++++++
结果