boot客户管理系统--第一天:查询列表

教材来自于黑马出的<<Java EE企业级应用开发教程>>,根据最后一章项目实例,自己重新做的一个合同管理系统。

3.10:实现简单的列表查询功能,很多功能如增删改,page和数据字典功能都已删减。

 一、创建持久化类

在com.itheima.core.po包中,根据相应的数据库表创建客户持久类和数据字典持久化类:

package com.itheima.core.po;

import java.util.Date;

public class Hetong {
	private Integer ht_id;
	private String ht_name;
	private String payby;
	private Integer cust_id;
	private String cust_name;	
	private Double money;
	private Date create_time;
	private String state;
	public String getCust_name() {
		return cust_name;
	}
	public void setCust_name(String cust_name) {
		this.cust_name = cust_name;
	}
	public Integer getHt_id() {
		return ht_id;
	}
	public void setHt_id(Integer ht_id) {
		this.ht_id = ht_id;
	}
	public String getHt_name() {
		return ht_name;
	}
	public void setHt_name(String ht_name) {
		this.ht_name = ht_name;
	}
	public String getPayby() {
		return payby;
	}
	public void setPayby(String payby) {
		this.payby = payby;
	}
	public Integer getCust_id() {
		return cust_id;
	}
	public void setCust_id(Integer cust_id) {
		this.cust_id = cust_id;
	}
	public Double getMoney() {
		return money;
	}
	public void setMoney(Double money) {
		this.money = money;
	}
	public Date getCreate_time() {
		return create_time;
	}
	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
}

 

二、实现客户DAO层接口以及映射文件

在com.itheima.core.dao包中,创建HetongDao接口

package com.itheima.core.dao;

import java.util.List;

import com.itheima.core.po.Hetong;

public interface HetongDao {
	public List<Hetong> selectHetongList(Hetong ht);
	
	
}

创建对应的映射文件HetongDao.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.itheima.core.dao.HetongDao">
	
	<!-- 查询客户列表 -->
	<select id="selectHetongList" parameterType="Hetong"
		resultType="com.itheima.core.po.Hetong">
	SELECT
		ht_id,
		ht_name,
		payby,
		cust_name,
		money,
		create_time,
		state
	FROM
		hetong,
		customer
	WHERE
		hetong.cust_id = customer.cust_id
		
	</select>
	
</mapper>

四.创建数据字典以及客户的service层接口实现类

HetongService

package com.itheima.core.service;

import java.util.List;

import com.itheima.common.utils.Page;
import com.itheima.core.po.Hetong;

public interface HetongService {
	public List<Hetong> findHetongList();
}

HetongServiceImpl

package com.itheima.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.common.utils.Page;
import com.itheima.core.dao.HetongDao;
import com.itheima.core.po.Hetong;
import com.itheima.core.service.HetongService;

@Service("hetongService")
public class HetongServiceImpl implements HetongService {
	
	@Autowired
	private HetongDao hetongDao;
	public List<Hetong> findHetongList(){
		Hetong ht=new Hetong();
		
		List<Hetong> hetongs=
				hetongDao.selectHetongList(ht);
		
		return hetongs;
		
	}	
	
}

  注:这里HetongServiceImpl与源文件已经有很大区别。1.由于未使用Page类(如page,rows)且链接中无需传输数据字典的相应值(如 custSource、custIndustry、custLevel),函数参数为空        2.,直接返回List<Hetong>对象,未进行result的封装

 

五.创建客户控制器类CustomerController

package com.itheima.core.web.controller;

import java.util.List;

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 org.springframework.web.bind.annotation.RequestParam;

import com.itheima.core.po.Hetong;
import com.itheima.core.service.HetongService;

@Controller
public class HetongController {
	
	@Autowired
	private HetongService hetongService;
	
	@RequestMapping(value="/hetong/list.action")
	public String list(Model model){
		List<Hetong> hetongs=         //返回的是List<>
				hetongService.findHetongList();
		
		model.addAttribute("page",hetongs);
		
		return "hetong";
		
	}
	
}

这边相比原书里的代码,又有很大不同。1.函数传参值里只保留了model(注:得明确函数参数里的值表示链接里的值)

2.返回的是List<Hetong>而非Page<Hetong>

 

六.引入自定义标签文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itheima" uri="http://itheima.com/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>合同管理-BootCRM</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>hetong/list.action">BOOT合同管理系统 v2.0</a>
	</div>
	
    <!-- 合同列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">合同管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
			  <form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/hetong/list.action">
					<div class="form-group">
						<label for="hetongName">客户名称</label> 
						<input type="text" class="form-control" id="customerName" 
						                   value="${custName }" name="custName" />
					</div>
				</form>
			</div>
		</div>
		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">合同信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>合同名称</th>
								<th>支付方式</th>
								<th>客户名称</th>
								<th>金额</th>
								<th>创建日期</th>
								<th>审核状态</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page}" var="row">
								<tr>
									<td>${row.ht_id }</td>
									<td>${row.ht_name}</td>
									<td>${row.payby}</td>
									<td>${row.cust_name}</td>
									<td>${row.money}</td>
									<td>${row.create_time}</td>
								    <td>${row.state}</td>
									
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	
    
</body>
</html>

七.启动测试

链接至:http://localhost:8080/bootSSM/hetong/list.action

-->PAUSING ENDING

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值