java SSM项目流程

package cn.com.wy.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.List;

/**
 * 车位实体类
 */

public class Stall {
    private int stallId;
    private String stallName;
    private Head head;  //户主    1 -- n
    private String stallCarNo;  //车牌号
    private int stallState; // 状态   1:未出售    2:已出售
    private String stallRemark;   //备注

    public int getStallId() {
        return stallId;
    }

    public void setStallId(int stallId) {
        this.stallId = stallId;
    }

    public String getStallName() {
        return stallName;
    }

    public void setStallName(String stallName) {
        this.stallName = stallName;
    }

    public Head getHead() {
        return head;
    }

    public void setHead(Head head) {
        this.head = head;
    }

    public String getStallCarNo() {
        return stallCarNo;
    }

    public void setStallCarNo(String stallCarNo) {
        this.stallCarNo = stallCarNo;
    }

    public int getStallState() {
        return stallState;
    }

    public void setStallState(int stallState) {
        this.stallState = stallState;
    }

    public String getStallRemark() {
        return stallRemark;
    }

    public void setStallRemark(String stallRemark) {
        this.stallRemark = stallRemark;
    }


    @Override
    public String toString() {
        return "Stall{" +
                "stallId=" + stallId +
                ", stallName='" + stallName + '\'' +
                ", head=" + head +
                ", stallCarNo='" + stallCarNo + '\'' +
                ", stallState=" + stallState +
                ", stallRemark='" + stallRemark + '\'' +
                '}';
    }
}

开发流程

1.需求分析

首先缺点做哪些功能,需求分析包括前台和后台。

前台又分为单纯要展示的那些功能-需求分析展示,以及提交给服务端的功能的交互。

2.表结构设计

表结构设计,围绕着需求分析,如果表有问题那么也将会影响功能的实现。除了表与表关系,建立SQL语句

3.原型图

接着是界面的原型图,与客户沟通顺畅的项目设计流程,借助原型图可以低成本,高效率,前台原型和后台原型

4.后台分类管理

按照模块之间的依赖关系,

二、文件目录

 1.pom 文件

<dependency>

【分页查询、文件上传、事务依赖、Mybits、juit、MVC、json、web、servlet、jstl、spring】

<dependency/>

