1. 程式人生 > >SSM整合專案:CRM客戶管理系統

SSM整合專案:CRM客戶管理系統

CRM專案
RequestMethod類,列舉型別。
MultipartFile類,配置介面的實現類。
把之前的資料表拿過來修改一下用。
新建資料庫,再執行sql檔案,即可匯入資料庫。
整合SSM框架
新建maven為什麼沒有生成資料夾啊?
新建maven專案,maven軟體的安裝位置,maven核心配置檔案的位置,maven倉庫的位置,這三個選不對,就不能正常建立專案。
新增依賴管理。
新建java和resources資料夾並設定對應屬性。
新增靜態資源(靜態資源新增的位置),加入分頁標籤。
 
標籤庫:
1)自定義標籤庫,標籤庫中可能有多個標籤,也可能只有一個標籤。
2)標籤的功能也是有java程式碼實現的,每一個標籤都要有java類的支援。
3)繼承自TagSupport
,就可以書寫自定義標籤。
 
實現頁面展示:
頁面佈局錯亂:Js,css樣式都被攔截掉了,所以導致頁面佈局出現問題。
使用*.do進行解決;通過spring-mvc對靜態資源進行放行
 
點選F12再重新整理頁面才會開始記錄網路請求的。
F12:檢視網路請求的,對前端頁面進行除錯。檢視Network基本資訊,請求了哪些地址及每個URL的網路相關請求資訊都可以看的到URL,響應狀態碼,響應資料型別,響應資料大小,響應時間。

XHR:XMLHttpRequest在後臺與伺服器交換資料。


 
實現查詢條件初始化,其實就是查詢導航欄。
springMVC @Value的使用:將某個常量,給變數賦值,供程式使用。@Value獲取某個引數的值並不是隨隨便便就能取到的,需要遵循一定的格式。
1)載入讀取配置檔案,2)讀取其中鍵值對中鍵的名字。
resources.properties。
 
三層中,首先編寫dao層。
寫sql注意資料庫的欄位和物件的屬性名不一樣(在這裡錯了太多次)。
模糊查詢
和精確查詢。
 
只在Service的介面實現類上添加註解,不需要在介面上添加註解
 
通過tomcat日誌去檢視錯誤資訊,看看是哪裡報錯了,如何解決?
學會檢視tomcat的報錯資訊,一般都能解決問題,大致哪裡寫錯了。

當前啟動的哪個Tomcat,就去看對應的執行日誌?Run面板。

log4j.properties 日誌的名字


Jsp頁面主要用於後臺管理系統,頁面展示。
EL表示式,JSP指令,JSP指令碼,JSP指令內建物件,JSP標籤庫,Form表單。
如何在jsp頁面中傳送網路請求?
Form表單的使用:傳送網路請求。
jsp頁面與java後臺的互動還是不熟悉,一定要精通。對錶單的網路請求不熟悉。
Jstl標籤庫:什麼時候使用jstl標籤庫?格式化日期,非空判斷,迴圈遍歷等

Jsp頁面中如何輸入java程式碼?

<Form>提交按鈕<input type="submit"> 定義用於向表單處理程式(form-handler)提交表單資料的按鈕。
action 屬性定義在提交表單時,傳送網路請求。
method 屬性規定在提交表單時所用的 HTTP 方法(GET POST)。
name 屬性:如果要正確地被提交,每個輸入欄位必須設定一個name 屬性。

${pageContext.request.contextPath}
pageContext物件是JSP中很重要的一個內建物件,pageContext物件提供了對JSP頁面所有的物件及名稱空間的訪問。
request.contextPath()拿到的是web專案的根路徑。
類頭註釋
/**
*describe:
*
*@author chenrushui
*@date ${YEAR}/${MONTH}/${DAY}

*/

