4.Eclipse+SSM+查所有

环境搭建参考https://blog.csdn.net/YKYZSYA/article/details/108000053
登录参考https://blog.csdn.net/YKYZSYA/article/details/108000392
对象封装参考https://blog.csdn.net/YKYZSYA/article/details/108070188
Dao层接口层 PersonDao.java(是一个接口)

 //查询所有方法
public List<Person> queryall();

Dao层mapper层 personmapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ly.dao.PersonDao">
   <!--因为是查两个表,所以需要配置resultMap -->
     <resultMap type="person" id="personmap">
  <id column="pid" property="pid" />
  <result column="pname" property="pname" />
  <result column="phone" property="phone" />
  <result column="idcard" property="idcard" />
  <result column="temperature" property="temperature" />
  <result column="sex" property="sex" />
  <association property="userinfo" javaType="Userinfo">
   <id column="uid" property="uid" />
      <result column="name" property="name" />
      <result column="pwd" property="pwd" />
  </association>
 </resultMap>
  <!-- id对应的是Dao层接口的方法名称 resultMap和上边配置的id保持一致-->
 <select id="queryall" resultMap="personmap">
 select * from userinfo,Person where userinfo.uid=Person.uid
 </select>
  </mapper>

service层接口层 PersonSer.java(是一个接口)

public List<Person> queryall();

service层实现层 PersonSerImpl.java

@Service
public class PersonSerImpl implements PersonSer {
     @Autowired
     PersonDao personDao;
     @Override
 public List<Person> queryall() {
  // TODO Auto-generated method stub
  return personDao.queryall();
 }
}

Controller层

@Controller
public class PersonCon {
@Autowired
PersonSer personSer;
   //和登录后调用查所有的方法路径保持一致
   @RequestMapping("queryall")
   public ModelAndView queryall() {
    ModelAndView mv=new ModelAndView("queryall.jsp");
    List<Person> list = personSer.queryall();
    mv.addObject("list",list);
    return mv;
   }
}

前台Jsp显示层
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
是用来遍历集合使用C:标签的

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1px solid red" cellpadding="0px" cellspacing="0px" align="center">
<tr><th colspan="6" align="left"><a href="add.jsp">新增</a></th></tr>
  <tr>
  <th>姓名</th>
  <th>性别</th>
  <th>手机</th>
  <th>身份证</th>
  <th>体温</th>
  <th>操作</th>
  </tr>
<c:forEach items="${list }" var="l">
  <tr>
   <!-- 和封装的对象变量名保持一致-->
  <td>${l.pname }</td>
   <td>${l.sex }</td>
    <td>${l.phone }</td>
    <td>${l.idcard }</td>
     <td>${l.temperature }</td>
     <td>
<a href="queryone?pid=${l.pid }">修改</a>
<a href="shan?pid=${l.pid }">删除</a>
     </td>
  </tr>
</c:forEach>
</table>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值