• JSD-2204-酷莎商城(后端)-Day17,18


    1.酷鲨商城

     1.1酷鲨商城项目步骤

    • 准备工作:
    • 创建新工程coolshark 打3个√ 将微博工程中application.properties里面的内容复制到新工程,并且将数据库名称weibo改成cs
    • 从老师的工程中把static文件夹下的4个html页面和一个imgs文件夹复制到自己的工程, 然后ReBuild static文件夹
    • 关闭其它工程, 启动新工程, 访问首页测试,如果显示首页内容即测试成功!
    • 建库建表
    1. create database cs charset=utf8;
    2. use cs;
    3. create table user(id int primary key auto_increment,username varchar(50),password varchar(50),nick varchar(50));
    4. insert into user values(null,'admin','123456','管理员');

    1.1.1登录功能步骤:

    1. 在login.html页面中,在页面中先引入axios框架, 通过双向绑定得到用户输入的用户名和密码, 给按钮添加点击事件, 点击时向/login发出请求同时把用户的信息提交到服务器
    2. 创建UserController,User实体类和UserMapper
    3. 在Controller里面添加login方法 处理/login请求, 接收传递过来的用户信息,在方法中调用mapper的selectByUsername方法查询返回User对象.........
    4. 实现mapper的selectByUsername方法

    1.1.2首页展示分类步骤

    1. 建分类表和插入数据
        1. create table category(id int primary key auto_increment,name varchar(30));
        2. insert into category values(null,'精彩活动'),(null,'当季女装'),(null,'品牌男装'),(null,'环球美食'),(null,'医药健康');
    2. 创建Category实体类
    3. 创建CategoryMapper 里面提供select方法
    4. 创建CategoryController
    5. 在首页index.html中添加axios框架的引入, 在Vue里面添加created方法,在里面向/category/select发出请求, 获取所有分类的信息, 把得到的数据给到categoryArr数组
    6. 在CategoryController 里面创建select方法处理/select请求调用mapper里面的select方法把得到的数据响应给客户端

    1.1.3首页展示轮播图步骤:

    1. 建表并插入数据
        1. create table banner(id int primary key auto_increment,url varchar(200));
        2. insert into banner values(null,'/imgs/b2.jpg'),(null,'/imgs/b3.jpg'),(null,'/imgs/b4.jpg');
    2. 创建Banner实体类
    3. 创建BannerMapper 提供select方法
    4. 创建BannerController添加select方法处理 /banner/select请求,方法中调用mapper的select方法把得到的数据响应给客户端
    5. 在首页的created方法中 向/banner/select发出异步请求获取所有轮播图数据, 把得到的数据给到bannerArr数组, 数组内容由原来装字符串变成了装banner对象 所以页面中遍历bannerArr数组部分的代码需要改动

    1.1.4后台管理页面分类和轮播图展示

    1. 在admin.html页面添加created方法, 在里面发请求获取所有分类,把得到的数据赋值给categoryArr数组, 发请求获取所有轮播图把得到的数据赋值给bannerArr数组

    1.1.5添加分类步骤:

    1. 在admin.html页面中 点击添加分类时 弹出文本输入框获取输入的分类名然后 向/category/insert发出添加分类的请求
    2. 在CategoryController中添加insert方法处理请求,然后调用mapper的insert方法
    3. 实现mapper里面的insert方法

    1.1.6删除分类步骤:

    1. 在admin.html页面中给删除按钮添加点击事件
    2. 在事件方法中 向/category/delete发出请求 响应之后把数组中的数据删除 页面自动发生改变
    3. 在Controller里面添加delete方法处理/category/delete请求, 调用mapper里面的删除方法
    4. 实现mapper中的方法
    5. 把删除按钮 改成 气泡确认框

    1.1.7删除轮播图步骤:

    1. 在admin.html页面中给删除按钮添加点击事件
    2. 在事件方法中 向/banner/delete发出请求 响应之后把数组中的数据删除 页面自动发生改变
    3. 在Controller里面添加delete方法处理/banner/delete请求, 调用mapper里面的删除方法
    4. 实现mapper中的方法
    5. 把删除按钮 改成 气泡确认框

    1.1.8添加轮播图步骤:

    1. 创建insertBanner.html页面 使用上传图片的组件,
    2. 在页面中向/banner/insert发出请求
    3. 在Controller里面添加insert方法 处理/banner/insert请求 ,方法中调用mapper的insert方法
    4. 实现mapper里面insert方法 

    1.1.9商品分类相关

    • 在添加商品页面中的form表单里面增加一行,获取用户选择的分类, 在data里面的p对象中添加categoryId的属性
    • 在页面的created方法中发请求获取所有分类信息,赋值给arr数组
    • 给Product实体类添加categoryId属性
    • 给product表添加category_id字段
    • 在Mapper里面的insert方法中添加和分类id相关的内容

    1.1.10删除商品

    • 在admin.html页面中给删除按钮添加点击事件
    • 在事件方法中 向/product/delete发出请求 响应之后把数组中的数据删除 页面自动发生改变
    • 在productController里面添加delete方法处理/product/delete请求, 方法中删除图片,调用mapper里面的删除方法
    • 实现mapper中的方法;
    • 把删除按钮 改成 气泡确认框

    1.1.11排行榜展示

    • 在首页的created方法中发出获取排行榜信息的请求
    • ProductController处理请求 掉mapper中的selectTop方法获取排行榜数据
    • 实现mapper中的方法

    1.1.12查看详情页面步骤:

    • 给首页的商品标题和商品图片添加超链接 点击时跳转到详情页面
    • 在详情页面添加 created方法, 在方法中通过地址栏里面的id向/product/selectById 地址发出请求 把得到的商品信息赋值给data里面的product
    • 在ProductController中创建selectById方法处理/product/selectById请求, 调用mapper的selectById方法,把查询到的Product对象直接响应给客户端
    • 实现mapper里面的selectById方法

    1.1.13点击分类查看分类相关商品

    • 创建result.html页面, 复制首页粘贴改名, 把轮播图和排行榜删除
    • 在首页中给el-menu标签添加@select事件 调用handleSelect方法, 方法中跳转到result.html页面 同时 把得到的分类id传递到结果页面
    • 在result.html页面中的created方法里面向/product/selectByCid发出请求
    • ProductController里面添加selectByCid方法处理/product/selectByCid, 调用mapper里面的selectByCid方法把查询到的集合返回给客户端
    • 实现mapper里面的selectByCid方法

    1.1.14结果页面中点击分类时的步骤:

    1. 给result.html页面中的el-menu添加@Select事件 调用handleSelect方法,在方法中直接向/product/selectByCid发请求 把得到的数据给到productArr数组

    1.1.15搜索功能步骤:

    • 在首页中给文本框添加双向绑定,给搜索按钮添加点击事件, 点击时跳转到result.html结果页面,同时把搜索的文本内容做为参数传递过去
    • 在result.html页面中的created方法里面 判断location.search里面是否包含wd,如果包含则向/product/selectByWd发出请求
    • 在ProductController里面添加selectByWd方法处理/product/selectByWd请求,调用mapper里面selectByWd方法,把查询到的List集合返回给客户端
    • 实现mapper里面的selectByWd方法

    1.2项目目录展示

    1.3代码展示 

    1.3.1BannerController.java(轮播图控制层)

    1. package cn.tedu.coolshark.controller;
    2. import cn.tedu.coolshark.entitu.Banner;
    3. import cn.tedu.coolshark.mapping.BannerMapper;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.RequestMapping;
    6. import org.springframework.web.bind.annotation.RestController;
    7. import java.io.File;
    8. import java.util.List;
    9. @RestController
    10. public class BannerController {
    11. @Autowired
    12. BannerMapper mapper;
    13. @RequestMapping("/banner/select")
    14. public List selectBanner(){
    15. return mapper.selectBanner();
    16. }
    17. @RequestMapping("/banner/delete")
    18. public void deleteBanner(int id){
    19. String url = mapper.selectBannerById(id);
    20. new File("E:/files"+url).delete();
    21. mapper.deleteBanner(id);
    22. }
    23. @RequestMapping("/banner/insert")
    24. public void insertBanner(String url){
    25. mapper.insertBanner(url);
    26. }
    27. }

    1.3.2CategoryController.java(商品分类控制层)

    1. package cn.tedu.coolshark.controller;
    2. import cn.tedu.coolshark.entitu.Category;
    3. import cn.tedu.coolshark.mapping.CategoryMapping;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.RequestMapping;
    6. import org.springframework.web.bind.annotation.RestController;
    7. import java.util.List;
    8. @RestController
    9. public class CategoryController {
    10. @Autowired
    11. CategoryMapping mapping;
    12. @RequestMapping("/category/select")
    13. public List selectCategory(){
    14. return mapping.selectCategory();
    15. }
    16. @RequestMapping("/category/insert")
    17. public void insertCategory(String name){
    18. mapping.insertCategory(name);
    19. }
    20. @RequestMapping("/category/delete")
    21. public void deleteCategory(int id){
    22. mapping.deleteCategoryById(id);
    23. }
    24. }

    1.3.3ProductController.java(商品控制层)

    1. package cn.tedu.coolshark.controller;
    2. import cn.tedu.coolshark.entitu.Product;
    3. import cn.tedu.coolshark.mapping.ProductMapper;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.RequestBody;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RestController;
    8. import java.io.File;
    9. import java.util.List;
    10. @RestController
    11. public class ProductController {
    12. @Autowired
    13. ProductMapper mapper;
    14. @RequestMapping("/product/insert")
    15. public void insertProduct(@RequestBody Product product){
    16. System.out.println("product = " + product);
    17. mapper.insertProduct(product);
    18. }
    19. @RequestMapping("/product/select/admin")
    20. public List selectProductAdmin(){
    21. return mapper.selectProduct();
    22. }
    23. @RequestMapping("/product/delete")
    24. public void deleteProduct(int id){
    25. String url = mapper.selectProductUrlById(id);
    26. new File("E:/files"+url).delete();
    27. mapper.deleteProductById(id);
    28. }
    29. @RequestMapping("/product/select/index")
    30. public List selectProductIndex(){
    31. return mapper.selectProductIndex();
    32. }
    33. @RequestMapping("/product/select/top")
    34. public List selectProductTop(){
    35. return mapper.selectProductTop();
    36. }
    37. @RequestMapping("/product/selectById")
    38. public Product selectProductById(int id){
    39. System.out.println("id = " + id);
    40. //商品浏览量+1
    41. mapper.updateProductViewCountById(id);
    42. return mapper.selectProductById(id);
    43. }
    44. @RequestMapping("/product/selectByCid")
    45. public List selectProductByCid(int id){
    46. return mapper.selectProductByCid(id);
    47. }
    48. @RequestMapping("/product/selectByName")
    49. public List selectProductByName(String title){
    50. return mapper.selectProductByName(title);
    51. }
    52. }

    1.3.4UploadController.java(文件上传)

    1. package cn.tedu.coolshark.controller;
    2. import org.springframework.web.bind.annotation.RequestMapping;
    3. import org.springframework.web.bind.annotation.RestController;
    4. import org.springframework.web.multipart.MultipartFile;
    5. import java.io.File;
    6. import java.io.IOException;
    7. import java.util.UUID;
    8. @RestController
    9. public class UploadController {
    10. @RequestMapping("/upload")
    11. public String upload(MultipartFile picFile) throws IOException {
    12. //得到文件的原始文件名字
    13. String fileName = picFile.getOriginalFilename();
    14. //得到后缀
    15. String suffix = fileName.substring(fileName.lastIndexOf("."));
    16. //得到唯一未见名
    17. fileName = UUID.randomUUID()+suffix;
    18. //文件夹路径
    19. String dirPath = "E:/files";
    20. File dirFile = new File(dirPath);
    21. if (!dirFile.exists()){
    22. dirFile.mkdirs();
    23. }
    24. //完整的文件路径
    25. String filePath = dirPath+"/"+fileName;
    26. //吧文件的路径
    27. picFile.transferTo(new File(filePath));
    28. //吧文件路径返回给客户端
    29. return "/"+fileName;
    30. }
    31. @RequestMapping("/remove")
    32. public void remove(String url){
    33. //得到文件的完整路径
    34. String filePath = "E:/files"+url;
    35. //删除图片文件
    36. new File(filePath).delete();
    37. }
    38. }

    1.3.5UserController.java(用户控制层)

    1. package cn.tedu.coolshark.controller;
    2. import cn.tedu.coolshark.entitu.User;
    3. import cn.tedu.coolshark.mapping.UserMapping;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.RequestBody;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RestController;
    8. import javax.servlet.http.HttpSession;
    9. @RestController
    10. public class UserController {
    11. @Autowired
    12. UserMapping mapping;
    13. @RequestMapping("/login")
    14. public int login(@RequestBody User user, HttpSession session){
    15. User u = mapping.selectUserByName(user.getUsername());
    16. if (u!=null){
    17. if (u.getPassword().equals(user.getPassword())){
    18. session.setAttribute("user",u);
    19. return 1;
    20. }
    21. return 2;
    22. }
    23. return 3;
    24. }
    25. }

    1.3.6Banner.java(轮播图对象)

    1. package cn.tedu.coolshark.entitu;
    2. public class Banner {
    3. private Integer id;
    4. private String url;
    5. @Override
    6. public String toString() {
    7. return "Banner{" +
    8. "id=" + id +
    9. ", url='" + url + '\'' +
    10. '}';
    11. }
    12. public Integer getId() {
    13. return id;
    14. }
    15. public void setId(Integer id) {
    16. this.id = id;
    17. }
    18. public String getUrl() {
    19. return url;
    20. }
    21. public void setUrl(String url) {
    22. this.url = url;
    23. }
    24. }

    1.3.7Category.java(商品分类对象)

    1. package cn.tedu.coolshark.entitu;
    2. public class Category {
    3. private Integer id;
    4. private String name;
    5. @Override
    6. public String toString() {
    7. return "Category{" +
    8. "id=" + id +
    9. ", name='" + name + '\'' +
    10. '}';
    11. }
    12. public Integer getId() {
    13. return id;
    14. }
    15. public void setId(Integer id) {
    16. this.id = id;
    17. }
    18. public String getName() {
    19. return name;
    20. }
    21. public void setName(String name) {
    22. this.name = name;
    23. }
    24. }

    1.3.8Product.java(商品对象)

    1. package cn.tedu.coolshark.entitu;
    2. public class Product {
    3. private Integer id;
    4. private String title;
    5. private Double price;
    6. private Double oldPrice;
    7. private Integer num;
    8. private Integer saleCount;
    9. private String url;
    10. private Integer viewCount;
    11. private Integer categoryId;
    12. @Override
    13. public String toString() {
    14. return "Product{" +
    15. "id=" + id +
    16. ", title='" + title + '\'' +
    17. ", price=" + price +
    18. ", oldPrice=" + oldPrice +
    19. ", num=" + num +
    20. ", saleCount=" + saleCount +
    21. ", url='" + url + '\'' +
    22. ", viewCount=" + viewCount +
    23. ", categoryId=" + categoryId +
    24. '}';
    25. }
    26. public Integer getId() {
    27. return id;
    28. }
    29. public void setId(Integer id) {
    30. this.id = id;
    31. }
    32. public String getTitle() {
    33. return title;
    34. }
    35. public void setTitle(String title) {
    36. this.title = title;
    37. }
    38. public Double getPrice() {
    39. return price;
    40. }
    41. public void setPrice(Double price) {
    42. this.price = price;
    43. }
    44. public Double getOldPrice() {
    45. return oldPrice;
    46. }
    47. public void setOldPrice(Double oldPrice) {
    48. this.oldPrice = oldPrice;
    49. }
    50. public Integer getNum() {
    51. return num;
    52. }
    53. public void setNum(Integer num) {
    54. this.num = num;
    55. }
    56. public Integer getSaleCount() {
    57. return saleCount;
    58. }
    59. public void setSaleCount(Integer saleCount) {
    60. this.saleCount = saleCount;
    61. }
    62. public String getUrl() {
    63. return url;
    64. }
    65. public void setUrl(String url) {
    66. this.url = url;
    67. }
    68. public Integer getViewCount() {
    69. return viewCount;
    70. }
    71. public void setViewCount(Integer viewCount) {
    72. this.viewCount = viewCount;
    73. }
    74. public Integer getCategoryId() {
    75. return categoryId;
    76. }
    77. public void setCategoryId(Integer categoryId) {
    78. this.categoryId = categoryId;
    79. }
    80. }

    1.3.9User.java(用户对象)

    1. package cn.tedu.coolshark.entitu;
    2. public class User {
    3. private Integer id;
    4. private String username;
    5. private String password;
    6. private String nick;
    7. @Override
    8. public String toString() {
    9. return "User{" +
    10. "id=" + id +
    11. ", username='" + username + '\'' +
    12. ", password='" + password + '\'' +
    13. ", nick='" + nick + '\'' +
    14. '}';
    15. }
    16. public Integer getId() {
    17. return id;
    18. }
    19. public void setId(Integer id) {
    20. this.id = id;
    21. }
    22. public String getUsername() {
    23. return username;
    24. }
    25. public void setUsername(String username) {
    26. this.username = username;
    27. }
    28. public String getPassword() {
    29. return password;
    30. }
    31. public void setPassword(String password) {
    32. this.password = password;
    33. }
    34. public String getNick() {
    35. return nick;
    36. }
    37. public void setNick(String nick) {
    38. this.nick = nick;
    39. }
    40. }

    1.3.10BannerMapper.java(跟轮播图有关的数据库操作)

    1. package cn.tedu.coolshark.mapping;
    2. import cn.tedu.coolshark.entitu.Banner;
    3. import org.apache.ibatis.annotations.Delete;
    4. import org.apache.ibatis.annotations.Insert;
    5. import org.apache.ibatis.annotations.Mapper;
    6. import org.apache.ibatis.annotations.Select;
    7. import java.util.List;
    8. @Mapper
    9. public interface BannerMapper {
    10. @Select("select * from banner")
    11. List selectBanner();
    12. @Delete("delete from banner where id = #{id}")
    13. void deleteBanner(int id);
    14. @Insert("insert into banner values(null,#{url})")
    15. void insertBanner(String url);
    16. @Select("select url from banner where id = #{id}")
    17. String selectBannerById(int id);
    18. }

    1.3.11CategoryMapping.java(跟导航菜单栏有关的数据库操作)

    1. package cn.tedu.coolshark.mapping;
    2. import cn.tedu.coolshark.entitu.Category;
    3. import org.apache.ibatis.annotations.Delete;
    4. import org.apache.ibatis.annotations.Insert;
    5. import org.apache.ibatis.annotations.Mapper;
    6. import org.apache.ibatis.annotations.Select;
    7. import java.util.List;
    8. @Mapper
    9. public interface CategoryMapping {
    10. @Select("select * from category")
    11. List selectCategory();
    12. @Insert("insert into category values(null,#{name})")
    13. void insertCategory(String name);
    14. @Delete("delete from category where id = #{id}")
    15. void deleteCategoryById(int id);
    16. }

    1.3.12ProductMapper.java(跟商品有关的数据库操作)

    1. package cn.tedu.coolshark.mapping;
    2. import cn.tedu.coolshark.entitu.Product;
    3. import org.apache.ibatis.annotations.*;
    4. import java.util.List;
    5. @Mapper
    6. public interface ProductMapper {
    7. @Insert("insert into product values(null,#{title},#{url},#{price},#{oldPrice},0,#{num},#{saleCount},#{categoryId})")
    8. void insertProduct(Object product);
    9. @Select("select id,title,price,old_price,sale_count,url from product")
    10. List selectProduct();
    11. @Select("select url from product where id = #{id}")
    12. String selectProductUrlById(int id);
    13. @Delete("delete from product where id = #{id}")
    14. void deleteProductById(int id);
    15. @Select("select id,title,url,price,old_price,sale_count from product")
    16. List selectProductIndex();
    17. @Select("select id,title,sale_count from product order by sale_count desc limit 0,6")
    18. List selectProductTop();
    19. @Select("select id,title,url,price,old_price,sale_count,view_count from product where id = #{id}")
    20. Product selectProductById(int id);
    21. @Update("update product set view_count = view_count+1 where id = #{id}")
    22. void updateProductViewCountById(int id);
    23. @Select("select id,title,url,price,old_price,sale_count from product where category_id = #{id}")
    24. List selectProductByCid(int id);
    25. //concat()时sql语句中用于拼接字符串的函数
    26. @Select("select id,title,url,price,old_price,sale_count from product where title like concat('%',#{title},'%')")
    27. List selectProductByName(String title);
    28. }

    1.3.13UserMapping.java(跟用户有关的数据库操作)

    1. package cn.tedu.coolshark.mapping;
    2. import cn.tedu.coolshark.entitu.User;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import org.apache.ibatis.annotations.Select;
    5. @Mapper
    6. public interface UserMapping {
    7. @Select("select id,password,nick from user where username = #{username}")
    8. User selectUserByName(String username);
    9. }

    1.3.14admin.html(商品后天管理页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. head>
    7. <body>
    8. <div id="app">
    9. <el-container>
    10. <el-header style="background-color: #0095d7">
    11. <h1 style="color: white;font-size: 22px">CoolShark商城后台管理系统
    12. <span style="float: right">欢迎xxx回来! <a href="">退出登录a>span>
    13. h1>
    14. el-header>
    15. <el-container>
    16. <el-aside width="200px">
    17. <el-menu @select="handleSelect" :default-openeds="['1']">
    18. <el-submenu index="1">
    19. <template slot="title">
    20. <i class="el-icon-s-flag"> 分类管理i>
    21. template>
    22. <el-menu-item index="1-1">分类列表el-menu-item>
    23. <el-menu-item index="1-2">添加分类el-menu-item>
    24. el-submenu>
    25. <el-submenu index="2">
    26. <template slot="title">
    27. <i class="el-icon-picture"> 轮播图管理i>
    28. template>
    29. <el-menu-item index="2-1">轮播图列表el-menu-item>
    30. <el-menu-item index="2-2">添加轮播图el-menu-item>
    31. el-submenu>
    32. <el-submenu index="3">
    33. <template slot="title">
    34. <i class="el-icon-shopping-cart-2"> 商品管理i>
    35. template>
    36. <el-menu-item index="3-1">商品列表el-menu-item>
    37. <el-menu-item index="3-2">添加商品el-menu-item>
    38. el-submenu>
    39. el-menu>
    40. el-aside>
    41. <el-main>
    42. <el-table v-if="selectedIndex=='1-1'" :data="categoryArr" style="width: 100%">
    43. <el-table-column type="index" label="编号" width="280">
    44. el-table-column>
    45. <el-table-column prop="name" label="名字" width="280">
    46. el-table-column>
    47. <el-table-column label="操作">
    48. <template slot-scope="scope">
    49. <el-popconfirm
    50. title="确认删除吗?"
    51. @confirm="categoryDelete(scope.$index, scope.row)"
    52. >
    53. <el-button slot="reference" size="mini" type="danger">删除el-button>
    54. el-popconfirm>
    55. template>
    56. el-table-column>
    57. el-table>
    58. <el-table v-if="selectedIndex=='2-1'" :data="bannerArr" style="width: 100%">
    59. <el-table-column type="index" label="编号" width="280">
    60. el-table-column>
    61. <el-table-column label="轮播图" width="280">
    62. <template slot-scope="scope">
    63. <img :src="scope.row.url" width="100%" alt="">
    64. template>
    65. el-table-column>
    66. <el-table-column label="操作">
    67. <template slot-scope="scope">
    68. <el-popconfirm
    69. title="确认删除吗?"
    70. @confirm="bannerDelete(scope.$index, scope.row)"
    71. >
    72. <el-button slot="reference" size="mini" type="danger">删除el-button>
    73. el-popconfirm>
    74. template>
    75. el-table-column>
    76. el-table>
    77. <el-table v-if="selectedIndex=='3-1'" :data="productArr" style="width: 100%">
    78. <el-table-column type="index" label="编号" width="100">
    79. el-table-column>
    80. <el-table-column prop="title" label="商品标题" width="200">
    81. el-table-column>
    82. <el-table-column prop="price" label="价格" width="100">
    83. el-table-column>
    84. <el-table-column prop="oldPrice" label="原价" width="100">
    85. el-table-column>
    86. <el-table-column prop="saleCount" label="销量" width="100">
    87. el-table-column>
    88. <el-table-column label="商品图片" width="100">
    89. <template slot-scope="scope">
    90. <img :src="scope.row.url" width="100%" alt="">
    91. template>
    92. el-table-column>
    93. <el-table-column label="操作">
    94. <template slot-scope="scope">
    95. <el-popconfirm
    96. title="确认删除吗?"
    97. @confirm="productDelete(scope.$index, scope.row)"
    98. >
    99. <el-button slot="reference" size="mini" type="danger">删除el-button>
    100. el-popconfirm>
    101. template>
    102. el-table-column>
    103. el-table>
    104. el-main>
    105. el-container>
    106. el-container>
    107. div>
    108. body>
    109. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    110. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    111. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    112. <script>
    113. let v = new Vue({
    114. el: '#app',
    115. data: function() {
    116. return {//在这里面定义变量
    117. selectedIndex:"1-1",
    118. categoryArr: [{id: 1, name: "精彩活动"}, {id: 2, name: "当季女装"},
    119. {id: 3, name: "品牌男装"}, {id: 4, name: "环球美食"}, {id: 5, name: "医药健康"},
    120. {id: 6, name: "美妆彩妆"}, {id: 7, name: "母婴产品"}
    121. ],
    122. bannerArr:[],
    123. productArr:[{title:"森马牛仔裤女宽松慢跑裤运动风2022春季新款显瘦束脚长裤复古",price:233,oldPrice:598,url:"imgs/a.jpg",saleCount:2342},
    124. {title:"茵曼马甲连衣裙两件套春季新款娃娃领色织格长袖背心裙套装",price:233,oldPrice:598,url:"imgs/b.jpg",saleCount:2342},
    125. {title:"雪中飞墨绿色短袖t恤女夏2022新款纯棉半袖打底体恤夏季上衣潮ins",price:233,oldPrice:598,url:"imgs/c.jpg",saleCount:2342},
    126. {title:"【佟丽娅同款】鸭鸭明星同款羽绒服2021年冬季新款时尚连帽外套冬",price:233,oldPrice:598,url:"imgs/d.jpg",saleCount:2342},
    127. {title:"BEASTER小恶魔鬼脸明星同款夹克毛绒保暖加厚字母印花宽松外套ins",price:233,oldPrice:598,url:"imgs/e.jpg",saleCount:2342},
    128. {title:"香影毛呢外套女中长款2021年冬季新款气质韩版娃娃领紫色呢子大衣",price:233,oldPrice:598,url:"imgs/f.jpg",saleCount:2342},
    129. {title:"SEMIR森马商场同款打底针织毛衣纯色高领新品显瘦",price:233,oldPrice:598,url:"imgs/g.jpg",saleCount:2342},
    130. {title:"美特斯邦威女MTEE 贺岁系列中长款风衣736598",price:233,oldPrice:598,url:"imgs/h.jpg",saleCount:2342},
    131. {title:"imone2021秋款黑色小西装外套女韩版学生宽松学院风外套jk外套",price:233,oldPrice:598,url:"imgs/i.jpg",saleCount:2342},
    132. {title:"BEASTER 小恶魔明星同款保暖长袖街头潮流连帽卫衣情侣上衣",price:233,oldPrice:598,url:"imgs/j.jpg",saleCount:2342},
    133. {title:"憨厚皇后100%绵羊皮2021秋海宁真皮皮衣女长款修身绵羊皮风衣外",price:233,oldPrice:598,url:"imgs/k.jpg",saleCount:2342},
    134. {title:"美特斯邦威高腰牛仔裤女宽松小脚新款春秋彩色潮流女士牛仔",price:233,oldPrice:598,url:"imgs/a.jpg",saleCount:2342}]
    135. }
    136. },
    137. methods:{
    138. productDelete(index,product){
    139. //发出删除请求
    140. axios.get("/product/delete?id="+product.id).then(function () {
    141. v.productArr.splice(index,1);
    142. })
    143. },
    144. categoryDelete(index,category){
    145. //发出删除请求
    146. axios.get("/category/delete?id="+category.id).then(function () {
    147. //删除数组中的元素对象 页面会自动发生改变,比直接刷新页面更节省流量
    148. //splice(数组下标,删除数量)
    149. v.categoryArr.splice(index,1)
    150. })
    151. },
    152. bannerDelete(index,banner){
    153. axios.get("/banner/delete?id="+banner.id).then(function () {
    154. //删除数组中的元素对象 页面会自动发生改变,比直接刷新页面更节省流量
    155. //splice(数组下标,删除数量)
    156. v.bannerArr.splice(index,1)
    157. })
    158. },
    159. handleSelect(index){
    160. if (index == "1-2"){
    161. let name = prompt("请输入分类名称");
    162. //判断出点击取消 未输入内容的情况
    163. if (name == null || name.trim()==""){
    164. return;
    165. }
    166. //发出添加分类的请求
    167. axios.get("/category/insert?name="+name).then(function () {
    168. location.reload()
    169. })
    170. }else if(index == "2-2"){
    171. location.href = "/insertBanner.html";
    172. }else if(index == "3-2"){
    173. location.href = "/insertProduct.html";
    174. }
    175. console.log(index);
    176. v.selectedIndex = index;
    177. }
    178. },
    179. created:function () {
    180. //标题菜单
    181. axios.get("/category/select").then(function (response) {
    182. v.categoryArr = response.data;
    183. })
    184. //轮播图片
    185. axios.get("/banner/select").then(function (response) {
    186. v.bannerArr = response.data;
    187. })
    188. //商品信息展示
    189. axios.get("/product/select/admin").then(function (response) {
    190. v.productArr = response.data;
    191. })
    192. }
    193. })
    194. script>
    195. html>

    1.3.15detail.html(商品详情页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. <style>
    7. header a {
    8. text-decoration: none;
    9. color: #6c6c6c;
    10. }
    11. .el-menu.el-menu--horizontal {
    12. border-bottom: none;
    13. }
    14. .el-table .el-table__cell{
    15. padding: 0;/*去掉排行榜表格中上下的内边距*/
    16. }
    17. style>
    18. head>
    19. <body>
    20. <div id="app">
    21. <el-container>
    22. <el-header height="150">
    23. <div style="width: 1200px;margin: 0 auto">
    24. <img src="imgs/logo.png" style="width: 300px;vertical-align: middle" alt="">
    25. <span>
    26. <a href="">首页a><el-divider direction="vertical">el-divider>
    27. <a href="">热点咨询a><el-divider direction="vertical">el-divider>
    28. <a href="">商家入驻a><el-divider direction="vertical">el-divider>
    29. <a href="">社会招聘a><el-divider direction="vertical">el-divider>
    30. <a href="">校园招聘a><el-divider direction="vertical">el-divider>
    31. <a href="">帮助a>
    32. span>
    33. div>
    34. <div style="background-color: #82c8ec">
    35. <el-menu style="width: 1200px;margin: 0 auto"
    36. :default-active="1"
    37. class="el-menu-demo"
    38. mode="horizontal"
    39. background-color="#82c8ec"
    40. text-color="#fff"
    41. active-text-color="#fff">
    42. <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}el-menu-item>
    43. <div style="float: right;margin-top: 10px">
    44. <el-input v-model="title" placeholder="请输入搜索内容">
    45. <el-button slot="append" icon="el-icon-search" @click="handleSelectLink(title)">el-button>
    46. el-input>
    47. div>
    48. el-menu>
    49. div>
    50. el-header>
    51. <el-main style="width: 1200px;margin: 0 auto">
    52. <el-row :gutter="20">
    53. <el-col :span="12">
    54. <el-card>
    55. <img :src="product.url" width="100%" alt="">
    56. el-card>
    57. el-col>
    58. <el-col :span="12">
    59. <p style="font-size: 25px">{{product.title}}p>
    60. <el-divider>el-divider>
    61. <p style="font-size: 15px;color: #666">
    62. 销量:{{product.saleCount}} 浏览量:{{product.viewCount}}p>
    63. <p style="font-size: 25px;font-weight: bold">¥{{product.price}}
    64. <span style="font-size: 15px;color: #666">原价:
    65. <s>{{product.oldPrice}}s>
    66. span>
    67. p>
    68. <el-row :gutter="20" style="text-align: center">
    69. <el-col :span="8">
    70. <el-card>
    71. <img src="imgs/ewm.jpg" width="100%" alt="">
    72. el-card>
    73. <p>扫码购买商品p>
    74. el-col>
    75. <el-col :span="8">
    76. <el-card>
    77. <img src="imgs/ewm.jpg" width="100%" alt="">
    78. el-card>
    79. <p>扫码关注公众号p>
    80. el-col>
    81. <el-col :span="8">
    82. <el-card>
    83. <img src="imgs/ewm.jpg" width="100%" alt="">
    84. el-card>
    85. <p>扫码下载Appp>
    86. el-col>
    87. el-row>
    88. el-col>
    89. el-row>
    90. el-main>
    91. <el-footer>
    92. <div style="height: 95px;background-image: url('imgs/wave.png');margin-bottom: -30px">div>
    93. <div style="height: 100px;background-color: #3f3f3f;
    94. padding: 30px;text-align: center;color: #b1b1b1">
    95. <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号p>
    96. <p>涵盖20余门课程体系,致力于打造权威的IT职业教育学习平台p>
    97. <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训p>
    98. div>
    99. el-footer>
    100. el-container>
    101. div>
    102. body>
    103. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    104. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    105. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    106. <script>
    107. let v = new Vue({
    108. el: '#app',
    109. data: function () {
    110. return {//在这里面定义变量
    111. title:"",
    112. categoryArr: [{id: 1, name: "精彩活动"}, {id: 2, name: "当季女装"},
    113. {id: 3, name: "品牌男装"}, {id: 4, name: "环球美食"}, {id: 5, name: "医药健康"},
    114. {id: 6, name: "美妆彩妆"}, {id: 7, name: "母婴产品"}
    115. ],
    116. product:{}
    117. }
    118. },
    119. created:function () {
    120. //蓝色导航菜单
    121. axios.get("/category/select").then(function (response) {
    122. v.categoryArr = response.data;
    123. })
    124. axios.get("/product/selectById"+location.search).then(function (response) {
    125. v.product=response.data;
    126. })
    127. },
    128. methods:{
    129. handleSelectLink(title){
    130. location.href = "/result.html?title="+title;
    131. }
    132. }
    133. })
    134. script>
    135. html>

    1.3.16index.html(商品首页)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. <style>
    7. header a {
    8. text-decoration: none;
    9. color: #6c6c6c;
    10. }
    11. .el-menu.el-menu--horizontal {
    12. border-bottom: none;
    13. }
    14. .el-table .el-table__cell{
    15. padding: 0;/*去掉排行榜表格中上下的内边距*/
    16. }
    17. .el-table .cell {
    18. white-space: nowrap;/*让内容在一行中显示,不换行*/
    19. text-overflow: ellipsis;/*如果文字溢出泽通过省略号展示*/
    20. }
    21. .p_img:hover{
    22. position: relative;
    23. bottom: 5px;
    24. /*元素的阴影:x便宜 y偏移 浓度 范围 颜色*/
    25. box-shadow: 0 0 10px 5px grey;
    26. }
    27. style>
    28. head>
    29. <body>
    30. <div id="app">
    31. <el-container>
    32. <el-header height="150">
    33. <div style="width: 1200px;margin: 0 auto">
    34. <img src="imgs/logo.png" style="width: 300px;vertical-align: middle" alt="">
    35. <span>
    36. <a href="">首页a><el-divider direction="vertical">el-divider>
    37. <a href="">热点咨询a><el-divider direction="vertical">el-divider>
    38. <a href="">商家入驻a><el-divider direction="vertical">el-divider>
    39. <a href="">社会招聘a><el-divider direction="vertical">el-divider>
    40. <a href="">校园招聘a><el-divider direction="vertical">el-divider>
    41. <a href="">帮助a>
    42. span>
    43. div>
    44. <div style="background-color: #82c8ec">
    45. <el-menu style="width: 1200px;margin: 0 auto"
    46. @select="handleSelect"
    47. :default-active="1"
    48. class="el-menu-demo"
    49. mode="horizontal"
    50. background-color="#82c8ec"
    51. text-color="#fff"
    52. active-text-color="#fff">
    53. <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}el-menu-item>
    54. <div style="float: right;margin-top: 10px">
    55. <el-input v-model="title" placeholder="请输入搜索内容">
    56. <el-button slot="append" icon="el-icon-search" @click="handleSelectLink(title)">el-button>
    57. el-input>
    58. div>
    59. el-menu>
    60. div>
    61. el-header>
    62. <el-main style="width: 1200px;margin: 0 auto">
    63. <el-row :gutter="20">
    64. <el-col :span="18">
    65. <el-carousel trigger="click" height="430px">
    66. <el-carousel-item v-for="item in bannerArr">
    67. <img :src="item.url" width="100%" alt="">
    68. el-carousel-item>
    69. el-carousel>
    70. el-col>
    71. <el-col :span="6">
    72. <el-card style="height: 430px">
    73. <h3>
    74. <i style="font-weight: bold" class="el-icon-trophy">销量最高i>
    75. h3>
    76. <el-divider>el-divider>
    77. <el-table :data="topArr" style="width: 100%">
    78. <el-table-column type="index" label="排名" width="50">
    79. el-table-column>
    80. <el-table-column prop="title" label="商品名" width="80">
    81. el-table-column>
    82. <el-table-column prop="saleCount" label="销量" width="80">
    83. el-table-column>
    84. el-table>
    85. el-card>
    86. el-col>
    87. el-row>
    88. <el-row :gutter="20">
    89. <el-col :span="6" v-for="p in productArr" style="margin-top: 20px">
    90. <el-card>
    91. <a :href="'/detail.html?id='+p.id">
    92. <img class="p_img" :src="p.url" width="100%" height="233" alt="">
    93. a>
    94. <div>
    95. <a style="text-decoration: none;color: #333;" :href="'/detail.html?id='+p.id">
    96. <p style="font-size: 15px;height: 40px;margin-top: 0">{{p.title}}p>
    97. a>
    98. <div style="color: #666">
    99. <span>¥{{p.price}}span>
    100. <s style="font-size: 12px">{{p.oldPrice}}s>
    101. <span style="float: right">销量:{{p.saleCount}}span>
    102. div>
    103. div>
    104. el-card>
    105. el-col>
    106. el-row>
    107. el-main>
    108. <el-footer>
    109. <div style="height: 95px;background-image: url('imgs/wave.png');margin-bottom: -30px">div>
    110. <div style="height: 100px;background-color: #3f3f3f;
    111. padding: 30px;text-align: center;color: #b1b1b1">
    112. <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号p>
    113. <p>涵盖20余门课程体系,致力于打造权威的IT职业教育学习平台p>
    114. <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训p>
    115. div>
    116. el-footer>
    117. el-container>
    118. div>
    119. body>
    120. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    121. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    122. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    123. <script>
    124. let v = new Vue({
    125. el: '#app',
    126. data: function () {
    127. return {//在这里面定义变量
    128. categoryArr: [],
    129. bannerArr:[],
    130. topArr:[{title:"小米手机",saleCount:988},
    131. {title:"李宁球鞋",saleCount:708},
    132. {title:"毛巾",saleCount:653},
    133. {title:"安踏拖鞋",saleCount:553},
    134. {title:"阿迪袜子",saleCount:438},
    135. {title:"耐克上衣",saleCount:88}],
    136. productArr:[{title:"森马牛仔裤女宽松慢跑裤运动风2022春季新款显瘦束脚长裤复古",price:233,oldPrice:598,url:"imgs/a.jpg",saleCount:2342},
    137. {title:"茵曼马甲连衣裙两件套春季新款娃娃领色织格长袖背心裙套装",price:233,oldPrice:598,url:"imgs/b.jpg",saleCount:2342},
    138. {title:"雪中飞墨绿色短袖t恤女夏2022新款纯棉半袖打底体恤夏季上衣潮ins",price:233,oldPrice:598,url:"imgs/c.jpg",saleCount:2342},
    139. {title:"【佟丽娅同款】鸭鸭明星同款羽绒服2021年冬季新款时尚连帽外套冬",price:233,oldPrice:598,url:"imgs/d.jpg",saleCount:2342},
    140. {title:"BEASTER小恶魔鬼脸明星同款夹克毛绒保暖加厚字母印花宽松外套ins",price:233,oldPrice:598,url:"imgs/e.jpg",saleCount:2342},
    141. {title:"香影毛呢外套女中长款2021年冬季新款气质韩版娃娃领紫色呢子大衣",price:233,oldPrice:598,url:"imgs/f.jpg",saleCount:2342},
    142. {title:"SEMIR森马商场同款打底针织毛衣纯色高领新品显瘦",price:233,oldPrice:598,url:"imgs/g.jpg",saleCount:2342},
    143. {title:"美特斯邦威女MTEE 贺岁系列中长款风衣736598",price:233,oldPrice:598,url:"imgs/h.jpg",saleCount:2342},
    144. {title:"imone2021秋款黑色小西装外套女韩版学生宽松学院风外套jk外套",price:233,oldPrice:598,url:"imgs/i.jpg",saleCount:2342},
    145. {title:"BEASTER 小恶魔明星同款保暖长袖街头潮流连帽卫衣情侣上衣",price:233,oldPrice:598,url:"imgs/j.jpg",saleCount:2342},
    146. {title:"憨厚皇后100%绵羊皮2021秋海宁真皮皮衣女长款修身绵羊皮风衣外",price:233,oldPrice:598,url:"imgs/k.jpg",saleCount:2342},
    147. {title:"美特斯邦威高腰牛仔裤女宽松小脚新款春秋彩色潮流女士牛仔",price:233,oldPrice:598,url:"imgs/a.jpg",saleCount:2342}],
    148. title:""
    149. }
    150. },
    151. created:function (){
    152. //蓝色导航菜单
    153. axios.get("/category/select").then(function (response) {
    154. v.categoryArr = response.data;
    155. })
    156. //轮播图
    157. axios.get("/banner/select").then(function (response){
    158. v.bannerArr = response.data;
    159. })
    160. //请求所以商品信息
    161. axios.get("/product/select/index").then(function (response) {
    162. v.productArr=response.data;
    163. })
    164. //请求排行榜信息
    165. axios.get("/product/select/top").then(function (response){
    166. v.topArr = response.data;
    167. })
    168. },
    169. methods:{
    170. handleSelect(index) {
    171. location.href = "/result.html?id="+index;
    172. },
    173. handleSelectLink(name){
    174. location.href = "/result.html?title="+name;
    175. }
    176. }
    177. })
    178. script>
    179. html>

    1.3.17insertBanner.html(添加轮播图页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. head>
    7. <body>
    8. <div id="app">
    9. <el-page-header style="background-color:#0095d7;color:white;line-height: 60px" @back="goBack" content="添加轮播图页面">
    10. el-page-header>
    11. <el-upload
    12. limit="1"
    13. action="/upload"
    14. name="picFile"
    15. list-type="picture-card"
    16. :on-preview="handlePictureCardPreview"
    17. :on-success="handleSuccess"
    18. :on-remove="handleRemove">
    19. <i class="el-icon-plus">i>
    20. el-upload>
    21. <el-dialog :visible.sync="dialogVisible">
    22. <img width="100%" :src="dialogImageUrl" alt="">
    23. el-dialog>
    24. <el-button @click="insert()">添加轮播图el-button>
    25. div>
    26. body>
    27. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    28. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    29. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    30. <script>
    31. let v = new Vue({
    32. el: '#app',
    33. data: function() {
    34. return {//在这里面定义变量
    35. dialogImageUrl: '',
    36. dialogVisible: false,
    37. url:""
    38. }
    39. },
    40. methods: {
    41. goBack(){
    42. //返回上一页面
    43. history.back()
    44. },
    45. handleRemove(file, fileList) {
    46. console.log(file, fileList);
    47. //file.response得到的是文件上传成功时服务器响应的内容(此内容就是图片的路径)
    48. let url = file.response;
    49. //发出删除图片的请求
    50. axios.get("/remove?url="+url).then(function () {
    51. alert("服务器中文件删除成功!");
    52. v.url="";
    53. })
    54. },
    55. handlePictureCardPreview(file) {
    56. this.dialogImageUrl = file.url;
    57. this.dialogVisible = true;
    58. },
    59. handleSuccess(response,file,fileList){
    60. //把服务器响应的图片路径 给到Vue的变量
    61. v.url = response;
    62. },
    63. insert(){
    64. if (v.url==""){
    65. alert("请选择上传的图片!");
    66. return;
    67. }
    68. //发出添加轮播图的请求
    69. axios.get("/banner/insert?url="+v.url).then(function () {
    70. //返回到后台管理页面
    71. location.href = "/admin.html";
    72. })
    73. }
    74. }
    75. })
    76. script>
    77. html>

    1.3.18insertProduct.html(添加商品页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. head>
    7. <body>
    8. <div id="app">
    9. <el-page-header style="background-color:#0095d7;color:white;line-height: 60px" @back="goBack" content="添加商品页面">
    10. el-page-header>
    11. <el-card style="width: 600px;height: 700px;margin: 0 auto;
    12. background-color: rgba(255,255,255,0.3)">
    13. <el-form style="width: 500px;margin: 50px auto" label-width="80px">
    14. <el-form-item label="商品标题">
    15. <el-input type="text" v-model="p.title" placeholder="请输入商品标题">el-input>
    16. el-form-item>
    17. <el-form-item label="商品价格">
    18. <el-input type="text" v-model="p.price" placeholder="请输入商品价格">el-input>
    19. el-form-item>
    20. <el-form-item label="商品原价">
    21. <el-input type="text" v-model="p.oldPrice" placeholder="请输入商品原价">el-input>
    22. el-form-item>
    23. <el-form-item label="销量">
    24. <el-input type="text" v-model="p.saleCount" placeholder="请输入销量">el-input>
    25. el-form-item>
    26. <el-form-item label="库存">
    27. <el-input type="text" v-model="p.num" placeholder="请输入库存">el-input>
    28. el-form-item>
    29. <el-form-item label="商品分类">
    30. <el-select placeholder="请选择" v-model="p.categoryId">
    31. <el-option v-for="c in arr" :label="c.name" :value="c.id">el-option>
    32. el-select>
    33. el-form-item>
    34. <el-form-item label="商品图片">
    35. <el-upload
    36. limit="1"
    37. action="/upload"
    38. name="picFile"
    39. list-type="picture-card"
    40. :on-preview="handlePictureCardPreview"
    41. :on-success="handleSuccess"
    42. :on-remove="handleRemove">
    43. <i class="el-icon-plus">i>
    44. el-upload>
    45. <el-dialog :visible.sync="dialogVisible">
    46. <img width="100%" :src="dialogImageUrl" alt="">
    47. el-dialog>
    48. el-form-item>
    49. <el-form-item >
    50. <el-button type="primary" @click="insert()">添加商品el-button>
    51. el-form-item>
    52. el-form>
    53. el-card>
    54. div>
    55. body>
    56. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    57. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    58. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    59. <script>
    60. let v = new Vue({
    61. el: '#app',
    62. data: function() {
    63. return {//在这里面定义变量
    64. dialogImageUrl: '',
    65. dialogVisible: false,
    66. p:{
    67. title:"",
    68. price:"",
    69. num:"",
    70. oldPrice:"",
    71. saleCount:"",
    72. url:"",
    73. categoryId:""
    74. },
    75. arr:[]
    76. }
    77. },
    78. created:function (){
    79. axios.get("/category/select").then(function (response) {
    80. v.arr=response.data;
    81. })
    82. },
    83. methods: {
    84. goBack(){
    85. //返回上一页面
    86. history.back()
    87. },
    88. handleRemove(file, fileList) {
    89. console.log(file, fileList);
    90. //file.response得到的是文件上传成功时服务器响应的内容(此内容就是图片的路径)
    91. let url = file.response;
    92. //发出删除图片的请求
    93. axios.get("/remove?url="+url).then(function () {
    94. alert("服务器中文件删除成功!");
    95. v.p.url="";
    96. })
    97. },
    98. handlePictureCardPreview(file) {
    99. this.dialogImageUrl = file.url;
    100. this.dialogVisible = true;
    101. },
    102. handleSuccess(response,file,fileList){
    103. //把服务器响应的图片路径 给到Vue的变量
    104. v.p.url = response;
    105. },
    106. insert(){
    107. if (v.url==""){
    108. alert("请选择上传的图片!");
    109. return;
    110. }
    111. //发出添加商品的请求
    112. axios.post("/product/insert",v.p).then(function () {
    113. //回到后台管理页面
    114. location.href="/admin.html";
    115. })
    116. }
    117. }
    118. })
    119. script>
    120. html>

    1.3.19login.html(登录页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. <style>
    7. body{
    8. margin: 0;/*去掉自带的8个像素外边距*/
    9. background-image: url("imgs/bg.jpg");
    10. /*cover封面 */
    11. background-size: cover;
    12. text-align: center;
    13. }
    14. h1{
    15. font-size: 72px;
    16. color: rgb(0,150,220);
    17. margin-bottom: 0;
    18. }
    19. img{width: 100px}
    20. h2{
    21. font-size: 32px;
    22. color: rgb(0,150,220);
    23. margin: 0;
    24. }
    25. style>
    26. head>
    27. <body>
    28. <div id="app">
    29. <h1>欢迎来到酷鲨商城h1>
    30. <img src="imgs/shark.png" alt="">
    31. <h2>CoolSharkMallh2>
    32. <el-card style="width: 600px;height: 300px;margin: 0 auto;
    33. background-color: rgba(255,255,255,0.3)">
    34. <el-form style="width: 400px;margin: 50px auto" label-width="60px">
    35. <el-form-item label="用户名">
    36. <el-input type="text" v-model="user.username" placeholder="请输入用户名">el-input>
    37. el-form-item>
    38. <el-form-item label="密码">
    39. <el-input type="password" v-model="user.password" placeholder="请输入密码">el-input>
    40. el-form-item>
    41. <el-form-item >
    42. <el-button style="position: relative;right: 30px" type="primary" @click="login()">登录el-button>
    43. el-form-item>
    44. el-form>
    45. el-card>
    46. div>
    47. body>
    48. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    49. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    50. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    51. <script>
    52. let v = new Vue({
    53. el: '#app',
    54. data: function() {
    55. return {//在这里面定义变量
    56. user:{
    57. username:"",
    58. password:""
    59. }
    60. }
    61. },
    62. methods:{
    63. login(){
    64. axios.post("/login",v.user).then(function (response) {
    65. if (response.data==1){
    66. /*alert("登录成功");*/
    67. location.href="/";
    68. }else if(response.data == 2){
    69. v.$message.error("密码错误")
    70. }else{
    71. v.$message.error("该用户不存在")
    72. }
    73. })
    74. }
    75. }
    76. })
    77. script>
    78. html>

    1.3.20result.html(查询分类结果页面)

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    6. <style>
    7. header a {
    8. text-decoration: none;
    9. color: #6c6c6c;
    10. }
    11. .el-menu.el-menu--horizontal {
    12. border-bottom: none;
    13. }
    14. .el-table .el-table__cell{
    15. padding: 0;/*去掉排行榜表格中上下的内边距*/
    16. }
    17. .el-table .cell {
    18. white-space: nowrap;/*让内容在一行中显示,不换行*/
    19. text-overflow: ellipsis;/*如果文字溢出泽通过省略号展示*/
    20. }
    21. .p_img:hover{
    22. position: relative;
    23. bottom: 5px;
    24. /*元素的阴影:x便宜 y偏移 浓度 范围 颜色*/
    25. box-shadow: 0 0 10px 5px grey;
    26. }
    27. style>
    28. head>
    29. <body>
    30. <div id="app">
    31. <el-container>
    32. <el-header height="150">
    33. <div style="width: 1200px;margin: 0 auto">
    34. <img src="imgs/logo.png" style="width: 300px;vertical-align: middle" alt="">
    35. <span>
    36. <a href="/">首页a><el-divider direction="vertical">el-divider>
    37. <a href="">热点咨询a><el-divider direction="vertical">el-divider>
    38. <a href="">商家入驻a><el-divider direction="vertical">el-divider>
    39. <a href="">社会招聘a><el-divider direction="vertical">el-divider>
    40. <a href="">校园招聘a><el-divider direction="vertical">el-divider>
    41. <a href="">帮助a>
    42. span>
    43. div>
    44. <div style="background-color: #82c8ec">
    45. <el-menu style="width: 1200px;margin: 0 auto"
    46. @select="handleSelect"
    47. :default-active="currentIndex"
    48. class="el-menu-demo"
    49. mode="horizontal"
    50. background-color="#82c8ec"
    51. text-color="#fff"
    52. active-text-color="#fff">
    53. <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}el-menu-item>
    54. <div style="float: right;margin-top: 10px">
    55. <el-input v-model="title" placeholder="请输入搜索内容">
    56. <el-button slot="append" icon="el-icon-search" @click="handleSelectLink(title)">el-button>
    57. el-input>
    58. div>
    59. el-menu>
    60. div>
    61. el-header>
    62. <el-main style="width: 1200px;margin: 0 auto">
    63. <el-row :gutter="20">
    64. <el-col :span="6" v-for="p in productArr" style="margin-top: 20px">
    65. <el-card>
    66. <a :href="'/detail.html?id='+p.id">
    67. <img class="p_img" :src="p.url" width="100%" height="233" alt="">
    68. a>
    69. <div>
    70. <a style="text-decoration: none;color: #333;" :href="'/detail.html?id='+p.id">
    71. <p style="font-size: 15px;height: 40px;margin-top: 0">{{p.title}}p>
    72. a>
    73. <div style="color: #666">
    74. <span>¥{{p.price}}span>
    75. <s style="font-size: 12px">{{p.oldPrice}}s>
    76. <span style="float: right">销量:{{p.saleCount}}span>
    77. div>
    78. div>
    79. el-card>
    80. el-col>
    81. el-row>
    82. el-main>
    83. <el-footer>
    84. <div style="height: 95px;background-image: url('imgs/wave.png');margin-bottom: -30px">div>
    85. <div style="height: 100px;background-color: #3f3f3f;
    86. padding: 30px;text-align: center;color: #b1b1b1">
    87. <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号p>
    88. <p>涵盖20余门课程体系,致力于打造权威的IT职业教育学习平台p>
    89. <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训p>
    90. div>
    91. el-footer>
    92. el-container>
    93. div>
    94. body>
    95. <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js">script>
    96. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
    97. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    98. <script>
    99. let v = new Vue({
    100. el: '#app',
    101. data: function () {
    102. return {//在这里面定义变量
    103. categoryArr: [],
    104. productArr:[],
    105. title:"",
    106. currentIndex:""
    107. }
    108. },
    109. created:function (){
    110. //亲求所有分类
    111. axios.get("/category/select").then(function (response) {
    112. v.categoryArr = response.data;
    113. })
    114. let uri = location.search.split("=")[0];
    115. if (location.search.indexOf("id")!=-1){
    116. axios.get("/product/selectByCid"+location.search).then(function (response) {
    117. v.productArr = response.data;
    118. })
    119. //在created方法中需要访问data里面的变量时需要使用this.变量名的方式
    120. //因为此时Vue对象还未创建完成还没有把实例化的对象赋值给v变量,
    121. //所以不能直接方位v
    122. //把地址栏中的分类id取出
    123. this.currentIndex = location.search.split("=")[1];
    124. }else if (location.search.indexOf("title")!=-1){
    125. axios.get("/product/selectByName"+location.search).then(function (response) {
    126. v.productArr = response.data;
    127. })
    128. }
    129. },
    130. methods:{
    131. handleSelect(index) {
    132. axios.get("/product/selectByCid?id="+index).then(function (response) {
    133. v.productArr = response.data;
    134. })
    135. },
    136. handleSelectLink(title){
    137. axios.get("/product/selectByName"+location.search).then(function (response) {
    138. v.productArr = response.data;
    139. })
    140. }
    141. }
    142. })
    143. script>
    144. html>

    1.3.21application.properties(配置文件)

    1. spring.datasource.url=jdbc:mysql://localhost:3306/cs?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
    2. spring.datasource.username=root
    3. spring.datasource.password=root
    4. #修改上传文件大小限制
    5. spring.servlet.multipart.max-file-size=10MB
    6. #配置静态资源文件夹
    7. spring.web.resources.static-locations=file:E:/files,classpath:static
    8. #自动处理表字段名_命名规范和Java实体类中驼峰命名时的映射关系
    9. mybatis.configuration.map-underscore-to-camel-case=true

  • 相关阅读:
    FPGA——SPI总线控制flash(2)(含代码)
    Java加密与解密
    框架安全-CVE 复现&Spring&Struts&Laravel&ThinkPHP漏洞复现
    jwt的了解和使用以及大致代码分析
    一文带你搞懂 JWT 常见概念 & 优缺点
    方法递归详解
    喜报|云畅科技获批加入全国信标委软件与系统工程分委会
    为什么网站页面没有被百度搜索收录?是网站被攻击了?
    MySQL数据库性能分析之explain使用
    通过git服务提高端侧开发调试效率
  • 原文地址:https://blog.csdn.net/TheNewSystrm/article/details/125898841