概述

居于ssm版本的crud跟多添加查询, 并带分页的demo

详细

一、功能展示

部门CRUD:

员工CRUD:

多条件查询与分页:

二、代码结构

三、操作过程

1>下载源码, 使用idea导入

2:>启动tomcat服务器

3>打开浏览器访问

http://localhost:8888/employee/list.do

四、关键代码

员工的表现层

package com.langfeiyes.ssm.web.controller;

import com.langfeiyes.ssm.domain.Employee;
import com.langfeiyes.ssm.query.EmployeeQueryObject;
import com.langfeiyes.ssm.query.QueryObject;
import com.langfeiyes.ssm.service.IDepartmentService;
import com.langfeiyes.ssm.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("employee")
public class EmployeeController {
@Autowired
private IEmployeeService employeeService; @Autowired
private IDepartmentService departmentService; @RequestMapping("list")
public String list(Model model, @ModelAttribute("qo") EmployeeQueryObject qo) throws Exception{ model.addAttribute("result", employeeService.query(qo));
model.addAttribute("currentMenu", "employee");
model.addAttribute("depts", departmentService.list()); return "employee/list";
} @RequestMapping("input")
public String input(Long id, Model model) throws Exception{ if(id != null){
model.addAttribute("entity", employeeService.get(id));
} model.addAttribute("depts", departmentService.list());
model.addAttribute("currentMenu", "employee");
return "employee/input";
} @RequestMapping("saveOrUpdate")
public String saveOrUpdate(Employee entity) throws Exception{ if(entity.getId() != null){
employeeService.update(entity);
}else{
employeeService.save(entity);
}
return "redirect:/employee/list.do";
} @RequestMapping("delete")
public String input(Long id) throws Exception{
if(id != null){
employeeService.delete(id);
}
return "redirect:/employee/list.do";
}
}

员工列表页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="/WEB-INF/views/common/header.jsp"%>
<style>
.page-head-line {
font-size: 30px;
text-transform: uppercase;
color: #337ab7;
font-weight: 800;
padding-bottom: 20px;
border-bottom: 2px solid #00a7ff;
margin-bottom: 10px;
}
</style>
<script type="text/javascript">
$(function(){
$("#pagination").twbsPagination({
totalPages:${result.totalPage},
visiblePages:${result.pageSize},
startPage:${qo.currentPage},
first:"首页",
prev:"上一页",
next:"下一页",
last:"尾页",
onPageClick:function(event,page){
$("#currentPage").val(page);
$("#searchForm").submit();
}
}); $("#query").click(function(){
$("#currentPage").val(1);
$("#searchForm").submit();
}); $("#cancel").click(function () {
$("#dept").val("-1");
$("#keyword").val("");
$("#currentPage").val(1);
$("#searchForm").submit();
});
});
</script>
</head>
<body> <div class="container " style="margin-top: 20px">
<div class="row">
<div class="col-sm-3">
<%@include file="/WEB-INF/views/common/menu.jsp"%>
</div>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-12">
<h1 class="page-head-line">员工管理</h1>
</div>
</div> <!--高级查询--->
<form class="form-inline" id="searchForm" action="/employee/list.do" method="post">
<input type="hidden" name="currentPage" id="currentPage" value="${qo.currentPage}">
<input type="hidden" name="pageSize" id="pageSize" value="${qo.pageSize}">
<div class="form-group">
<label for="keyword">关键字:</label>
<input type="text" class="form-control" id="keyword" name="keyword" placeholder="请输入姓名/邮箱" value="${qo.keyword}">
</div>
<div class="form-group">
<label for="dept">部门:</label>
<select class="form-control" id="dept" name="deptId">
<option value="-1">全部</option>
<c:forEach items="${depts}" var="d">
<option value="${d.id}" ${qo.deptId == d.id? 'selected':''}>${d.name}</option>
</c:forEach>
</select>
</div> <button type="button" id="query" class="btn btn-default">查询</button>
<button type="button" id="cancel" class="btn btn-default" >重置</button> <a class="btn btn-success" href="/employee/input.do">
<span class="glyphicon glyphicon-plus"></span>添加
</a> </form> <table class="table table-striped table-hover" >
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<%--<th>密码</th>--%>
<th>email</th>
<th>年龄</th>
<th>部门</th>
<th>操作</th>
</tr>
</thead>
<c:forEach items="${result.list}" var="e" varStatus="vs">
<tr>
<td>${vs.count}</td>
<td>${e.name}</td>
<%--<td>${e.password}</td>--%>
<td>${e.email}</td>
<td>${e.age}</td>
<td>${e.dept.name}</td>
<td>
<a class="btn btn-info btn-xs" href="/employee/input.do?id=${e.id}">
<span class="glyphicon glyphicon-pencil"></span>编辑
</a>
<a href="/employee/delete.do?id=${e.id}" class="btn btn-danger btn-xs" >
<span class="glyphicon glyphicon-trash"></span>删除
</a>
</td>
</tr>
</c:forEach>
</table>
<div style="text-align: center;">
<ul id="pagination" class="pagination"></ul>
</div>
</div>
</div>
</div>
</body>
</html>