xml對映檔案:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.crm.mapper.CustomerDao">

    <!--查詢到的資料的條數-->
    <select id="customCount" parameterType="QueryVo" resultType="Integer">
        select count(1) from customer
        <where>
            <if test="custName!=null and custName!=''">
                cust_name like "%"#{custName}"%"
            </if>
            <if test="custSource!=null and custSource!=''">
                and cust_source = #{custSource}
            </if>
            <if test="custIndustry!=null and custIndustry!=''">
                and cust_industry = #{custIndustry}
            </if>
            <if test="custLevel!=null and custLevel!=''">
                and cust_level = #{custLevel}
            </if>
        </where>
    </select>
    
    <!--通過id查詢使用者資訊-->
    <select id="selectCustomerById" parameterType="Integer" resultType="com.crm.pojo.Customer">
        select * from customer where cust_id=#{id}
    </select>

    <update id="updateCustomerById" parameterType="Customer">
        update customer set cust_name=#{cust_name} where cust_id=#{cust_id};
    </update>

    <delete id="deleteCustomer" parameterType="Integer">
        delete from customer where cust_id=#{id}
    </delete>
</mapper>

Controller層程式碼:

package com.crm.controller;

import com.crm.pojo.BaseDict;
import com.crm.pojo.Customer;
import com.crm.pojo.QueryVo;
import com.crm.service.BaseCustomerService;
import com.crm.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * describe:使用者管理控制器
 *
 * @author chenrushui
 * @date 2018/06/14
 */
@Controller
@RequestMapping(value = "/customer")
public class CustomerController {
    //注入成為成員變數:需要被載入的資原始檔需要放到spring-mvc配置檔案中。
    //這種方式特別好用,不需要通過ResourceBundle進行讀取。
    @Value("${fromType.code}")
    private String fromTypeCode;
    @Value("${industryType.code}")
    private String industryTypeCode;
    @Value("${levelType.code}")
    private String levelTypeCode;
    
    @Autowired
    private BaseCustomerService mBaseCustomerService;

    /**
     * 展示前端頁面
     *
     * @return
     */
    @RequestMapping(value = "/list")
    public String getCustomerList(QueryVo vo, Model model) {
        //特別注意:如何解決硬編碼問題?通過注入成員變數的方式進行解決
        List<BaseDict> fromType = mBaseCustomerService.selectCustomerByCode(fromTypeCode);
        List<BaseDict> industryType = mBaseCustomerService.selectCustomerByCode(industryTypeCode);
        List<BaseDict> levelType = mBaseCustomerService.selectCustomerByCode(levelTypeCode);
        //特別注意:鍵的名稱要和jsp頁面中獲取的一樣。
        model.addAttribute("fromType", fromType);
        model.addAttribute("industryType", industryType);
        model.addAttribute("levelType", levelType);

        //填充結果資料
        Page<Customer> page = mBaseCustomerService.selectCustomerByQueryVo(vo);
        model.addAttribute("page", page);

        //實現資料回顯(把資料返回)
        model.addAttribute("custName", vo.getCustName());
        model.addAttribute("custSource", vo.getCustSource());
        model.addAttribute("custIndustry", vo.getCustIndustry());
        model.addAttribute("custLevel", vo.getCustLevel());
        //model內部是通過request域實現的,通過el表示式獲取的是哪個變數的值,控制元件的name屬性名
        return "customer";
    }

    /**
     * 編輯使用者資訊
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit.action", method = RequestMethod.GET)
    @ResponseBody
    public Customer changeCustomerInfo(Integer id) {
        return mBaseCustomerService.selectCustomerById(id);
    }

    /**
     * 儲存修改的使用者資訊
     *
     * @param customer
     * @return
     */
    @RequestMapping(value = "/update.action", method = RequestMethod.POST)
    @ResponseBody
    public String updateCustomer(Customer customer) {
        Integer row = mBaseCustomerService.updateCustomerById(customer);
        System.out.print(row + "");
        return "ok";
    }

    @RequestMapping(value = "/delete.action", method = RequestMethod.POST)
    @ResponseBody
    public String deleteCustomer(Integer id) {
        Integer row = mBaseCustomerService.deleteCustomer(id);
        System.out.print(row + "受影響的行數");
        return "ok";
    }
}