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"; } }

相关推荐
paopaokaka_luck9 小时前
基于springboot3+vue3的企业考勤管理系统(部门树递归、Echarts图形化分析)
开发语言·spring boot·学习·echarts·mybatis·需求分析·代码规范
long3169 小时前
MySQL 学习练习(配套 01 入门资料)
数据库·学习·mysql
Pluchon9 小时前
Java个人综合项目——萌部落社区V2.0
java·python·spring·spring cloud·postman·idea
梦雨生生10 小时前
java开发工具(学习第一天)
java·开发语言·学习
数据库小学妹10 小时前
数据库等保三级和四级有什么区别?从访问控制到备份恢复的完整对比
数据库·安全·数据库安全·三级等保·等保合规·四级等保
她说可以呀10 小时前
Spring-ai-alibaba文生图
java·人工智能·spring
看浪的路人11 小时前
第3讲:手写第一个 MCP Server(Python SDK)
jvm·数据库·oracle
大眼、不聚光11 小时前
5.mysql--主从同步安装部署
数据库·mysql
Yan_chen66612 小时前
SQL-LABS_Less18-20实战攻略
数据库·sql·web安全·网络安全
oradh12 小时前
Oracle RAC OCR维护操作总结
数据库·oracle·ocr·rac ocr维护·ocr维护·vote disk