<properties>
      <spring.version>5.1.5.RELEASE</spring.version>
      <servlet.version>3.0.1</servlet.version>
      <jstl.version>1.2</jstl.version>
      <jsp.version>2.2</jsp.version>
      <jackson.version>2.9.5</jackson.version>
      <kaptcha.version>2.3.2</kaptcha.version>
      <mybatis.version>3.4.4</mybatis.version>
      <mysql.driver.version>8.0.11</mysql.driver.version>
      <junit.version>4.12</junit.version>
      <log4j.version>1.2.17</log4j.version>
      <druid.version>1.1.16</druid.version>
      <mybatis.spring.version>2.0.1</mybatis.spring.version>

      <commons.io.version>2.6</commons.io.version>
      <file.upload.version>1.3.3</file.upload.version>
      <com.github.pagehelper>5.2.1</com.github.pagehelper>
      <mybatis.generator.version>1.3.2</mybatis.generator.version>
    </properties>

    <dependencies>

      <!-- 分页 -->
      <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper</artifactId>
        <version>${com.github.pagehelper}</version>
      </dependency>

      <!-- 文件上传 -->
      <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>${file.upload.version}</version>
      </dependency>
      <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>${commons.io.version}</version>
      </dependency>

      <!-- 事务依赖 -->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
      </dependency>

      <!-- MyBatis -->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>${druid.version}</version>
      </dependency>
      <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>${mybatis.spring.version}</version>
      </dependency>

      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
      </dependency>

      <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>${mybatis.version}</version>
      </dependency>

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

      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
      </dependency>

      <dependency>
        <groupId>com.github.penggle</groupId>
        <artifactId>kaptcha</artifactId>
        <version>${kaptcha.version}</version>
      </dependency>

      <!-- MVC  -->
      <!-- json -->
      <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-annotations</artifactId>
        <version>${jackson.version}</version>
      </dependency>
      <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
      </dependency>

      <!-- web and mvc -->
      <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>

      <!-- servlet jsp jstl-->
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.version}</version>
        <scope>provided</scope>
      </dependency>

      <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
      </dependency>
      <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>${jsp.version}</version>
        <scope>provided</scope>
      </dependency>

      <!-- spring -->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</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-context</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-aspects</artifactId>
        <version>${spring.version}</version>
      </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.2</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
      <plugins>
        <!-- <plugin>

              <groupId>org.mybatis.generator</groupId>
              <artifactId>mybatis-generator-maven-plugin</artifactId>
              <version>1.3.2</version>
              <configuration>
                  <configurationFile>src/test/resources/generator.xml</configurationFile>配置文件路径
                  <verbose>true</verbose>
                  <overwrite>true</overwrite>
              </configuration>
              <executions>
                  <execution>
                      <id>Generate MyBatis Artifacts</id>
                      <goals>
                          <goal>generate</goal>
                      </goals>
                  </execution>
              </executions>
              <dependencies>
                  <dependency>
                      <groupId>mysql</groupId>
                      <artifactId>mysql-connector-java</artifactId>
                      <version>${mysql.driver.version}</version>
                  </dependency>
                  <dependency>
                      <groupId>org.mybatis.generator</groupId>
                      <artifactId>mybatis-generator-core</artifactId>
                      <version>${mybatis.generator.version}</version>
                  </dependency>
              </dependencies>
          </plugin>  -->
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>6</source>
                  <target>6</target>
              </configuration>
          </plugin>
      </plugins>
      <pluginManagement>
        <plugins>
          <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
          <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
              <lifecycleMappingMetadata>
                <pluginExecutions>
                  <pluginExecution>
                    <pluginExecutionFilter>
                      <groupId>
                        org.mybatis.generator
                      </groupId>
                      <artifactId>
                        mybatis-generator-maven-plugin
                      </artifactId>
                      <versionRange>
                        [1.3.2,)
                      </versionRange>
                      <goals>
                        <goal>generate</goal>
                      </goals>
                    </pluginExecutionFilter>
                    <action>
                      <ignore></ignore>
                    </action>
                  </pluginExecution>
                </pluginExecutions>
              </lifecycleMappingMetadata>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </project>