总配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- -1: 配置扫描包 -->
<context:component-scan base-package="com.langfeiyes.ssm"/> <!--0:配置数据源-->
<context:property-placeholder location="classpath:db.properties" system-properties-mode="NEVER"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--1:配置SqlSessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--1.1:配置数据源-->
<property name="dataSource" ref="dataSource"/>
<!--1.2:配置mybatis.xml配置文件-->
<property name="configLocation" value="classpath:mybatis.xml"/>
<!--1.3:配置mapper配置文件-->
<property name="mapperLocations" value="classpath:com/langfeiyes/ssm/mapper/*Mapper.xml"/>
<!--1.4:配置别名-->
<property name="typeAliasesPackage" value="com.langfeiyes.ssm.domain"/>
</bean> <!---2:配置mapper接口实现类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.langfeiyes.ssm.mapper"/>
</bean> <!--3:配置事务-->
<!--3w: who what when : I has dinner last night -->
<!--3.1:what 什么增强-->
<bean id="txManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!--3.2:when-->
<tx:advice id="txAdivce" transaction-manager="txManger">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="list*" read-only="true"/>
<tx:method name="check*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!--3.3:who-->
<aop:config>
<aop:pointcut id="pc" expression="execution( * com.langfeiyes.ssm.service.*Service.*(..))"/>
<aop:advisor advice-ref="txAdivce" pointcut-ref="pc"/>
</aop:config>
</beans>

五、其他补充

暂时没有

注:本文著作权归作者,由demo大师发表,拒绝转载,转载需要作者授权

具有SSM框架的CRUD与多条件查询的更多相关文章

  1. mybatis+maven+父子多模块进行crud以及动态条件查询

    使用IDEA创建maven项目,File→New→Project→maven→Next→填写GroupId(例:com.zyl)和ArtifactId(mybatis-demo-parent)→Nex ...

  2. java实现ssm框架的crud

    上一篇博客写了通过表名获取数据库表结构的demo,现在我以此为基础实现了一个简单的通过数据库表结构生成对应的实体,通过读取mapper接口文件.mapping映射文件. service映射文件模板,替 ...

  3. 【前端VUE】【后端SSM】 记录一次多条件查询状态下加载极慢的解决思路和解决方案

    最近在开发一个Online Judge系统,其中有一个“挑战模式”模块,如图所示 由于是第一次使用ECharts做开发,所以完成整个模块的过程也是边写边学了,记录一下问题: 遇到的问题:在最开始进行测 ...

  4. SSM框架三分钟搞定分页查询

    使用的国产第三方jar   pagehelper 里面的基本属性值 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 ...

  5. ssm框架的搭建实现CRUD的操作

    最近在开发公司的一个系统,系统的框架是用ssm的框架搭建的,当然和这次写博客的不一样,它拥有很多的配置文件,企业级的开发所需要的配置文件是非常繁琐的,今天记录一下一个简单的SSM框架的搭建和实现一个C ...

  6. ssm 框架实现增删改查CRUD操作(Spring + SpringMVC + Mybatis 实现增删改查)

    ssm 框架实现增删改查 SpringBoot 项目整合 一.项目准备 1.1 ssm 框架环境搭建 1.2 项目结构图如下 1.3 数据表结构图如下 1.4 运行结果 二.项目实现 1. Emplo ...

  7. Spring SSM 框架

    IDEA 整合 SSM 框架学习 http://www.cnblogs.com/wmyskxz/p/8916365.html 认识 Spring 框架 更多详情请点击这里:这里 Spring 框架是 ...

  8. java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化

    一.ssm框架搭建 1.1创建项目 新建项目后规划好各层的包. 1.2导入包 搭建SSM框架所需包百度云链接:http://pan.baidu.com/s/1cvKjL0 1.3整合spring与my ...

  9. SSM框架Web程序的流程(Spring SpringMVC Mybatis)

    SSM框架的Web程序主要用到了三个技术: Spring:用到了注解和自动装配,就是Spring的两个精髓IOC(反向控制)和 AOP(面向切面编程). SpringMVC:用到了MVC模型,将逻辑代 ...

随机推荐

  1. 利用SharpZipLib对字符串进行压缩和解压缩

    添加对ICSharpCode.SharpZipLib的引用. using ICSharpCode.SharpZipLib.BZip2; /// <summary> /// 压缩 /// & ...

  2. VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) D. Running with Obstacles 贪心

    D. Running with Obstacles 题目连接: http://www.codeforces.com/contest/637/problem/D Description A sports ...

  3. poj 3624 Charm Bracelet 背包DP

    Charm Bracelet Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ...

  4. Caused by: java.net.UnknownHostException: localhost.localdomain: localhost.localdomain的问题解决

    在hosts文件增加如下配置即可,下面的方法适合上面提示的错误,无论是Tomcat问题还是MongoDB等等的问题都可以完美解决. vi /etc/hosts 127.0.0.1 localhost ...

  5. Registering DLL and ActiveX controls from code

    http://delphi.about.com/od/windowsshellapi/l/aa040803a.htm How to register (and unregister) OLE cont ...

  6. stdafx.h是什么用处, stdafx.h、stdafx.cpp的作用

    http://blog.csdn.net/songkexin/article/details/1750396 stdafx.h头文件的作用 Standard Application Fram Exte ...

  7. nib 加载过程分析以及对File’s Owner的理解

    nib loading的过程,这个是app文档里面有说到资源编程指南 1.  It loads the contents of the nib file and any referenced reso ...

  8. 数学图形(2.14)Spherical helix曲线

    从http://mathworld.wolfram.com/SphericalHelix.html上找到如下一些关于该曲线的说明,不过似乎他的公式和我的脚本完全是两个东西.. The tangent  ...

  9. 高版本teamview的成为被控制端时,会一直出现“正在初始化显示参数”

    故障现象:高版本teamview的成为被控制端时,控制端会一直出现“正在初始化显示参数”,如图是teamview13作为服务器端,控制端连接一直出现这个情况 做好的解决办法: 把被控制端的teamvi ...

  10. 正向代理/反向代理理解、Nginx概述、安装及配置详解

    一.Nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理, ...