SpringBoot实现SSM进行增删改查
首先设计一张用户表
新建一个SpringBoot项目
目录结构
在pom文件中添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kun</groupId>
<artifactId>SSM-SpringBoot-CRUD</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<!-- java版本 -->
<java.version>1.8</java.version>
<!-- 编译时的编码 -->
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<dependencies>
<!-- springboot启动类 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- springboot配置类 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<!-- springboot整合mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!--数据库连接驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 分页助手-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.7.5</version>
</dependency>
<!--引入web配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- servlet依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat的支持. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional><!-- optional=true,依赖不会传递,该项目依赖devtools;之后依赖myboot项目的项目如果想要使用devtools,需要重新引入 -->
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${maven.compiler.encoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置application.yml文件
server:
port: 8080
servlet:
jsp:
init-parameters:
development: true
contextPath: /springbootSSM
#spring
spring:
mvc:
view:
prefix: /WEB-INF/page/
suffix: .jsp
datasource:
url: jdbc:mysql://127.0.0.1:3306/j210303?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapperLocations: classpath:com/kun/mapper/*.xml
添加Application启动类
package com.kun;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication
@MapperScan("com.kun.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
依次添加entity、vo、mapper、service、controller
在entity包下添加User类
package com.kun.entity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class User {
private Integer id;
private String name;
private String pwd;
private String phone;
private String email;
private String address;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birth;
private Integer sex;
private String hobby;
private Integer job;
private String describes;
private String head;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd == null ? null : pwd.trim();
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone == null ? null : phone.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address == null ? null : address.trim();
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby == null ? null : hobby.trim();
}
public Integer getJob() {
return job;
}
public void setJob(Integer job) {
this.job = job;
}
public String getDescribes() {
return describes;
}
public void setDescribes(String describes) {
this.describes = describes == null ? null : describes.trim();
}
public String getHead() {
return head;
}
public void setHead(String head) {
this.head = head == null ? null : head.trim();
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", pwd='" + pwd + '\'' +
", phone='" + phone + '\'' +
", email='" + email + '\'' +
", address='" + address + '\'' +
", birth=" + birth +
", sex=" + sex +
", hobby='" + hobby + '\'' +
", job=" + job +
", describes='" + describes + '\'' +
", head='" + head + '\'' +
'}';
}
}
在mapper包下新建UserMapper接口
package com.kun.mapper;
import com.kun.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface UserMapper {
int deleteByPrimaryKey(Integer id);
int insert(User record);
int insertSelective(User record);
User selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(User record);
int updateByPrimaryKey(User record);
@Select("select * from user where name = #{name}")
User selectByName(String name);
@Select("select * from user")
List<User> selectAll();
List<User> selectByWherePage(@Param("name") String name, @Param("phone") String phone);
}
在service下添加UserService接口
package com.kun.service;
import com.github.pagehelper.PageInfo;
import com.kun.entity.User;
import java.util.List;
public interface UserService {
User selectByName(String name);
List<User> selectAll();
PageInfo selectByWherePage(String name, String phone, Integer pageNum, Integer pageSize);
User selectByPrimaryKey(Integer id);
Integer insert(User user);
Integer update(User user);
Integer deleteByPrimaryKey(Integer id);
}
在service包下添加impl包,在impl包下添加UserServiceImpl实现类
package com.kun.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.entity.User;
import com.kun.mapper.UserMapper;
import com.kun.service.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserMapper userMapper;
@Override
public User selectByName(String name) {
return userMapper.selectByName(name);
}
@Override
public List<User> selectAll() {
return userMapper.selectAll();
}
@Override
public PageInfo selectByWherePage(String name, String phone, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<User> users = userMapper.selectByWherePage(name,phone);
PageInfo<User> pageInfo = new PageInfo<User>(users);
return pageInfo;
}
@Override
public User selectByPrimaryKey(Integer id) {
return userMapper.selectByPrimaryKey(id);
}
@Override
public Integer insert(User user) {
return userMapper.insert(user);
}
@Override
public Integer update(User user) {
return userMapper.updateByPrimaryKeySelective(user);
}
@Override
public Integer deleteByPrimaryKey(Integer id) {
return userMapper.deleteByPrimaryKey(id);
}
}
在controller包下添加IndexController类和UserController类
IndexController类
package com.kun.controller;
import com.kun.entity.User;
import com.kun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
/**
* 一些声明信息
* Description: <br/>
* date: 2021/8/29 13:32<br/>
*
* @author kun<br />
* @since JDK 1.8
*/
@Controller
public class IndexController {
@Autowired
private UserService userService;
@RequestMapping("/login")
public String login(String name, String pwd, ModelMap map, HttpSession session){
User user = userService.selectByName(name);
if(user != null){
//有用户
if(user.getPwd().equals(pwd)){
session.setAttribute("user",user);
map.put("msg","登陆成功");
return "redirect:/user/list";
}else {
map.put("msg","密码错误");
return "index";
}
}else{
map.put("msg","用户不存在");
return "index";
}
}
}
UserController类
package com.kun.controller;
import com.github.pagehelper.PageInfo;
import com.kun.entity.User;
import com.kun.service.UserService;
import com.kun.vo.AjaxReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 一些声明信息
* Description: <br/>
* date: 2021/8/29 13:43<br/>
*
* @author kun<br />
* @since JDK 1.8
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/list")
public String list(String name,String phone
,@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum
,@RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize
, ModelMap map){
PageInfo pageInfo = userService.selectByWherePage(name, phone, pageNum, pageSize);
map.put("pageInfo",pageInfo);
map.put("name",name);
map.put("phone",phone);
return "user/list";
}
@RequestMapping("/toInsert")
public String toInsert(){
return "user/insert";
}
@RequestMapping("/toUpdate")
public String toUpdate(Integer id,ModelMap map){
User user = userService.selectByPrimaryKey(id);
map.put("record",user);
return "user/insert";
}
@RequestMapping("/insert")
@ResponseBody
public AjaxReturn insert(User user){
Integer i = userService.insert(user);
AjaxReturn ajaxReturn = new AjaxReturn();
if(i > 0){
//成功
ajaxReturn.setCode(1000);
ajaxReturn.setMsg("添加成功");
}else{
ajaxReturn.setCode(1001);
ajaxReturn.setMsg("添加失败");
}
return ajaxReturn;
}
@RequestMapping("/update")
@ResponseBody
public AjaxReturn update(User user){
Integer i = userService.update(user);
AjaxReturn ajaxReturn = new AjaxReturn();
if(i > 0){
//成功
ajaxReturn.setCode(1000);
ajaxReturn.setMsg("修改成功");
}else{
ajaxReturn.setCode(1001);
ajaxReturn.setMsg("修改失败");
}
return ajaxReturn;
}
@RequestMapping("/delete")
@ResponseBody
public AjaxReturn delete(Integer id){
Integer i = userService.deleteByPrimaryKey(id);
AjaxReturn ajaxReturn = new AjaxReturn();
if(i > 0){
//成功
ajaxReturn.setCode(1000);
ajaxReturn.setMsg("删除成功");
}else{
ajaxReturn.setCode(1001);
ajaxReturn.setMsg("删除失败");
}
return ajaxReturn;
}
}
在resources包下创建包 com/kun/mapper 创建UserMapping.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.kun.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.kun.entity.User">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="pwd" jdbcType="VARCHAR" property="pwd" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="address" jdbcType="VARCHAR" property="address" />
<result column="birth" jdbcType="DATE" property="birth" />
<result column="sex" jdbcType="INTEGER" property="sex" />
<result column="hobby" jdbcType="VARCHAR" property="hobby" />
<result column="job" jdbcType="INTEGER" property="job" />
<result column="describes" jdbcType="VARCHAR" property="describes" />
<result column="head" jdbcType="VARCHAR" property="head" />
</resultMap>
<sql id="Base_Column_List">
id, name, pwd, phone, email, address, birth, sex, hobby, job, describes, head
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByWherePage" resultType="com.kun.entity.User">
select
<include refid="Base_Column_List"></include>
from user
<where>
<if test="name != null and name != ''">
and name like concat('%',#{name},'%')
</if>
<if test="phone != null and phone != ''">
and name like concat('%',#{phone},'%')
</if>
</where>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from user
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.kun.entity.User">
insert into user (id, name, pwd,
phone, email, address,
birth, sex, hobby, job,
describes, head)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
#{birth,jdbcType=DATE}, #{sex,jdbcType=INTEGER}, #{hobby,jdbcType=VARCHAR}, #{job,jdbcType=INTEGER},
#{describes,jdbcType=VARCHAR}, #{head,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.kun.entity.User">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="pwd != null">
pwd,
</if>
<if test="phone != null">
phone,
</if>
<if test="email != null">
email,
</if>
<if test="address != null">
address,
</if>
<if test="birth != null">
birth,
</if>
<if test="sex != null">
sex,
</if>
<if test="hobby != null">
hobby,
</if>
<if test="job != null">
job,
</if>
<if test="describes != null">
describes,
</if>
<if test="head != null">
head,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="pwd != null">
#{pwd,jdbcType=VARCHAR},
</if>
<if test="phone != null">
#{phone,jdbcType=VARCHAR},
</if>
<if test="email != null">
#{email,jdbcType=VARCHAR},
</if>
<if test="address != null">
#{address,jdbcType=VARCHAR},
</if>
<if test="birth != null">
#{birth,jdbcType=DATE},
</if>
<if test="sex != null">
#{sex,jdbcType=INTEGER},
</if>
<if test="hobby != null">
#{hobby,jdbcType=VARCHAR},
</if>
<if test="job != null">
#{job,jdbcType=INTEGER},
</if>
<if test="describes != null">
#{describes,jdbcType=VARCHAR},
</if>
<if test="head != null">
#{head,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.kun.entity.User">
update user
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="pwd != null">
pwd = #{pwd,jdbcType=VARCHAR},
</if>
<if test="phone != null">
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
<if test="address != null">
address = #{address,jdbcType=VARCHAR},
</if>
<if test="birth != null">
birth = #{birth,jdbcType=DATE},
</if>
<if test="sex != null">
sex = #{sex,jdbcType=INTEGER},
</if>
<if test="hobby != null">
hobby = #{hobby,jdbcType=VARCHAR},
</if>
<if test="job != null">
job = #{job,jdbcType=INTEGER},
</if>
<if test="describes != null">
describes = #{describes,jdbcType=VARCHAR},
</if>
<if test="head != null">
head = #{head,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.kun.entity.User">
update user
set name = #{name,jdbcType=VARCHAR},
pwd = #{pwd,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR},
birth = #{birth,jdbcType=DATE},
sex = #{sex,jdbcType=INTEGER},
hobby = #{hobby,jdbcType=VARCHAR},
job = #{job,jdbcType=INTEGER},
describes = #{describes,jdbcType=VARCHAR},
head = #{head,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
webapp包下的文件
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>登录</h2>
<form id="loginform" action="${pageContext.request.contextPath}/login" method="post">
<label> 姓名</label><input name="name" value=""><br>
<label> 密码</label><input name="pwd" type="password" value=""><br>
<button>提交</button>
</form>
</body>
</html>
insert.jsp
<%--
Created by IntelliJ IDEA.
User: chair
Date: 2021/6/17
Time: 14:35
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>${requestScope.record == null ? '新增' : '编辑'}</h2>
<hr>
${sessionScope.user.name},你好!!
<hr>
<form id="edit" action="${pageContext.request.contextPath}${requestScope.record == null ? '/user/insert' : '/user/update'}" method="get">
<c:if test="${requestScope.record != null}">
<input type="hidden" name="id" value="${requestScope.record.id }">
</c:if>
<label>name</label><input name="name" value="${requestScope.record.name }"><br>
<label>pwd</label><input name="pwd" value="${requestScope.record.pwd }"><br>
<label>phone</label><input name="phone" value="${requestScope.record.phone }"><br>
<label>email</label><input name="email" value="${requestScope.record.email }"><br>
<label>sex</label>
<select name="sex">
<option value="">请选择</option>
<option value="1" ${requestScope.record.sex == 1 ? 'selected' : '' }>男</option>
<option value="2" ${requestScope.record.sex == 2 ? 'selected' : '' }>女</option>
</select>
<br>
<label>address</label><input name="address" value="${requestScope.record.address }"><br>
<label>birth</label><input id="birth" type="date" name="birth" value="<fmt:formatDate value="${requestScope.record.birth }" pattern="yyyy-MM-dd"></fmt:formatDate>"><br>
<button>提交</button>
</form>
<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
<script>
$("#edit").submit(function(){
var that = this;
$.ajax({
url:$(that).attr("action"),
type:$(that).attr("method"),
dataType:"json",
data:$(that).serialize(),
success:function (result) {
if(result.code == 1000){
layer.msg(result.msg,{
icon : 1,
time : 1000
},function () {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
parent.location.reload();
})
}else{
layer.msg(result.msg,{
icon:2
})
}
}
});
return false;
})
</script>
</body>
</html>
list.jsp
<%--
Created by IntelliJ IDEA.
User: chair
Date: 2021/6/17
Time: 14:35
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>列表</h2>
<%--<hr>--%>
<%--${sessionScope.user.name},你好!!<a href="${pageContext.request.contextPath}/logout">注销</a>--%>
<%--<hr>--%>
<form action="${pageContext.request.contextPath}/user/list" method="get">
<label>名字</label><input name="name" value="${requestScope.name}">
<label>手机</label><input name="phone" value="${requestScope.phone}">
<button>查询</button>
</form>
<hr>
<table border="1" cellspacing="0">
<tr>
<th>id</th>
<th>name</th>
<th>pwd</th>
<th>phone</th>
<th>邮件</th>
<th>地址</th>
<th>生日</th>
<th>操作
<a id="toEdit" href="${pageContext.request.contextPath}/user/toInsert">添加</a>
</th>
</tr>
<c:forEach items="${requestScope.pageInfo.list }" var="record">
<tr>
<td>${record.id }</td>
<td>${record.name }</td>
<td>${record.pwd }</td>
<td>${record.phone }</td>
<td>${record.email }</td>
<td>${record.sex == 1 ? '男' : '女'} </td>
<td><fmt:formatDate value="${record.birth }" pattern="yyyy-MM-dd"></fmt:formatDate></td>
<td>
<a class="toUpdate" href="${pageContext.request.contextPath}/user/toUpdate?id=${record.id }">编辑</a>
<a class="delete" href="${pageContext.request.contextPath}/user/delete?id=${record.id }">删除</a>
</td>
</tr>
</c:forEach>
</table>
<a href="${pageContext.request.contextPath}/user/list?pageNum=1&name=${requestScope.name}&phone=${requestScope.phone}">首页</a>
<c:if test="${ ! requestScope.pageInfo.isFirstPage}">
<a href="${pageContext.request.contextPath}/user/list?pageNum=${requestScope.pageInfo.prePage}&name=${requestScope.name}&phone=${requestScope.phone}">上一页</a>
</c:if>
<c:if test="${! requestScope.pageInfo.isLastPage}">
<a href="${pageContext.request.contextPath}/user/list?pageNum=${requestScope.pageInfo.nextPage}&name=${requestScope.name}&phone=${requestScope.phone}">下一页</a>
</c:if>
<a href="${pageContext.request.contextPath}/user/list?pageNum=${requestScope.pageInfo.pages}&name=${requestScope.name}&phone=${requestScope.phone}">末页</a>
${requestScope.pageInfo.pageNum}/${requestScope.pageInfo.pages} 总数据:${requestScope.pageInfo.total}
<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
<script>
$("#toEdit").click(function () {
var that = this
layer.open({
type: 2,
title: '添加操作',
maxmin: true,
shadeClose: true, //点击遮罩关闭层
area : ['800px' , '520px'],
content: $(this).attr("href")
});
return false;
})
$(".toUpdate").click(function () {
var that = this
layer.open({
type: 2,
title: '修改操作',
maxmin: true,
shadeClose: true, //点击遮罩关闭层
area : ['800px' , '520px'],
content: $(this).attr("href")
});
return false;
})
$(".delete").click(function () {
var that = this;
layer.confirm('确定删除吗?', {icon: 3, title:'提示'}, function(index){
//do something
$.ajax({
url:$(that).attr("href"),
type:"get",
dataType:"json",
success:function (result) {
if(result.code == 1000){
layer.msg(result.msg,{
icon : 1,
time : 1000
},function () {
parent.location.reload();
})
}else{
layer.msg(result.msg, {
icon : 2,
time : 1000
});
}
}
})
layer.close(index);
});
return false;
})
</script>
</body>
</html>
js下主要有jq包和校验包,layer包