121 项目 034 笔记向 easyui

Stella981
• 阅读 620

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.laolang.jc.one</groupId>
    <artifactId>jcone-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <!-- 集中定义依赖版本号 -->
    <properties>
        <!-- test -->
        <junit.version>4.10</junit.version>
        <hamcrest.version>1.3</hamcrest.version>


        <!-- java ee -->
        <javaee-api.version>7.0</javaee-api.version>
        <servlet-api.version>3.0.1</servlet-api.version>
        <persistence-api.version>1.0</persistence-api.version>
        <jstl.version>1.2</jstl.version>
        <standard.version>1.1.2</standard.version>


        <!-- spring -->
        <spring.version>4.2.0.RELEASE</spring.version>

        <!-- mybatis  -->
        <mybatis.version>3.2.8</mybatis.version>
        <mybatis.spring.version>1.2.2</mybatis.spring.version>
        <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
        <pagehelper.version>4.0.3</pagehelper.version>
        <tk.mapper.version>3.2.2</tk.mapper.version>


        <mysql.version>5.1.32</mysql.version>

        <!-- log -->
        <slf4j.version>1.7.12</slf4j.version>
        <logback.version>1.1.3</logback.version>
        <logback.ext.version>0.1.2</logback.ext.version>

        <!-- json -->
        <jackson.version>2.4.2</jackson.version>
        <jackson.mapper.version>1.9.13</jackson.mapper.version>

        <!-- google -->
        <gson.version>2.2.2</gson.version>
        <guava.version>18.0</guava.version>

        <!-- alibaba -->
        <druid.version>1.0.12</druid.version>

        <!-- apache -->
        <httpclient.version>4.5</httpclient.version>
        <commons-lang3.version>3.3.2</commons-lang3.version>
        <commons-io.version>2.5</commons-io.version>
        <commons-fileupload.version>1.3.2</commons-fileupload.version>
        <commons-net.version>3.3</commons-net.version>
        <commons-codec.version>1.9</commons-codec.version>

        <!-- beetl -->
        <beetl.version>2.7.5</beetl.version>

        <!-- jedis -->
        <jedis.version>2.6.3</jedis.version>

        <!-- JSR 303 -->
        <hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
        <validator-api.version>1.1.0.Final</validator-api.version>

        <joda-time.version>2.5</joda-time.version>

        <cglib.versoin>3.1</cglib.versoin>

        <quartz.versoin>2.2.1</quartz.versoin>

        <spring-rabbit.version>1.4.0.RELEASE</spring-rabbit.version>

    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- test -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-all</artifactId>
                <version>${hamcrest.version}</version>
                <scope>test</scope>
            </dependency>

            <!-- java ee-->
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>${javaee-api.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>${servlet-api.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>1.0</version>
            </dependency>
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>${jstl.version}</version>
            </dependency>
            <dependency>
                <groupId>taglibs</groupId>
                <artifactId>standard</artifactId>
                <version>${standard.version}</version>
            </dependency>

            <!-- Spring -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <!-- JSR 303 -->
            <dependency>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>${validator-api.version}</version>
            </dependency>

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>${hibernate-validator.version}</version>
            </dependency>


            <!-- beetl -->
            <dependency>
                <groupId>com.ibeetl</groupId>
                <artifactId>beetl</artifactId>
                <version>${beetl.version}</version>
            </dependency>

            <!-- Mybatis -->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>${mybatis.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>${mybatis.spring.version}</version>
            </dependency>
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>${pagehelper.version}</version>
            </dependency>
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper</artifactId>
                <version>${tk.mapper.version}</version>
            </dependency>


            <!-- MySql -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>

            <!-- alibaba -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${druid.version}</version>
            </dependency>

            <!-- Jackson Json处理工具包 -->
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
                <version>${jackson.mapper.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>${jackson.version}</version>
            </dependency>

            <!-- google -->
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>${gson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
            </dependency>

            <!-- apache -->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang3.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>${commons-io.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>${commons-fileupload.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>${httpclient.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
                <version>${commons-net.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>${commons-codec.version}</version>
            </dependency>

            <!-- logback -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>${logback.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${logback.version}</version>
            </dependency>
            <dependency>
                <groupId>org.logback-extensions</groupId>
                <artifactId>logback-ext-spring</artifactId>
                <version>${logback.ext.version}</version>
            </dependency>


            <!-- 时间操作组件 -->
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>${joda-time.version}</version>
            </dependency>

            <!-- jedis -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>${jedis.version}</version>
            </dependency>

            <!-- 动态代理 -->
            <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
                <version>${cglib.versoin}</version>
            </dependency>

            <!-- quartz -->
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
                <version>${quartz.versoin}</version>
            </dependency>

            <!-- RabbitMQ -->
            <dependency>
                <groupId>org.springframework.amqp</groupId>
                <artifactId>spring-rabbit</artifactId>
                <version>${spring-rabbit.version}</version>
            </dependency>


        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- 资源文件拷贝插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- java编译插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!-- 配置Tomcat插件 -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

java

bean

BaseDomain

package com.laolang.jc.one.manage.domain;

import java.util.Date;

/**
 * 实体类基类
 * @author laolang2016
 * @version 1.0
 */
public class BaseDomain {

    /**
     * 创建时间
     */
    protected Date created;

    /**
     * 最后更新时间
     */
    protected Date updated;

    public Date getCreated() {
        return created;
    }
    public void setCreated(Date created) {
        this.created = created;
    }
    public Date getUpdated() {
        return updated;
    }
    public void setUpdated(Date updated) {
        this.updated = updated;
    }
}

Employee

package com.laolang.jc.one.manage.domain;

import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

import javax.persistence.*;

/**
 * 员工实体类
 * @author laolang2016
 * @version 1.0
 */
@Table(name = "tb_employee")
public class Employee extends BaseDomain {

    public Employee() {
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", loginNumber='" + loginNumber + '\'' +
                ", name='" + name + '\'' +
                ", sex=" + sex +
                ", pwd='" + pwd + '\'' +
                ", birthday=" + birthday +
                ", city='" + city + '\'' +
                ", phone='" + phone + '\'' +
                ", lead=" + lead +
                ", created=" + created +
                ", updated=" + updated +
                '}';
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public boolean isLead() {
        return lead;
    }

    public void setLead(boolean lead) {
        this.lead = lead;
    }

    public String getLoginNumber() {
        return loginNumber;
    }

    public void setLoginNumber(String loginNumber) {
        this.loginNumber = loginNumber;
    }

    /**
     * ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 登陆账号,也是编辑
     */
    @Column(name = "login_number")
    private String loginNumber;

    /**
     * 员工姓名
     */
    private String name;

    /**
     * 员工性别 <br />
     * true : 男 <br />
     * false : 女
     */
    private boolean sex;

    /**
     * 登陆密码
     */
    private String pwd;

    /**
     * 出生日期
     */
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date birthday;

    /**
     * 居住地(城市)
     */
    private String city;

    /**
     * 办公室电话
     */
    private String phone;

    /**
     * 是否领导 <br />
     * true : 是 <br />
     * false : 不是
     */
    private boolean lead;
}

Mapper

package com.laolang.jc.one.manage.mapper;


import com.laolang.jc.one.manage.domain.Employee;
import tk.mybatis.mapper.common.Mapper;

public interface EmployeeMapper extends Mapper<Employee> {
}

service

BaseService

package com.laolang.jc.one.manage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.laolang.jc.one.manage.domain.BaseDomain;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

public abstract class BaseService<T extends BaseDomain> {

//    不使用泛型注入的方法
//    public abstract Mapper<T> getMapper();

    @Autowired
    protected Mapper<T> mapper;

    /**
     * 根据条件查询记录数
     * @param t
     * @return
     */
    public Integer findCountByWhere( T t){
        return mapper.selectCount(t);
    }

    /**
     * 根据 ID 查询
     *
     * @param id id
     * @return
     */
    public T findById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }


    /**
     * 查询所有
     *
     * @return
     */
    public List<T> findAll() {
        return mapper.selectAll();
    }

    /**
     * 根据条件查询一个
     *
     * @param t
     * @return
     */
    public T findOne(T t) {
        return mapper.selectOne(t);
    }

    /**
     * 根据条件查询列表
     *
     * @param t
     * @return
     */
    public List<T> findListByWhere(T t) {
        return mapper.select(t);
    }

    /**
     * 带条件的分页查询
     *
     * @param page
     * @param rows
     * @param t
     * @return
     */
    public PageInfo<T> findPageListByWhere(Integer page, Integer rows, T t) {
        PageHelper.startPage(page, rows);
        List<T> list = mapper.select(t);
        return new PageInfo<T>(list);
    }

    /**
     * 插入数据,null的属性也会保存,不会使用数据库默认值
     *
     * @param t
     * @return
     */
    public Integer save(T t) {
        t.setCreated(new Date());
        t.setUpdated(t.getCreated());
        return mapper.insert(t);
    }

    /**
     * 插入数据,null的属性不会保存,会使用数据库默认值
     *
     * @param t
     * @return
     */
    public Integer saveSelective(T t) {
        t.setCreated(new Date());
        t.setUpdated(t.getCreated());
        return mapper.insertSelective(t);
    }


    /**
     * 根据主键更新实体全部字段,null值会被更新
     *
     * @param t
     * @return
     */
    public Integer updateByPrimaryKey(T t) {
        t.setUpdated(new Date());
        return mapper.updateByPrimaryKey(t);
    }

    /**
     * 根据主键更新属性不为null的值
     *
     * @param t
     * @return
     */
    public Integer updateByPrimaryKeySelective(T t) {
        t.setUpdated(new Date());
        return mapper.updateByPrimaryKeySelective(t);
    }

    /**
     * 根据ID删除
     *
     * @param id
     * @return
     */
    public Integer deleteById(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    /**
     * 批量删除
     *
     * @param clazz    要删除的类
     * @param property ID 名称
     * @param values   要删除的ID列表
     * @return
     */
    public Integer deleteByIds(Class<T> clazz, String property, List< Object> values) {
        Example example = new Example(clazz);
        example.createCriteria().andIn(property, values);
        return mapper.deleteByExample(example);
    }

    /**
     * 根据条件删除
     *
     * @param t
     * @return
     */
    public Integer deleteByWhere(T t) {
        return mapper.delete(t);
    }




}

EmployeeService

package com.laolang.jc.one.manage.service;


import com.laolang.jc.one.manage.domain.Employee;
import org.springframework.stereotype.Service;

@Service
public class EmployeeService extends BaseService<Employee> {


}

pojo

package com.laolang.jc.one.manage.web.pojo;


import java.util.List;

public class EasyUIGridPojo<T> {

    public EasyUIGridPojo() {
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    private List<T> rows;

    private Long total;
}

controller

package com.laolang.jc.one.manage.web.web;

import com.github.pagehelper.PageInfo;
import com.laolang.jc.one.manage.domain.Employee;
import com.laolang.jc.one.manage.service.EmployeeService;
import com.laolang.jc.one.manage.web.pojo.EasyUIGridPojo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("employee")
@Controller
public class EmployeeController {



    @Autowired
    private EmployeeService employeeService;

    /**
     * 查询
     * @param page 第几页
     * @param rows 每页显示多少条
     * @return {@link com.laolang.jc.one.manage.web.pojo.EasyUIGridPojo} 实例
     */
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResponseEntity<EasyUIGridPojo<Employee>> list(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "rows", defaultValue = "30")
    Integer rows) {
        PageInfo<Employee> pageInfo = employeeService.findPageListByWhere(page,rows,null);
        EasyUIGridPojo<Employee> gridPojo = new EasyUIGridPojo<>();
        gridPojo.setTotal(pageInfo.getTotal());
        gridPojo.setRows(pageInfo.getList());
        return ResponseEntity.ok(gridPojo);
    }

    /**
     * 批量删除员工信息
     * @param ids id字符串[1-2-3]
     * @return
     * 400 : 请求参数有误 <br />
     * 204 : 删除成功 <br />
     * 500 : 服务器内部
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public ResponseEntity<Void> delete( @RequestParam(value = "ids") String ids ){
        String[] idArray = StringUtils.split(ids,'-');
        if ( null == idArray || 0 == idArray.length ){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
        }

        try{
            if( 1 == idArray.length ){
                employeeService.deleteById(Long.parseLong(idArray[0]));
            }else{
                List<Object> idList = new ArrayList<>();
                for (String s : idArray) {
                    idList.add(Long.parseLong(s));
                }
                employeeService.deleteByIds(Employee.class,"id",idList);
            }
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }catch (Exception e){
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    /**
     * 添加员工信息
     * @param employee 员工
     * @return
     * 201 : 新增成功 <br />
     * 500 : 服务器内部错误
     */
    @RequestMapping(value = "save",method = RequestMethod.POST)
    public ResponseEntity<Void> save( Employee employee ){
        try{
            System.out.println(employee);
            employee.setPwd("123456");
            employeeService.saveSelective(employee);
            return ResponseEntity.status(HttpStatus.CREATED).build();
        }catch (Exception e){
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    /**
     * 更新员工信息
     * @param employee
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public ResponseEntity<Void> update( Employee employee ){
        try{
            System.out.println(employee);
            employeeService.updateByPrimaryKeySelective(employee);
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }catch (Exception e){
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
}

page

index.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>index</title>
    <link rel="stylesheet" type="text/css" href="https://my.oschina.net/assets/jquery-easyui-1.4.5/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="https://my.oschina.net/assets/jquery-easyui-1.4.5/themes/icon.css" />

</head>
<body class="easyui-layout">

<div data-options="region:'north',title:'header',split:true,noheader:true" style="height:45px;">
    banner
</div>
<!--<div data-options="region:'south',title:'footer',split:true,noheader:true" style="height:35px;line-height:30px;text-align:center;">-->
    <!--copyRight-->
<!--</div>-->
<div data-options="region:'west',title:'导航',split:true,iconCls:'icon-world'" style="width:180px;padding:10px;">
    <ul id="nav" class="easyui-tree" data-options="lines:true,animate:true">
        <li>
            <span>员工管理</span>
            <ul>
                <li>员工查询</li>
            </ul>
        </li>
        <li>
            <span>消息管理</span>
            <ul>
                <li>消息查询</li>
            </ul>
        </li>
    </ul>
</div>
<div data-options="region:'center'" style="overflow:hidden;">
    <div id="tabs">
        <div title="起始页" iconCls="icon-home" style="padding:0 10px;display:block;">
            欢迎来到后台管理系统!
        </div>
    </div>
</div>


<script type="text/javascript" src="https://my.oschina.net/assets/jquery/jquery.min.js"></script>
<script type="text/javascript" src="https://my.oschina.net/assets/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="https://my.oschina.net/assets/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">

    /**
     * 根据菜单文本返回对应页面的地址
     * @param {string} menuText 菜单文本
     * @returns {string} 对应页面的URL地址
     */
    function getUrl( menuText ){
        if ( '员工查询' == menuText ){
            return 'page/employee/list';
        }else if( '消息查询' == menuText ){
            return 'page/message/list';
        }

        return '';
    }

    $(function () {
        console.log('jc one!');

        var tab = $('#tabs');
        var nav = $('#nav');
        // 初始化tab
        tab.tabs({
            fit : true,
            border : false
        });

        // tree 点击事件
        nav.tree({
            onClick : function (node) {
                if( nav.tree('isLeaf',node.target) ){
                    var text = node.text;
                    var url = getUrl(text);
                    if( tab.tabs('exists',text)){
                        tab.tabs('select',text);
                    }else{
                        if ( url !== '') {
                            tab.tabs('add',{
                                url:url,
                                closable  : true,
                                title : text,
                                href : url
                            });
                        }
                    }
                }
            }
        });
    });


</script>
</body>
</html>

list.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<table id="employee-data"></table>

<script type="text/javascript">
    $(function () {
        var grid = $('#employee-data');
        var win = $('<div>');
        grid.datagrid({
            loadMsg:'数据加载中....',
            url : 'http://manage.jcone.com/employee/list',
            idField : 'id',
            rownumbers : true,
            striped : true,
            pagination : true,
            method : 'GET',
            ctrlSelect : true,
            pageSize : 30,
            pageList : [30, 60, 90],
            fitColumns : true,
            toolbar : [{
                text : '添加',
                iconCls:'icon-add',
                handler : function () {
                    createWindow({
                        type : 'save',
                        url : 'employee/save'
                    });
                }
            },'-',{
                text : '编辑',
                iconCls:'icon-edit',
                handler : function () {
                    var rows = grid.datagrid('getSelections');
                    if( 0 == rows.length || rows.length > 1 ){
                        $.messager.show({title: '提示',msg: '请选择一条数据!',timeout: 2000,showType: 'slide'});
                    }else{
                        createWindow({
                            type : 'update',
                            url : 'employee/update',
                            rowData : rows[0]
                        });
                    }
                }
            },'-',{
                text : '删除',
                iconCls:'icon-remove',
                handler : function () {
                    var ids = [];
                    var rows = grid.datagrid('getSelections');
                    if( rows.length > 0 ) {
                        for (var i = 0; i < rows.length; i++) {
                            ids.push(rows[i].id)
                        }
                        var idStr = '';
                        for (var i = 0; i < ids.length; i++) {
                            idStr += ids[i] + '-';
                        }
                        idStr = idStr.substr(0, idStr.length - 1);
                        $.ajax({
                            url: 'employee/delete',
                            data: 'ids=' + idStr,
                            type: 'POST',
                            statusCode: {
                                204: function (data) {
                                    $.messager.show({title: '提示',msg: '已删除',timeout: 2000,showType: 'slide'});
                                    grid.datagrid('reload');
                                },
                                400: function (data) {
                                    $.messager.show({title: '提示',msg: '请求参数错误',timeout: 2000,showType: 'slide'});
                                },
                                500: function (data) {
                                    $.messager.alert('提示', '服务器内部错误!', 'error');
                                }
                            }
                        });
                    }else{
                        $.messager.show({title: '提示',msg: '未选择数据',timeout: 2000,showType: 'slide'});
                    }

                }
            }],
            columns : [
                [{field : 'id',title : 'id',width : 100,checkbox:true},{field : 'loginNumber',title : '编号',width : 50},
                    {field : 'name',title : '姓名',width : 100},{field : 'sex',title : '性别',width : 50,formatter : formateSex},
                    {field : 'birthday',title : '出生日期',width : 80,formatter : formateBirthday},{field : 'lead',title : '是否领导',width : 50,formatter : formateLead},
                    {field : 'phone',title : '办公室电话',width : 100},{field : 'city',title : '住址',width : 100},
                    {field : 'created',title : '创建时间',width : 120,formatter : formateDateTime},{field : 'updated',title : '更新时间',width : 120,formatter : formateDateTime}
                ]
            ]
        });


        /**
         * 性别格式化
         * @param [boolean] sex 性别
         * @returns {string}
         * true : 男
         * false : 女
         */
        function formateSex( sex ){
            if(!sex){
                return '女'
            }
            return '男';
        }

        /**
         * 是否领导格式化
         * @param lead 是否领导
         * @returns {string}
         * true : 是
         * false : 否
         */
        function formateLead( lead ){
            if( !lead ){
                return '否';
            }
            return '是';
        }

        /**
         * 格式化出生日期
         * @param {string} birthday 出生日期
         * @returns {string} yyyy-MM-dd
         */
        function formateBirthday( birthday ){
            var date = new Date(parseInt(birthday));
            var b = date.getFullYear() + '-' + ( date.getMonth() - 1 ) + '-' + date.getDate();
            return b;
        }

        /**
         * 格式化时间戳
         * @param {string} datetime 时间戳
         * @returns {string} yyyy-MM-dd HH:mm:ss
         */
        function formateDateTime( datetime ){
            var date = new Date(parseInt(datetime));
            var b = date.getFullYear() + '-' + ( date.getMonth() - 1 ) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':'+ date.getSeconds();
            return b;
        }

        /**
         * 创建表单窗口
         * @param winConfig
         * type :
         *      save 新增
         *      update 更新
         * url : ajax提交地址
         * rowData : datagrid行
         */
        function createWindow( winConfig ){
            var type = winConfig.type;
            var url = winConfig.url;
            var winTitle = '';
            var msgText = '';
            if( 'save' == type ){
                msgText = '新增成功!';
                winTitle = '新增员工信息';
            }else if( 'update' == type ){
                msgText = '更新成功!';
                winTitle = '更新员工信息';
            }
            win.css('padding','10px');
            win.addClass('easyui-layout');
            win.window({
                width : 400,
                height : 350,
                modal : true,
                closable : false,
                maximizable : false,
                collapsible : false,
                resizable : false,
                minimizable : false,
                //{"北京市", "天津市", "唐山市", "邯郸市", "邢台市", "保定市", "承德市", "沧州市", "廊坊市", "衡水市", "太原市", "大同市", "阳泉市", "长治市", "晋城市", "晋中市", "运城市", "忻州市", "临汾市", "吕梁市", "朔州市"};
                title : winTitle,
                content : "<div data-options='region:center'><form id='employee-form'><table style='border-spacing:0px 10px'>\
                        <input id='emp-id' type='hidden' name='id'/>\
                        <tr><td>员工编号:</td><td><input id='emp-loginNumber' name='loginNumber' class='easyui-validatebox' data-options='required:true'/></td></tr>\
                        <tr><td>员工姓名:</td><td><input id='emp-name' name='name' class='easyui-validatebox' data-options='required:true'/></td></tr>\
                        <tr><td>员工性别:</td><td><select id='emp-sex' style='width:180px' class='easyui-combobox' data-options='editable:false,panelHeight:50'>\
                        <option value='true'>男</option><option value='false'>女</option></select>\
                        <input id='emp-sex-sub' type='hidden' name='sex'/></td></tr>\
                        <tr><td>办公室电话:</td><td><input id='emp-phone' name='phone' class='easyui-validatebox' data-options='required:true'/></td></tr>\
                        <tr><td>住址:</td><td><select id='emp-city' name='city' class='easyui-combobox'>\
                        <option value='北京市'>北京市</option><option value='大同市'>大同市</option><option value='太原市'>太原市</option>\
                        </select></td></tr>\
                        <tr><td>出生日期:</td><td><input id='emp-birthday' name='birthday' class='easyui-datebox' required ='required'/></td></tr>\
                        <tr><td>是否领导:</td><td><select id='emp-lead' style='width:180px' class='easyui-combobox' data-options='editable:false,panelHeight:50'>\
                        <option value='true'>是</option><option value='false'>否</option>\
                        </select> <input id='emp-lead-sub' type='hidden' name='lead'/></td></tr>\
                        </table></form></div>\
                        <div data-options='region:south' style='text-align:right;padding:5px 0 0'>\
                        <a id='form-btn-submit' class='easyui-linkbutton'  href='javascript:void(0)' style='width:80px' >确定</a>\
                        <a id='form-btn-cancle' class='easyui-linkbutton'  href='javascript:void(0)' style='width:80px' >取消</a>\
                        </div>",
                onOpen : function () {
                    if( 'update' == type ){
                        setFormValue(winConfig.rowData);
                    }

                    win.find('#form-btn-submit').click(function () {
                        winSubFunc(url,win.find('#employee-form'),msgText);
                    });
                    win.find('#form-btn-cancle').click(function () {
                        win.window('destroy');
                    });
                },
                onClose : function () {
                    win.window('destroy');
                }
            });
        }

        /**
         * 表单窗口提交
         * @param url ajax 地址
         * @param empForm 表彰对象[jQuery对象]
         * @param msgText 提示信息
         */
        function winSubFunc( url , empForm , msgText ){
            var sexText = win.find('#emp-sex').combobox('getValue');
            var sex = '';
            if( '男' == sexText || 'true' == sexText ){ sex = 'true' }else if( '女' == sexText || 'false' == sexText ){ sex = 'false' }
            win.find('#emp-sex-sub').val(sex);

            var leadText = win.find('#emp-lead').combobox('getValue');
            var lead = '';
            if( '是' == leadText || 'true' == leadText ){ lead = 'true' }else if( '否' == leadText || 'false' == leadText ){ lead = 'false' }
            win.find('#emp-lead-sub').val(lead);

            $.ajax({
                url : url,
                type : 'POST',
                data : empForm.serialize(),
                statusCode : {
                    201 : function () {
                        showMsg(msgText)
                    },
                    204 : function () {
                        showMsg(msgText);
                    },
                    500 : function () {
                        $.messager.alert('提示', '服务器内部错误!', 'error');
                    }
                }
            });
        }

        /**
         * 1.显示提示信息
         * 2.关闭表单窗口
         * 3. 重新加载datagrid
         * @param msgText 提示信息
         */
        function showMsg( msgText ){
            $.messager.show({title: '提示',msg: msgText,timeout: 2000,showType: 'slide'});
            grid.datagrid('reload');
            win.window('destroy');
            grid.datagrid('reload');
        }

        /**
         * 设置表单值
         * @param rowData datagrid行
         */
        function setFormValue( rowData ){
            win.find('#emp-id').val(rowData.id);
            win.find('#emp-loginNumber').val(rowData.loginNumber);
            win.find('#emp-name').val(rowData.name);
            var v = rowData.sex == true ? '男' : '女';
            win.find('#emp-sex').combobox('select',v);
            win.find('#emp-phone').val(rowData.phone);
            win.find('#emp-city').val(rowData.city);
            win.find('#emp-birthday').datebox('setValue',formateBirthday(rowData.birthday));
            v = rowData.lead == true ? '是' : '否';
            win.find('#emp-lead').combobox('select',v);
        }
    });
</script>
</body>
</html>

配置文件

spring-mvc

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.laolang.jc.one.manage.web.web"></context:component-scan>


    <mvc:annotation-driven>

    </mvc:annotation-driven>

    <mvc:resources location="/assets/" mapping="/assets/**"/>

    <!-- beetl 配置 -->
    <bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"/>
    <bean id="viewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
        <property name="contentType" value="text/html;charset=UTF-8"/>
    </bean>
</beans>

spring-public

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    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">

    <context:component-scan base-package="com.laolang"></context:component-scan>


    <!-- 导入配置文件 -->
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!-- 允许JVM参数覆盖 -->
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <!-- 忽略没有找到的资源文件 -->
        <property name="ignoreResourceNotFound" value="true" />
        <!-- 配置资源文件 -->
        <property name="locations">
            <list>
                <value>classpath:db.properties</value>
            </list>
        </property>
    </bean>

    <!-- 配置 druid数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="${jdbc.jdbcUrl}" />
        <property name="username" value="${jdbc.user}" />
        <property name="password" value="${jdbc.password}" />

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="20" />

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />

        <property name="validationQuery" value="SELECT 'x'" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
            value="20" />

        <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
        <property name="filters" value="stat" />
    </bean>
</beans>

spring-mybatis

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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">


    <!-- 配置SqlSessionFactory -->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 数据源 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 配置 mybatis 配置文件 -->
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
        <!-- sql 映射文件 -->
        <!--<property name="mapperLocations" value="classpath:mybatis/**/mapping/*.xml" 
            /> -->
        <property name="typeAliasesPackage" value="com.laolang.jc.one.manage.domain" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 会话工厂 -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
        <!-- 扫描包路径 多个包中间用半角逗号分隔 -->
        <property name="basePackage" value="com.laolang.jc.one.manage.mapper" />
    </bean>

    <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.laolang.jc.one.manage.mapper" />
        <property name="properties">
            <value>
                mappers=tk.mybatis.mapper.common.Mapper
            </value>
        </property>
    </bean>


</beans>

spring-transaction

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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">


    <!-- 配置SqlSessionFactory -->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 数据源 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 配置 mybatis 配置文件 -->
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
        <!-- sql 映射文件 -->
        <!--<property name="mapperLocations" value="classpath:mybatis/**/mapping/*.xml" 
            /> -->
        <property name="typeAliasesPackage" value="com.laolang.jc.one.manage.domain" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 会话工厂 -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
        <!-- 扫描包路径 多个包中间用半角逗号分隔 -->
        <property name="basePackage" value="com.laolang.jc.one.manage.mapper" />
    </bean>

    <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.laolang.jc.one.manage.mapper" />
        <property name="properties">
            <value>
                mappers=tk.mybatis.mapper.common.Mapper
            </value>
        </property>
    </bean>


</beans>

运行效果

121 项目 034 笔记向 easyui

121 项目 034 笔记向 easyui

mysql

CREATE TABLE `tb_employee` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '员工ID',
  `login_number` varchar(20) NOT NULL COMMENT '登陆名,也是员工编号',
  `name` varchar(20) NOT NULL COMMENT '员工姓名',
  `sex` tinyint(1) NOT NULL DEFAULT '1' COMMENT '员工性别,1:男,0:女',
  `pwd` varchar(150) NOT NULL COMMENT '员工登陆密码',
  `birthday` date DEFAULT NULL COMMENT '出生日期',
  `city` varchar(50) DEFAULT NULL COMMENT '居住地[城市名]',
  `phone` varchar(20) NOT NULL COMMENT '办公室电话',
  `lead` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否领导,1:是,0不是',
  `created` datetime DEFAULT NULL COMMENT '创建时间',
  `updated` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `login_number` (`login_number`)
) ENGINE=InnoDB AUTO_INCREMENT=4510 DEFAULT CHARSET=utf8 COMMENT='员工表';

项目地址

http://git.oschina.net/laolang2016/jcone/tree/ssm-1.1.0/

点赞
收藏
评论区
推荐文章
执键写春秋 执键写春秋
3年前
基于Maven工程下的MyBatis框架+MySQL+连接池的数据查询操作
具体操作项目结构引入项目依赖pom.xml<?xmlversion"1.0"encoding"UTF8"?<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xsi
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Easter79 Easter79
3年前
springboot2.1整合mybatis
1:添加依赖<?xmlversion"1.0"encoding"UTF8"?<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xsi
Stella981 Stella981
3年前
SpringBoot2.0配置durid数据源
pom依赖<?xmlversion"1.0"encoding"UTF8"?<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"
Stella981 Stella981
3年前
Spring boot 配置异步处理执行器
示例如下:1、新建Maven项目 asyncexecutor2、pom.xml<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xsi:sch
可莉 可莉
3年前
121 项目 034 笔记向 easyui
pom<?xmlversion"1.0"encoding"UTF8"?<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"
Stella981 Stella981
3年前
Maven系列
<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0http://ma
Stella981 Stella981
3年前
SpringBoot2.1.6 + Shiro1.4.1 + Thymeleaf + Jpa整合练习
  首先,添加maven依赖,完整的pom文件如下:1<?xmlversion"1.0"encoding"UTF8"?2<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema
Easter79 Easter79
3年前
SpringBoot2.1.6 + Shiro1.4.1 + Thymeleaf + Jpa整合练习
  首先,添加maven依赖,完整的pom文件如下:1<?xmlversion"1.0"encoding"UTF8"?2<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema
Easter79 Easter79
3年前
SpringBoot2.0配置durid数据源
pom依赖<?xmlversion"1.0"encoding"UTF8"?<projectxmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"