2.先建立sql语句表

 

 3.sql语句

 stallDao.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="cn.com.wy.dao.StallDao" >
  <resultMap id="StallMap" type="cn.com.wy.entity.Stall" >
    <id column="stall_id" property="stallId"/>
    <result column="stall_name" property="stallName"/>
    <result column="stall_carno" property="stallCarNo"/>
    <result column="stall_state" property="stallState"/>
    <result column="stall_remark" property="stallRemark"/>
    <association property="head" column="stall_headid"
                select="cn.com.wy.dao.HeadDao.findByHeadId">
    </association>
  </resultMap>

  <select id="findAll1" resultMap="StallMap">
    select *
    from t_stall
  </select>

  <select id="findByStallId" resultMap="StallMap" parameterType="int">
    select *
    from t_stall
    where stall_id = #{stallId}
  </select>

  <select id="findByHeadId" resultMap="StallMap" parameterType="int">
    select  *
    from t_stall
    where stall_headid = #{headId}
  </select>

  <select id="findByCarNo" resultMap="StallMap" parameterType="string">
    select *
    from t_stall
    where stall_carno = #{stallCarNo}
  </select>

  <update id="updateStall" parameterType="cn.com.wy.entity.Stall">
    update t_stall
    <set>
      <if test="stallName != null">
        stall_name=#{stallName},
      </if>
      <if test="headId != null">
        stall_headid=#{head.headId},
      </if>
      <if test="stallCarNo != null">
        stall_carno=#{stallCarNo},
      </if>
      <if test="stallState != null">
        stall_state=#{stallState},
      </if>
      <if test="stallRemark != null and stallRemark != ''">
        stall_remark=#{stallRemark},
      </if>
    </set>
    where stall_id=#{stallId};
  </update>

  <insert id="addStall" parameterType="cn.com.wy.entity.Stall">
        insert into
        t_stall (stall_name,stall_carno,stall_state,stall_remark,stall_headid) values (#{stallName},#{stallCarNo},#{stallState},#{stallRemark},#{head.headId})
  </insert>


  <delete id="deleteStall" parameterType="java.lang.Integer">
    delete from t_stall
    where stall_id in
    <foreach collection="stallId" item="id" index="no" open="("
             separator="," close=")">
      #{id}
    </foreach>
  </delete>


  <select id="findAll" resultMap="StallMap"  parameterType="cn.com.wy.entity.Stall">
    select * from t_stall
    <where>
      <if test="stallName != null and stallName !=''">
        and stall_name like concat("%",#{stallName},"%")
      </if>
      <if test="stallCarNo != null and stallCarNo !=''">
        and stall_carno like concat("%",#{stallCarNo},"%")
      </if>
<!--      <if test="headId != null">-->
<!--        and stall_headid like concat("%",#{head.headId},"#")-->
<!--      </if>-->
      <if test="stallState != 0">
        and stall_state=#{stallState}
      </if>
    </where>
  </select>
</mapper>

4. sql语句被dao 引用

package cn.com.wy.dao;

import cn.com.wy.entity.Stall;
import com.alibaba.druid.support.json.JSONUtils;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 车位
 */
public interface StallDao {
    /**
     * 查询所有车位
     * @return
     */
    List<Stall> findAll1(Stall stall);


    /**
     * 根据车位Id查询车位
     * @param stallId
     * @return
     */
    Stall findByStallId(int stallId);

    /**
     * 根据户主Id查询车位
     * @param headId
     * @return
     */
    List<Stall> findByHeadId(int headId);

    /**
     * 根据车牌号查询车位
     * @param carNo
     * @return
     */
    List<Stall> findByCarNo(String carNo);

    /**
     * 修改车位信息<
     * @param stall
     * @return
     */
    int updateStall(Stall stall);

    /**
     * 新增车位信息
     * @param stall
     * @return
     */
    int addStall(Stall stall);

    /**
     * 根据车位Id删除车位
     * @param stallId
     * @return
     */
    int deleteStall(@Param("stallId") List<Integer> stallId);

    /**
     * 搜索框 模糊查询 车位
     */
    List<Stall> findAll(Stall stall);
//    List<Stall> selectLike(Stall stall);
}

5.定义实体类

package cn.com.wy.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.List;

/**
 * 车位实体类
 */

public class Stall {
    private int stallId;
    private String stallName;
    private Head head;  //户主    1 -- n
    private String stallCarNo;  //车牌号
    private int stallState; // 状态   1:未出售    2:已出售
    private String stallRemark;   //备注

    public int getStallId() {
        return stallId;
    }

    public void setStallId(int stallId) {
        this.stallId = stallId;
    }

    public String getStallName() {
        return stallName;
    }

    public void setStallName(String stallName) {
        this.stallName = stallName;
    }

    public Head getHead() {
        return head;
    }

    public void setHead(Head head) {
        this.head = head;
    }

    public String getStallCarNo() {
        return stallCarNo;
    }

    public void setStallCarNo(String stallCarNo) {
        this.stallCarNo = stallCarNo;
    }

    public int getStallState() {
        return stallState;
    }

    public void setStallState(int stallState) {
        this.stallState = stallState;
    }

    public String getStallRemark() {
        return stallRemark;
    }

    public void setStallRemark(String stallRemark) {
        this.stallRemark = stallRemark;
    }


    @Override
    public String toString() {
        return "Stall{" +
                "stallId=" + stallId +
                ", stallName='" + stallName + '\'' +
                ", head=" + head +
                ", stallCarNo='" + stallCarNo + '\'' +
                ", stallState=" + stallState +
                ", stallRemark='" + stallRemark + '\'' +
                '}';
    }
}

 6.impl 继承 service 调用dao

package cn.com.wy.service.Impl;

import cn.com.wy.dao.HeadDao;
import cn.com.wy.dao.StallDao;
import cn.com.wy.entity.Head;
import cn.com.wy.entity.Stall;
import cn.com.wy.service.StallService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.List;

public class StallServiceImpl implements StallService {

    private StallDao stallDao;
    private HeadDao headDao;

    public void setHeadDao(HeadDao headDao) {
        this.headDao = headDao;
    }

    public void setStallDao(StallDao stallDao){
        this.stallDao = stallDao;
    }

    @Override
    public List<Stall> findAll(Stall stall) {

        return stallDao.findAll(stall);
    }

    @Override
    public List<Stall> selectLike(Stall stall) {
        return null;
    }


    @Override
    public List<Stall> findAll1(Stall stall) {
        return stallDao.findAll1(stall);
    }

    @Override
    public Stall findByStallId(int stallId) {
        return stallDao.findByStallId(stallId);
    }

    @Override
    public List<Stall> findByHeadId(int headId) {
        return stallDao.findByHeadId(headId);
    }

    @Override
    public List<Stall> findByCarNo(String carNo) {
        return stallDao.findByCarNo(carNo);
    }


    @Override
    public boolean updateStall(Stall stall) {
        boolean bool  =false;
        int i = this.stallDao.updateStall(stall);
        if(i != 0) {
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean addStall(Stall stall) {
        boolean bool = false;
        Head head = headDao.findByHeadName(stall.getHead().getHeadName());
        stall.setHead(head);
        int i = stallDao.addStall(stall);
        if( i >= 0){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean deleteStall( List<Integer> stallId) {
        boolean bool  = false;
        int i =stallDao.deleteStall(stallId);
        System.out.println(i);
        if(i != 0){
            bool = true;
            return bool;
        }
        return  bool;
    }

//    @Override
//    public List<Stall> selectLike(Stall stall) {
//        return stallDao.selectLike(stall);
//    }
}

7.Service 被controller 调用

package cn.com.wy.service;

import cn.com.wy.entity.Stall;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.PreDestroy;
import java.util.List;

public interface StallService {
    /**
     * 查询所有车位
     * @return
     */
    List<Stall> findAll1(Stall stall);

    /**
     * 根据车位Id查询车位
     * @param stallId
     * @return
     */
    Stall findByStallId(int stallId);

    /**
     * 根据户主Id查询车位
     * @param headId
     * @return
     */
    List<Stall> findByHeadId(int headId);

    /**
     * 根据车牌号查询车位
     * @param carNo
     * @return
     */
    List<Stall> findByCarNo(String carNo);

    /**
     * 修改车位信息
     * @param stall
     * @return
     */
    boolean updateStall(Stall stall);

    /**
     * 新增车位信息
     * @param stall
     * @return
     */
    boolean addStall(Stall stall);

    /**
     * 根据车位Id删除车位
     * @param stallId
     * @return
     */
    boolean deleteStall(List<Integer> stallId);

    /**
     * 查询 车位like
     */
    List<Stall> findAll(Stall stall);
    List<Stall> selectLike(Stall stall);
}

三、controller的使用

1.页面地址请求

@Controller 声明控制

 @RequesMapping()     url地址

@Autowired                   自动注入

 return返回的是相对应的 web.jsp 界面

返回 WEB-INF/views/parking/list.jsp

2.查询语句 一个对多

 @RequesMapping  查询的url地址

@ResponseBody    json转换文本防止乱码

3.添加 controller语句

 4.修改语句

5.删除语句

 

 

 四、前端显示台

显示数据

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="../common/header.jsp"%>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar">
        <div class="wu-toolbar-button">
            <%@include file="../common/menus.jsp"%>
        </div>
        <div class="wu-toolbar-search">
            <label>车位名称:</label><input id="search-name" class="wu-text" style="width:100px">
            <label>车牌号:</label><input id="search-carno" class="wu-text" style="width:100px">
            <label>所属业主:</label><input id="search-yezhu" class="wu-text" style="width:100px">
            <label>状态:</label>
            <select id="search-status" class="easyui-combobox" panelHeight="auto" style="width:120px">
               <option value="0">全部</option>
               <option value="1">已售</option>
               <option value="2">未售</option>
            </select>

            <a href="#" id="search-btn" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="data-datagrid" class="easyui-datagrid" toolbar="#wu-toolbar"></table>
</div>
<!-- 添加弹框 -->
<div id="add-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:420px; padding:10px;">
   <form id="add-form" method="post"  >
        <table>
            <tr>
                <td align="right" >车位名称:</td>
                <td><input type="text" id="add-stallName" name="stallName" class="wu-text easyui-validatebox"  /></td>
            </tr>
            <tr>
                <td align="right">车牌号:</td>
                <td><input type="text" id="add-stallCarNo" name="stallCarNo" class="wu-text easyui-validatebox"  /></td>
            </tr>
            <tr>
                <td align="right">所属业主:</td>
                <td><input type="text" id="add-head" name="head.headName" class="wu-text easyui-validatebox"  /></td>
            </tr>
            <tr>
                <td align="right">状态:</td>
                <td>
                       <select id="add-stallState" name="stallState" class="easyui-combobox" panelHeight="auto" style="width:268px">
                     <option value="2">已售</option>
                     <option value="1">未售</option>
                  </select>
            </td>
            </tr>
            <tr>
                <td align="right">备注:</td>
                <td><textarea id="add-stallRemark" name="stallRemark" rows="6" class="wu-textarea" style="width:260px"></textarea></td>
            </tr>
        </table>
    </form>
</div>
<!-- 修改窗口 -->
<div id="edit-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:450px; padding:10px;">
   <form id="edit-form" method="post" >
        <input type="hidden" name="stallId" id="edit-stallId">
        <table>
            <tr>
                <td align="right" style="width:60px">车位名称:</td>
                <td><input type="text" id="edit-stallName" name="stallName" class="wu-text easyui-validatebox"  /></td>
            </tr>
            <tr>
                <td align="right">车牌号:</td>
                <td><input type="text" id="edit-stallCarNo" name="stallCarNo" class="wu-text easyui-validatebox" /></td>
            </tr>
            <tr>
                 <td align="right">业主姓名:</td>
                <td><input type="text" id="edit-headName" name="head.headName" class="wu-text easyui-validatebox"  style="width: 260px" /></td>
            </tr>
                 <tr>
                <td align="right">状态:</td>
                <td>
                       <select id="edit-stallState" name="stallState" class="easyui-combobox" panelHeight="auto" style="width:268px">
                     <option value="1">已售</option>
                     <option value="2">未售</option>
                  </select>
            </td>
            </tr>
            <tr>
                <td align="right">备注:</td>
                <td><textarea id="edit-stallRemark" name="stallRemark" rows="6" class="wu-textarea" style="width:260px"></textarea></td>
            </tr>
        </table>
    </form>
</div>
<%@include file="../common/footer.jsp"%>
<!-- End of easyui-dialog -->
<script type="text/javascript">
   
   /**
   *  添加记录
   */
   function add(){
      var validate = $("#add-form").form("validate");
      if(!validate){
         $.messager.alert("消息提醒","请检查你输入的数据!","warning");
         return;
      }
      var data = $("#add-form").serialize();
      $.ajax({
         url:'../stall/addStall',
         dataType:'json',
         type:'post',
         data:data,
         success:function(data){
            if(data.type == 'success'){
               $.messager.alert('信息提示','添加成功!','info');
               $("#add-stallName").val('');
               $("#add-stallCarNo").val('');
               $("#add-add-head").val('');
               $("#add-stallState").val('');
               $("#add-stallRemark").val('');
               $('#add-dialog').dialog('close');
               $('#data-datagrid').datagrid('reload');
            }else{
               $.messager.alert('信息提示',data.msg,'warning');
            }
         }
      });
   }
   
   /**
   * 编辑记录
   */
   function edit(){
      var validate = $("#edit-form").form("validate");
      if(!validate){
         $.messager.alert("消息提醒","请检查你输入的数据!","warning");
         return;
      }
      var data = $("#edit-form").serialize();
      $.ajax({
         url:'../stall/update',
         dataType:'json',
         type:'post',
         data:data,
         success:function(data){
            if(data.type == 'success'){
               $.messager.alert('信息提示','修改成功!','info');
               $('#edit-dialog').dialog('close');
               $('#data-datagrid').datagrid('reload');
               $('#data-datagrid').datagrid('unselectAll');
            }else{
               $.messager.alert('信息提示',data.msg,'warning');
            }
         }
      });
   }
   
   
   /**
   * 删除记录
   */
    function remove(){
        $.messager.confirm('信息提示','确定要删除该记录?', function(result){
            if(result){
                var item = $('#data-datagrid').datagrid('getSelections');
                if(item == null || item.length == 0){
                    $.messager.alert('信息提示','请选择要删除的数据!','info');
                    return;
                }
                var ids = '';
                for(var i=0;i<item.length;i++){
                    ids += item[i].stallId + ',';
                }
                $.ajax({
                    url:'../stall/delete',
                    dataType:'json',
                    type:'post',
                    data:{ids:ids},
                    success:function(data){
                        if(data.type == 'success'){
                            $.messager.alert('信息提示','删除成功!','info');
                            $('#data-datagrid').datagrid('reload');
                        }else{
                            $.messager.alert('信息提示',data.msg,'warning');
                        }
                    }
                });
            }
        });
    }
   
   /**
   * Name 打开编辑窗口
   */
   function openEdit(){
      //$('#add-form').form('clear');
      var item = $('#data-datagrid').datagrid('getSelected');
      if(item == null || item.length == 0){
         $.messager.alert('信息提示','请选择要编辑的数据!','info');
         return;
      }
      $('#edit-dialog').dialog({
         closed: false,
         modal:true,
            title: "编辑停车场信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#edit-dialog').dialog('close');                    
                }
            }],
            onBeforeOpen:function(){
               //$("#add-form input").val('');
               $("#edit-stallId").val(item.stallId);
               $("#edit-stallName").val(item.stallName);
               $("#edit-stallCarNo").val(item.stallCarNo);
               $("#edit-headName").val(item.head.headName);
               $("#edit-stallState").combobox('setValue',item.stallState);
               $("#edit-stallRemark").val(item.stallRemark);
            }
        });
   }
   
   /**
   * Name 打开添加窗口
   */
   function openAdd(){
      //$('#add-form').form('clear');
      $('#add-dialog').dialog({
         closed: false,
         modal:true,
            title: "添加停车场信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#add-dialog').dialog('close');                    
                }
            }],
            onBeforeOpen:function(){
               $("#add-form input").val('');
               
            }
        });
   }
   
   //搜索按钮监听
   $("#search-btn").click(function(){
      var option = {stallName:$("#search-name").val()};
      var carno = $("#search-carno").val();
      // var yezhu = {headname:$("#search-yezhu").val()};
      var status = $("#search-status").combobox('getValue');
            option.stallState = status;
            option.stallCarNo = carno;
            // option.yezhu = yezhu;

      $('#data-datagrid').datagrid('reload',option);
   });
   /** 
   * 载入数据
   */
   $('#data-datagrid').datagrid({
      url:'../stall/select',
        rownumbers:true,
        singleSelect:false,
        pageSize:20,
        pagination:true,
        multiSort:true,
        fitColumns:true,
        idField:'stallId',
        treeField:'name',
        fit:true,
      columns:[[
         { field:'chk',checkbox:true},
            { field:'stallId',title:'编号',width:100,sortable:true,hidden:true},
         { field:'stallName',title:'车位名称',width:100,sortable:true},
         { field:'stallCarNo',title:'车牌号',width:100,sortable:true},
         { field:'head.headName',title:'所属业主',width:100,
                formatter:function(value,row,index){
                return row['head']['headName']

            }},
            { field:'stallState',title:'状态',width:100,formatter:function(value,row,index){
               switch(value){
                  case 2:{
                     return '未售';
                  }
                  case 1:{
                     return '已售';
                  }
               }
               return value;
            }},
         { field:'stallRemark',title:'备注',width:200,sortable:true},
      ]],
        // onLoadSuccess:function(data){
        //     $('.authority-edit').linkbutton({text:'编辑权限',plain:true,iconCls:'icon-edit'});
        // }
    });
</script>

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值