[TOC]
## 步驟 1 : 準備數據
因為用戶信息是前臺注冊的時候增加的,截至目前為止,還沒有講到前臺的功能。所以需要手動在數據庫中增加數據,以便于觀察運行的效果
~~~
insert into t_user values(null,'a1','123456');
insert into t_user values(null,'a2','123456');
insert into t_user values(null,'a3','123456');
insert into t_user values(null,'a4','123456');
insert into t_user values(null,'a5','123456');
~~~
## 步驟 2 : 先運行,看到效果,再學習
先將完整的 tmall-ssm 項目(向老師要相關資料),配置運行起來,確認可用之后,再學習做了哪些步驟以達到這樣的效果。
## 步驟 3 : 模仿和排錯
在確保可運行項目能夠正確無誤地運行之后,再嚴格照著教程的步驟,對代碼模仿一遍。
模仿過程難免代碼有出入,導致無法得到期望的運行結果,此時此刻通過比較**正確答案** ( 可運行項目 ) 和自己的代碼,來定位問題所在。
采用這種方式,**學習有效果,排錯有效率**,可以較為明顯地提升學習速度,跨過學習路上的各個檻。
## 步驟 4 : 頁面截圖
用戶這部分做的比較簡單,只有查詢,為什么呢?
1. 用戶的增加,是交由前臺注冊行為產生的,后臺不需要自己進行增加
2. 用戶信息不能刪除。 用戶信息是最重要的業務信息,不可以刪除
3. 用戶資料的修改,也應該有前臺用戶自己進行,而不是后臺操作。比如修改密碼

## 步驟 5 : User
User使用自動生成的,沒變化
## 步驟 6 : UserService
新增UserService,提供CRUD一套
~~~
package com.dodoke.tmall.service;
import java.util.List;
import com.dodoke.tmall.pojo.User;
public interface UserService {
void add(User c);
void delete(int id);
void update(User c);
User get(int id);
List list();
}
~~~
## 步驟 7 : UserServiceImpl
新建類UserServiceImpl,提供CURD一套
~~~
package com.dodoke.tmall.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dodoke.tmall.mapper.UserMapper;
import com.dodoke.tmall.pojo.User;
import com.dodoke.tmall.pojo.UserExample;
import com.dodoke.tmall.service.UserService;
@Service
public class UserServiceImpl implements UserService {
@Autowired
UserMapper userMapper;
@Override
public void add(User u) {
userMapper.insert(u);
}
@Override
public void delete(int id) {
userMapper.deleteByPrimaryKey(id);
}
@Override
public void update(User u) {
userMapper.updateByPrimaryKeySelective(u);
}
@Override
public User get(int id) {
return userMapper.selectByPrimaryKey(id);
}
public List<User> list() {
UserExample example = new UserExample();
example.setOrderByClause("id desc");
return userMapper.selectByExample(example);
}
}
~~~
## 步驟 8 : UserController
新建UserController類,提供分頁查詢
~~~
package com.dodoke.tmall.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dodoke.tmall.pojo.User;
import com.dodoke.tmall.service.UserService;
import com.dodoke.tmall.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Controller
@RequestMapping("")
public class UserController {
@Autowired
UserService userService;
@RequestMapping("admin_user_list")
public String list(Model model, Page page) {
PageHelper.offsetPage(page.getStart(), page.getCount());
List<User> us = userService.list();
int total = (int) new PageInfo<>(us).getTotal();
page.setTotal(total);
model.addAttribute("us", us);
model.addAttribute("page", page);
return "admin/listUser";
}
}
~~~
## 步驟 9 : listUser.jsp
listUser.jsp頁面
## 步驟 10 : 查詢功能講解
點擊后臺管理上方導航中的 用戶管理,進入用戶查詢界面
`http://127.0.0.1:8080/tmall_ssm/admin_user_list`
UserController的list方法被調用
1. 獲取分頁對象
2. 設置分頁信息
3. 查詢用戶集合
4. 通過PageInfo獲取總數,并設置在page對象上
5. 把用戶集合設置到model的"us"屬性上
6. 把分頁對象設置到model的"page"屬性上
5. 服務端跳轉到admin/listUser.jsp頁面
6. 在listUser.jsp用c:forEach遍歷"us"集合

UserController 代碼片段:
~~~
@RequestMapping("admin_user_list")
public String list(Model model, Page page) {
PageHelper.offsetPage(page.getStart(), page.getCount());
List<User> us = userService.list();
int total = (int) new PageInfo<>(us).getTotal();
page.setTotal(total);
model.addAttribute("us", us);
model.addAttribute("page", page);
return "admin/listUser";
}
~~~
listUser.jsp:
~~~
<c:forEach items="${us}" var="u">
<tr>
<td>${u.id}</td>
<td>${u.name}</td>
</tr>
</c:forEach>
~~~
## 步驟 11 : 增加,刪除,修改功能
增加交由前臺用戶注冊功能
刪除不提供(用戶信息是最重要的資料)
修改不提供,應該由前臺用戶自己完成****
- 項目簡介
- 功能一覽
- 前臺
- 后臺
- 開發流程
- 需求分析-展示
- 首頁
- 產品頁
- 分類頁
- 搜索結果頁
- 購物車查看頁
- 結算頁
- 確認支付頁
- 支付成功頁
- 我的訂單頁
- 確認收貨頁
- 確認收貨成功頁
- 評價頁
- 需求分析-交互
- 分類頁排序
- 立即購買
- 加入購物車
- 調整訂單項數量
- 刪除訂單項
- 生成訂單
- 訂單頁功能
- 確認付款
- 確認收貨
- 提交評價信息
- 登錄
- 注冊
- 退出
- 搜索
- 前臺需求列表
- 需求分析后臺
- 分類管理
- 屬性管理
- 產品管理
- 產品圖片管理
- 產品屬性設置
- 用戶管理
- 訂單管理
- 后臺需求列表
- 表結構設計
- 數據建模
- 表與表之間的關系
- 后臺-分類管理
- 可運行的項目
- 靜態資源
- JSP包含關系
- 查詢
- 分頁
- 增加
- 刪除
- 編輯
- 修改
- 做一遍
- 重構
- 分頁方式
- 分類逆向工程
- 所有逆向工程
- 后臺其他頁面
- 屬性管理實現
- 產品管理實現
- 產品圖片管理實現
- 產品屬性值設置
- 用戶管理實現
- 訂單管理實現
- 前端
- 前臺-首頁
- 可運行的項目
- 靜態資源
- ForeController
- home方法
- home.jsp
- homePage.jsp
- 前臺-無需登錄
- 注冊
- 登錄
- 退出
- 產品頁
- 模態登錄
- 分類頁
- 搜索
- 前臺-需要登錄
- 購物流程
- 立即購買
- 結算頁面
- 加入購物車
- 查看購物車頁面
- 登錄狀態攔截器
- 其他攔截器
- 購物車頁面操作
- 訂單狀態圖
- 生成訂單
- 我的訂單頁
- 我的訂單頁操作
- 評價產品
- 總結