• ssm宠物商城管理系统源码


    在 Internet飞速开展的今天,互联网成为人们快速获取、发布和传 递信息的重要渠道,它在人们学习、工作、生活等各个方面发挥着重要的作用。 因此建立在 Internet应用上的地位显而易见,它已成为政府、企事业单位信息化 建立中的重要组成局部,从而倍受人们的重视。
    宠物正在成为不少家庭里的新成员。随着养宠物的家庭不断增多,宠物经济也越来越受
    人关注。 目前从养宠物的数量和消费能力上看,、、、和已经成为我国五大“宠物城市〞,在这些城 市。而 XX、、、、等城市,宠物普及程度也相当高。不少业人士表示,随着日前公布的"宠物
    条例"中免去每年宠物年检费用的政策出台后,可能会有更多人参加养宠物的行列,中国宠 物市场的潜力仍待挖掘。
      如此大的市场自然吸引了众商家的眼球,围绕“宠物赚钱〞(指宠物交易本身)和“赚宠
    物的钱〞这两个主题,市场可提供的工程越来越多,为宠物衣食住行、生老病死支出的费用
    也在逐年增加,个别已经面临效劳升级的工程收费更是高得惊人。由于饲养宠物是一个循环
    消费的过程,消费者需要不停地支出,因此宠物产业成为投资者非常看中的热点行业。

     

    项目运行效果视频如下:

    ssm宠物商城管理系统源码

    关键代码:

    1. package com.controller;
    2. import java.util.Objects;
    3. import javax.servlet.http.HttpServletRequest;
    4. import javax.servlet.http.HttpSession;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RequestParam;
    9. import org.springframework.web.bind.annotation.ResponseBody;
    10. import org.springframework.web.multipart.MultipartFile;
    11. import com.entity.Admins;
    12. import com.entity.Goods;
    13. import com.entity.Tops;
    14. import com.entity.Types;
    15. import com.entity.Users;
    16. import com.service.AdminService;
    17. import com.service.GoodService;
    18. import com.service.OrderService;
    19. import com.service.TopService;
    20. import com.service.TypeService;
    21. import com.service.UserService;
    22. import com.util.PageUtil;
    23. import com.util.SafeUtil;
    24. import com.util.UploadUtil;
    25. /**
    26. * 后台相关接口
    27. */
    28. @Controller
    29. @RequestMapping("/admin")
    30. public class AdminController {
    31. private static final int rows = 10;
    32. @Autowired
    33. private AdminService adminService;
    34. @Autowired
    35. private OrderService orderService;
    36. @Autowired
    37. private UserService userService;
    38. @Autowired
    39. private GoodService goodService;
    40. @Autowired
    41. private TopService topService;
    42. @Autowired
    43. private TypeService typeService;
    44. /**
    45. * 管理员登录
    46. * @return
    47. */
    48. @RequestMapping("/login")
    49. public String login(Admins admin, HttpServletRequest request, HttpSession session) {
    50. if (adminService.checkUser(admin.getUsername(), admin.getPassword())) {
    51. session.setAttribute("username", admin.getUsername());
    52. return "redirect:index";
    53. }
    54. request.setAttribute("msg", "用户名或密码错误!");
    55. return "/admin/login.jsp";
    56. }
    57. /**
    58. * 退出
    59. * @return
    60. */
    61. @RequestMapping("/logout")
    62. public String logout(HttpSession session) {
    63. session.removeAttribute("admin");
    64. return "/admin/login.jsp";
    65. }
    66. /**
    67. * 后台首页
    68. * @return
    69. */
    70. @RequestMapping("/index")
    71. public String index(HttpServletRequest request) {
    72. request.setAttribute("msg", "恭喜你! 登录成功了");
    73. return "/admin/index.jsp";
    74. }
    75. /**
    76. * 订单列表
    77. *
    78. * @return
    79. */
    80. @RequestMapping("/orderList")
    81. public String orderList(@RequestParam(required=false, defaultValue="0")byte status, HttpServletRequest request,
    82. @RequestParam(required=false, defaultValue="1") int page) {
    83. request.setAttribute("flag", 1);
    84. request.setAttribute("status", status);
    85. request.setAttribute("orderList", orderService.getList(status, page, rows));
    86. request.setAttribute("pageTool", PageUtil.getPageTool(request, orderService.getTotal(status), page, rows));
    87. return "/admin/order_list.jsp";
    88. }
    89. /**
    90. * 订单发货
    91. *
    92. * @return
    93. */
    94. @RequestMapping("/orderDispose")
    95. public String orderDispose(int id, byte status,
    96. @RequestParam(required=false, defaultValue="1") int page) {
    97. orderService.dispose(id);
    98. return "redirect:orderList?flag=1&status="+status+"&page="+page;
    99. }
    100. /**
    101. * 订单完成
    102. *
    103. * @return
    104. */
    105. @RequestMapping("/orderFinish")
    106. public String orderFinish(int id, byte status,
    107. @RequestParam(required=false, defaultValue="1") int page) {
    108. orderService.finish(id);
    109. return "redirect:orderList?flag=1&status="+status+"&page="+page;
    110. }
    111. /**
    112. * 订单删除
    113. *
    114. * @return
    115. */
    116. @RequestMapping("/orderDelete")
    117. public String orderDelete(int id, byte status,
    118. @RequestParam(required=false, defaultValue="1") int page) {
    119. orderService.delete(id);
    120. return "redirect:orderList?flag=1&status="+status+"&page="+page;
    121. }
    122. /**
    123. * 顾客管理
    124. *
    125. * @return
    126. */
    127. @RequestMapping("/userList")
    128. public String userList(HttpServletRequest request,
    129. @RequestParam(required=false, defaultValue="1") int page) {
    130. request.setAttribute("flag", 2);
    131. request.setAttribute("userList", userService.getList(page, rows));
    132. request.setAttribute("pageTool", PageUtil.getPageTool(request, userService.getTotal(), page, rows));
    133. return "/admin/user_list.jsp";
    134. }
    135. /**
    136. * 顾客添加
    137. *
    138. * @return
    139. */
    140. @RequestMapping("/userAdd")
    141. public String userAdd(HttpServletRequest request) {
    142. request.setAttribute("flag", 2);
    143. return "/admin/user_add.jsp";
    144. }
    145. /**
    146. * 顾客添加
    147. *
    148. * @return
    149. */
    150. @RequestMapping("/userSave")
    151. public String userSave(Users user, HttpServletRequest request,
    152. @RequestParam(required=false, defaultValue="1") int page) {
    153. if (userService.isExist(user.getUsername())) {
    154. request.setAttribute("msg", "用户名已存在!");
    155. return "/admin/user_add.jsp";
    156. }
    157. userService.add(user);
    158. return "redirect:userList?flag=2&page="+page;
    159. }
    160. /**
    161. * 顾客密码重置页面
    162. *
    163. * @return
    164. */
    165. @RequestMapping("/userRe")
    166. public String userRe(int id, HttpServletRequest request) {
    167. request.setAttribute("flag", 2);
    168. request.setAttribute("user", userService.get(id));
    169. return "/admin/user_reset.jsp";
    170. }
    171. /**
    172. * 顾客密码重置
    173. *
    174. * @return
    175. */
    176. @RequestMapping("/userReset")
    177. public String userReset(Users user,
    178. @RequestParam(required=false, defaultValue="1") int page) {
    179. String password = SafeUtil.encode(user.getPassword());
    180. user = userService.get(user.getId());
    181. user.setPassword(password);
    182. userService.update(user);
    183. return "redirect:userList?flag=2&page="+page;
    184. }
    185. /**
    186. * 顾客更新
    187. *
    188. * @return
    189. */
    190. @RequestMapping("/userEdit")
    191. public String userEdit(int id, HttpServletRequest request) {
    192. request.setAttribute("flag", 2);
    193. request.setAttribute("user", userService.get(id));
    194. return "/admin/user_edit.jsp";
    195. }
    196. /**
    197. * 顾客更新
    198. *
    199. * @return
    200. */
    201. @RequestMapping("/userUpdate")
    202. public String userUpdate(Users user,
    203. @RequestParam(required=false, defaultValue="1") int page) {
    204. userService.update(user);
    205. return "redirect:userList?flag=2&page="+page;
    206. }
    207. /**
    208. * 顾客删除
    209. *
    210. * @return
    211. */
    212. @RequestMapping("/userDelete")
    213. public String userDelete(Users user,
    214. @RequestParam(required=false, defaultValue="1") int page) {
    215. userService.delete(user);
    216. return "redirect:userList?flag=2&page="+page;
    217. }
    218. /**
    219. * 产品列表
    220. *
    221. * @return
    222. */
    223. @RequestMapping("/goodList")
    224. public String goodList(@RequestParam(required=false, defaultValue="0")byte status, HttpServletRequest request,
    225. @RequestParam(required=false, defaultValue="1") int page) {
    226. request.setAttribute("flag", 3);
    227. request.setAttribute("page", page);
    228. request.setAttribute("status", status);
    229. request.setAttribute("goodList", goodService.getList(status, page, rows));
    230. request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getTotal(status), page, rows));
    231. return "/admin/good_list.jsp";
    232. }
    233. /**
    234. * 产品添加
    235. *
    236. * @return
    237. */
    238. @RequestMapping("/goodAdd")
    239. public String goodAdd(HttpServletRequest request) {
    240. request.setAttribute("flag", 3);
    241. request.setAttribute("typeList", typeService.getList());
    242. return "/admin/good_add.jsp";
    243. }
    244. /**
    245. * 产品添加
    246. *
    247. * @return
    248. * @throws Exception
    249. */
    250. @RequestMapping("/goodSave")
    251. public String goodSave(String name, int price, String intro, int stock, int typeId,
    252. MultipartFile cover, MultipartFile image1, MultipartFile image2,
    253. @RequestParam(required=false, defaultValue="1") int page) throws Exception {
    254. Goods good = new Goods();
    255. good.setName(name);
    256. good.setPrice(price);
    257. good.setIntro(intro);
    258. good.setStock(stock);
    259. good.setTypeId(typeId);
    260. good.setCover(UploadUtil.fileUpload(cover));
    261. good.setImage1(UploadUtil.fileUpload(image1));
    262. good.setImage2(UploadUtil.fileUpload(image2));
    263. goodService.add(good);
    264. return "redirect:goodList?flag=3&page="+page;
    265. }
    266. /**
    267. * 产品更新
    268. *
    269. * @return
    270. */
    271. @RequestMapping("/goodEdit")
    272. public String goodEdit(int id, HttpServletRequest request) {
    273. request.setAttribute("flag", 3);
    274. request.setAttribute("typeList", typeService.getList());
    275. request.setAttribute("good", goodService.get(id));
    276. return "/admin/good_edit.jsp";
    277. }
    278. /**
    279. * 产品更新
    280. *
    281. * @return
    282. * @throws Exception
    283. */
    284. @RequestMapping("/goodUpdate")
    285. public String goodUpdate(int id, String name, int price, String intro, int stock, int typeId,
    286. MultipartFile cover, MultipartFile image1, MultipartFile image2,
    287. @RequestParam(required=false, defaultValue="1") int page) throws Exception {
    288. Goods good = goodService.get(id);
    289. good.setName(name);
    290. good.setPrice(price);
    291. good.setIntro(intro);
    292. good.setStock(stock);
    293. good.setTypeId(typeId);
    294. if (Objects.nonNull(cover) && !cover.isEmpty()) {
    295. good.setCover(UploadUtil.fileUpload(cover));
    296. }
    297. if (Objects.nonNull(image1) && !image1.isEmpty()) {
    298. good.setImage1(UploadUtil.fileUpload(image1));
    299. }
    300. if (Objects.nonNull(image2) && !image2.isEmpty()) {
    301. good.setImage2(UploadUtil.fileUpload(image2));
    302. }
    303. goodService.update(good);
    304. return "redirect:goodList?flag=3&page="+page;
    305. }
    306. /**
    307. * 产品删除
    308. *
    309. * @return
    310. */
    311. @RequestMapping("/goodDelete")
    312. public String goodDelete(int id,
    313. @RequestParam(required=false, defaultValue="1") int page) {
    314. goodService.delete(id);
    315. return "redirect:goodList?flag=3&page="+page;
    316. }
    317. /**
    318. * 添加推荐
    319. * @return
    320. */
    321. @RequestMapping("/topSave")
    322. public @ResponseBody String topSave(Tops tops,
    323. @RequestParam(required=false, defaultValue="0")byte status,
    324. @RequestParam(required=false, defaultValue="1") int page) {
    325. int id = topService.add(tops);
    326. return id > 0 ? "ok" : null;
    327. }
    328. /**
    329. * 删除推荐
    330. * @return
    331. */
    332. @RequestMapping("/topDelete")
    333. public @ResponseBody String topDelete(Tops tops,
    334. @RequestParam(required=false, defaultValue="0")byte status,
    335. @RequestParam(required=false, defaultValue="1") int page) {
    336. boolean flag = topService.delete(tops);
    337. return flag ? "ok" : null;
    338. }
    339. /**
    340. * 类目列表
    341. *
    342. * @return
    343. */
    344. @RequestMapping("/typeList")
    345. public String typeList(HttpServletRequest request) {
    346. request.setAttribute("flag", 4);
    347. request.setAttribute("typeList", typeService.getList());
    348. return "/admin/type_list.jsp";
    349. }
    350. /**
    351. * 类目添加
    352. *
    353. * @return
    354. */
    355. @RequestMapping("/typeSave")
    356. public String typeSave(Types type,
    357. @RequestParam(required=false, defaultValue="1") int page) {
    358. typeService.add(type);
    359. return "redirect:typeList?flag=4&page="+page;
    360. }
    361. /**
    362. * 类目更新
    363. *
    364. * @return
    365. */
    366. @RequestMapping("/typeEdit")
    367. public String typeUp(int id, HttpServletRequest request) {
    368. request.setAttribute("flag", 4);
    369. request.setAttribute("type", typeService.get(id));
    370. return "/admin/type_edit.jsp";
    371. }
    372. /**
    373. * 类目更新
    374. *
    375. * @return
    376. */
    377. @RequestMapping("/typeUpdate")
    378. public String typeUpdate(Types type,
    379. @RequestParam(required=false, defaultValue="1") int page) {
    380. typeService.update(type);
    381. return "redirect:typeList?flag=4&page="+page;
    382. }
    383. /**
    384. * 类目删除
    385. *
    386. * @return
    387. */
    388. @RequestMapping("/typeDelete")
    389. public String typeDelete(Types type,
    390. @RequestParam(required=false, defaultValue="1") int page) {
    391. typeService.delete(type);
    392. return "redirect:typeList?flag=4&page="+page;
    393. }
    394. /**
    395. * 管理员列表
    396. *
    397. * @return
    398. */
    399. @RequestMapping("/adminList")
    400. public String adminList(HttpServletRequest request,
    401. @RequestParam(required=false, defaultValue="1") int page) {
    402. request.setAttribute("flag", 5);
    403. request.setAttribute("adminList", adminService.getList(page, rows));
    404. request.setAttribute("pageTool", PageUtil.getPageTool(request, adminService.getTotal(), page, rows));
    405. return "/admin/admin_list.jsp";
    406. }
    407. /**
    408. * 管理员修改自己密码
    409. *
    410. * @return
    411. */
    412. @RequestMapping("/adminRe")
    413. public String adminRe(HttpServletRequest request, HttpSession session) {
    414. request.setAttribute("flag", 5);
    415. request.setAttribute("admin", adminService.getByUsername(String.valueOf(session.getAttribute("username"))));
    416. return "/admin/admin_reset.jsp";
    417. }
    418. /**
    419. * 管理员修改自己密码
    420. *
    421. * @return
    422. */
    423. @RequestMapping("/adminReset")
    424. public String adminReset(Admins admin, HttpServletRequest request) {
    425. request.setAttribute("flag", 5);
    426. if (adminService.get(admin.getId()).getPassword().equals(SafeUtil.encode(admin.getPassword()))) {
    427. admin.setPassword(SafeUtil.encode(admin.getPasswordNew()));
    428. adminService.update(admin);
    429. request.setAttribute("admin", admin);
    430. request.setAttribute("msg", "修改成功!");
    431. }else {
    432. request.setAttribute("msg", "原密码错误!");
    433. }
    434. return "/admin/admin_reset.jsp";
    435. }
    436. /**
    437. * 管理员添加
    438. *
    439. * @return
    440. */
    441. @RequestMapping("/adminSave")
    442. public String adminSave(Admins admin, HttpServletRequest request,
    443. @RequestParam(required=false, defaultValue="1") int page) {
    444. if (adminService.isExist(admin.getUsername())) {
    445. request.setAttribute("msg", "用户名已存在!");
    446. return "/admin/admin_add.jsp";
    447. }
    448. adminService.add(admin);
    449. return "redirect:adminList?flag=5&page="+page;
    450. }
    451. /**
    452. * 管理员修改
    453. *
    454. * @return
    455. */
    456. @RequestMapping("/adminEdit")
    457. public String adminEdit(int id, HttpServletRequest request) {
    458. request.setAttribute("flag", 5);
    459. request.setAttribute("admin", adminService.get(id));
    460. return "/admin/admin_edit.jsp";
    461. }
    462. /**
    463. * 管理员更新
    464. *
    465. * @return
    466. */
    467. @RequestMapping("/adminUpdate")
    468. public String adminUpdate(Admins admin,
    469. @RequestParam(required=false, defaultValue="1") int page) {
    470. admin.setPassword(SafeUtil.encode(admin.getPassword()));
    471. adminService.update(admin);
    472. return "redirect:adminList?flag=5&page="+page;
    473. }
    474. /**
    475. * 管理员删除
    476. *
    477. * @return
    478. */
    479. @RequestMapping("/adminDelete")
    480. public String adminDelete(Admins admin,
    481. @RequestParam(required=false, defaultValue="1") int page) {
    482. adminService.delete(admin);
    483. return "redirect:adminList?flag=5&page="+page;
    484. }
    485. }

     

     

    经济可行性
    随着计算机技术的飞速开展,计算机在企业管理中应用的普及,实现了企业业务管理的
    高效化、系统化、规化、自动化。同样随着宠物业的崛起,贝贝宠物公司已经成长为一个跨
    地区的大公司,并且公司的业务已遍布全国。而传统的经营模式已无法适合当今的庞大的数
    据处理和准确的运算需求。所以一套精巧完善的宠物网系统是提高工作效率节省人力物力财
    力的有效解决方案。拥有自己的一套特色的宠物系统是非常必要的。它可持续使用并能随着
    时代和工作的需求不断更新,一期投入终身受用,按长期的使用计算,开发系统的造价平均
    到每年与传统式的管理方式的年耗资本相比照,性价比是可行的。开发这套系统的经济可行
    性是很高的。
    关键代码2:
    1. package com.controller;
    2. import java.util.List;
    3. import java.util.Objects;
    4. import javax.annotation.Resource;
    5. import javax.servlet.ServletRequest;
    6. import javax.servlet.http.HttpSession;
    7. import org.springframework.stereotype.Controller;
    8. import org.springframework.ui.Model;
    9. import org.springframework.web.bind.annotation.RequestMapping;
    10. import org.springframework.web.bind.annotation.RequestParam;
    11. import org.springframework.web.bind.annotation.ResponseBody;
    12. import com.entity.Goods;
    13. import com.entity.Items;
    14. import com.entity.Orders;
    15. import com.entity.Users;
    16. import com.service.GoodService;
    17. import com.service.OrderService;
    18. import com.service.TypeService;
    19. import com.service.UserService;
    20. import com.util.SafeUtil;
    21. /**
    22. * 用户相关接口
    23. */
    24. @Controller
    25. @RequestMapping("/index")
    26. public class UserController{
    27. private static final String INDENT_KEY = "order";
    28. @Resource
    29. private UserService userService;
    30. @Resource
    31. private OrderService orderService;
    32. @Resource
    33. private GoodService goodService;
    34. @Resource
    35. private TypeService typeService;
    36. /**
    37. * 注册用户
    38. * @return
    39. */
    40. @RequestMapping("/register")
    41. public String register(@RequestParam(required=false, defaultValue="0")int flag, Users user, Model model){
    42. model.addAttribute("typeList", typeService.getList());
    43. if(flag==-1) {
    44. model.addAttribute("flag", 5); // 注册页面
    45. return "/index/register.jsp";
    46. }
    47. if (user.getUsername().isEmpty()) {
    48. model.addAttribute("msg", "用户名不能为空!");
    49. return "/index/register.jsp";
    50. }else if (userService.isExist(user.getUsername())) {
    51. model.addAttribute("msg", "用户名已存在!");
    52. return "/index/register.jsp";
    53. }else {
    54. String password = user.getPassword();
    55. userService.add(user);
    56. user.setPassword(password);
    57. return "redirect:login?flag=-1"; // 注册成功后转去登录
    58. }
    59. }
    60. /**
    61. * 用户登录
    62. * @return
    63. */
    64. @RequestMapping("/login")
    65. public String login(@RequestParam(required=false, defaultValue="0")int flag, Users user, HttpSession session, Model model) {
    66. model.addAttribute("typeList", typeService.getList());
    67. if(flag==-1) {
    68. flag = 6; // 登录页面
    69. return "/index/login.jsp";
    70. }
    71. if(userService.checkUser(user.getUsername(), user.getPassword())){
    72. session.setAttribute("user", userService.get(user.getUsername()));
    73. return "redirect:index";
    74. } else {
    75. model.addAttribute("msg", "用户名或密码错误!");
    76. return "/index/login.jsp";
    77. }
    78. }
    79. /**
    80. * 注销登录
    81. * @return
    82. */
    83. @RequestMapping("/logout")
    84. public String logout(HttpSession session) {
    85. session.removeAttribute("user");
    86. session.removeAttribute("order");
    87. return "/index/login.jsp";
    88. }
    89. /**
    90. * 查看购物车
    91. * @return
    92. */
    93. @RequestMapping("/cart")
    94. public String cart(Model model) {
    95. model.addAttribute("typeList", typeService.getList());
    96. return "/index/cart.jsp";
    97. }
    98. /**
    99. * 购买
    100. * @return
    101. */
    102. @RequestMapping("/buy")
    103. public @ResponseBody String buy(int goodid, HttpSession session){
    104. Goods goods = goodService.get(goodid);
    105. if (goods .getStock() <= 0) { // 库存不足
    106. return "empty";
    107. }
    108. Orders order = (Orders) session.getAttribute(INDENT_KEY);
    109. if (order==null) {
    110. session.setAttribute(INDENT_KEY, orderService.add(goods));
    111. }else {
    112. session.setAttribute(INDENT_KEY, orderService.addOrderItem(order, goods));
    113. }
    114. return "ok";
    115. }
    116. /**
    117. * 减少
    118. */
    119. @RequestMapping("/lessen")
    120. public @ResponseBody String lessen(int goodid, HttpSession session){
    121. Orders order = (Orders) session.getAttribute(INDENT_KEY);
    122. if (order != null) {
    123. session.setAttribute(INDENT_KEY, orderService.lessenIndentItem(order, goodService.get(goodid)));
    124. }
    125. return "ok";
    126. }
    127. /**
    128. * 删除
    129. */
    130. @RequestMapping("/delete")
    131. public @ResponseBody String delete(int goodid, HttpSession session){
    132. Orders order = (Orders) session.getAttribute(INDENT_KEY);
    133. if (order != null) {
    134. session.setAttribute(INDENT_KEY, orderService.deleteIndentItem(order, goodService.get(goodid)));
    135. }
    136. return "ok";
    137. }
    138. /**
    139. * 提交订单
    140. * @return
    141. */
    142. @RequestMapping("/save")
    143. public String save(ServletRequest request, HttpSession session, Model model){
    144. model.addAttribute("typeList", typeService.getList());
    145. Users user = (Users) session.getAttribute("user");
    146. if (user == null) {
    147. request.setAttribute("msg", "请登录后提交订单!");
    148. return "/index/login.jsp";
    149. }
    150. Orders sessionOrder = (Orders) session.getAttribute(INDENT_KEY);
    151. if (sessionOrder != null) {
    152. if (sessionOrder != null) {
    153. for(Items item : sessionOrder.getItemList()){ // 检测商品库存(防止库存不足)
    154. Goods product = goodService.get(item.getGoodId());
    155. if(item.getAmount() > product.getStock()){
    156. request.setAttribute("msg", "商品 ["+product.getName()+"] 库存不足! 当前库存数量: "+product.getStock());
    157. return "/index/cart.jsp";
    158. }
    159. }
    160. }
    161. sessionOrder.setUserId(user.getId());
    162. sessionOrder.setUser(userService.get(user.getId()));
    163. int orderid = orderService.save(sessionOrder); // 保存订单
    164. session.removeAttribute(INDENT_KEY); // 清除购物车
    165. return "redirect:topay?orderid="+orderid;
    166. }
    167. request.setAttribute("msg", "处理失败!");
    168. return "/index/cart.jsp";
    169. }
    170. /**
    171. * 支付页面
    172. * @return
    173. */
    174. @RequestMapping("/topay")
    175. public String topay(int orderid, ServletRequest request, Model model) {
    176. model.addAttribute("typeList", typeService.getList());
    177. request.setAttribute("order", orderService.get(orderid));
    178. return "/index/pay.jsp";
    179. }
    180. /**
    181. * 支付(模拟)
    182. * @return
    183. */
    184. @RequestMapping("/pay")
    185. public String pay(Orders order, Model model) {
    186. model.addAttribute("typeList", typeService.getList());
    187. orderService.pay(order);
    188. return "redirect:payok?orderid="+order.getId();
    189. }
    190. /**
    191. * 支付成功
    192. * @return
    193. */
    194. @RequestMapping("/payok")
    195. public String payok(int orderid, ServletRequest request, Model model) {
    196. model.addAttribute("typeList", typeService.getList());
    197. Orders order = orderService.get(orderid);
    198. int paytype = order.getPaytype();
    199. if(paytype == Orders.PAYTYPE_WECHAT || paytype == Orders.PAYTYPE_ALIPAY) {
    200. request.setAttribute("msg", "订单["+orderid+"]支付成功");
    201. }else {
    202. request.setAttribute("msg", "订单["+orderid+"]货到付款");
    203. }
    204. return "/index/payok.jsp";
    205. }
    206. /**
    207. * 查看订单
    208. * @return
    209. */
    210. @RequestMapping("/order")
    211. public String order(HttpSession session, Model model){
    212. model.addAttribute("flag", 3);
    213. model.addAttribute("typeList", typeService.getList());
    214. Users user = (Users) session.getAttribute("user");
    215. if (user == null) {
    216. model.addAttribute("msg", "请登录后查看订单!");
    217. return "/index/login.jsp";
    218. }
    219. List<Orders> orderList = orderService.getListByUserid(user.getId());
    220. if (orderList!=null && !orderList.isEmpty()) {
    221. for(Orders order : orderList){
    222. order.setItemList(orderService.getItemList(order.getId()));
    223. }
    224. }
    225. model.addAttribute("orderList", orderList);
    226. return "/index/order.jsp";
    227. }
    228. /**
    229. * 个人信息
    230. * @return
    231. */
    232. @RequestMapping("/my")
    233. public String my(Users user, HttpSession session, Model model){
    234. model.addAttribute("flag", 4);
    235. model.addAttribute("typeList", typeService.getList());
    236. Users userLogin = (Users) session.getAttribute("user");
    237. if (userLogin == null) {
    238. model.addAttribute("msg", "请先登录!");
    239. return "/index/login.jsp";
    240. }
    241. // 进入个人中心
    242. if (Objects.isNull(user) || Objects.isNull(user.getId())) {
    243. return "/index/my.jsp";
    244. }
    245. Users u = userService.get(user.getId());
    246. // 修改资料
    247. u.setName(user.getName());
    248. u.setPhone(user.getPhone());
    249. u.setAddress(user.getAddress());
    250. userService.update(u); // 更新数据库
    251. session.setAttribute("user", u); // 更新session
    252. model.addAttribute("msg", "信息修改成功!");
    253. // 修改密码
    254. if(user.getPasswordNew()!=null && !user.getPasswordNew().trim().isEmpty()) {
    255. if (user.getPassword()!=null && !user.getPassword().trim().isEmpty()
    256. && SafeUtil.encode(user.getPassword()).equals(u.getPassword())) {
    257. if (user.getPasswordNew()!=null && !user.getPasswordNew().trim().isEmpty()) {
    258. u.setPassword(SafeUtil.encode(user.getPasswordNew()));
    259. }
    260. userService.update(u); // 更新数据库
    261. session.setAttribute("user", u); // 更新session
    262. model.addAttribute("msg", "密码修改成功!");
    263. }else {
    264. model.addAttribute("msg", "原密码错误!");
    265. }
    266. }
    267. return "/index/my.jsp";
    268. }
    269. }

     

     

     

  • 相关阅读:
    基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(七)
    GSCoolink GSV6127 HDMI 2.0/DisplayPort 1.4到MIPI CSI-2嵌入式MCU混合转换器芯片
    C#开发的OpenRA游戏之世界存在的属性GivesExperience(4)
    「项目实战」一文读懂思科网络设备IOS系统
    你知道什么是物联网MQTT么?
    mysql源码分析——InnoDB的内存结构分析
    【技巧】JS代码这么写,前端小姐姐都会爱上你
    transformers架构实现
    AI语音机器人是否可以设计开放式问题
    java实现创建时间、修改时间自动生成
  • 原文地址:https://blog.csdn.net/weixin_46437112/article/details/128068907