SSM搭建测试

resources下创建mapper

1.AccountDao.xml

<mapper namespace="com.qcby.dao.AccountDao"> <select id="findAll" resultType="com.qcby.model.Account"> select * from account; </select> </mapper>

2.AccountDao接口

public interface AccountDao { public List<Account> findAll(); }

3.AccountServiceImpl

package com.qcby.service.servicelmpl; import com.qcby.dao.AccountDao; import com.qcby.model.Account; import com.qcby.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class AccountServicelmpl implements AccountService { @Autowired private AccountDao accountDao;//注入Dao层 //查询所有 @Override public List<Account> findAll() { System.out.println("业务层:查询所有"); return this.accountDao.findAll();//返回查询所有 } }

4.AccountController

加入for循环打印数据

package com.qcby.controller; import com.qcby.model.Account; import com.qcby.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; @Controller public class AccountController { //依赖注入 @Autowired private AccountService accountService; /** * 处理超链接发送出来的请求 * @param model * @return */ @RequestMapping(path = "/hello") public String sayHello(Model model){ System.out.println("入门方法执行了2..."); List<Account> accounts = accountService.findAll(); // 向模型中添加属性msg与值,可以在html页面中取出并渲染 /*加入for循环打印数据*/ for (Account account: accounts) { System.out.println(account.toString()); } model.addAttribute("msg","hello,SpringMVC"); // 配置了视图解析器后,写法 return "suc"; } }

相关推荐
提笔了无痕2 分钟前
RAG存储策略中.md格式的切片与存储怎么处理
数据库·ai·rag
yaoxin5211235 分钟前
419. 现代 Java IO 最佳实践 - 写入文本文件
java·windows·python
陳土9 分钟前
DuckDB精读——基于Getting started with DuckDB
数据库·oracle
雪宫街道10 分钟前
synchronized 锁的范围:对象锁、类锁与代码块锁
java·jvm·后端·面试
x***r15121 分钟前
linux安装 jdk-8u291-linux-x64.tar.gz 详细步骤(解压配置环境变量)
java
凯瑟琳.奥古斯特36 分钟前
数据库原理选择题精选
数据库·python·职场和发展
极光代码工作室1 小时前
基于SpringBoot的校园论坛系统
java·springboot·web开发·后端开发
曹牧1 小时前
C#:主线程能够捕获到子线程中的异常
开发语言·数据库·c#
XS0301061 小时前
Spring Bean 作用域 & 生命周期
java·后端·spring
NagatoYukee1 小时前
Spring Security基础部分学习
java·学习·spring