伙伴云客服论坛»论坛 S区 S客户管理 查看内容

0 评论

0 收藏

分享

电商订单后台管理系统

文章目录

    前言一、项目构造
      1.文件构造2.部分显示效果图
    二、项目配置文件
      pom.xmlresouerces
        mapper文件
          AdminMapper.xmlMyFileMapper.xmlUsersMapper.xmlOrdersMapper.xml(订单表映射)RoleMapper.xml

      application.xml(整合所有容器)db.properties(mysql配置)logj.properties(日志容器)mybits-config.xml(存储过程及映射)spring-dao.xmlspring-mvc.xmlspring-service.xmlspring-shiro.xml
    三、后端功能实现
      1.实体层(entity)2.耐久层(mapper)又称dao层3.业务层(service)
        service(定义接口)Impl(实现接口)
      4.控制层(controller)5.工具层(utils)6.登录实现层(realm)
    四、前端功能实现
      1.static(前端静态资源显示)2.upOAd(文件上传目录)3.jsp(显示页面格式为:xxx.jsp)
    总结


前言

开发工具:IntelliJ IDEA 2019.3.1
本文用到的技术:layui+ajax+SSM(Spring+SpringMVC+MyBatis)+mysql+tomcat
编写语言为:Java
由于本位篇幅过长,我这里提供两种下载地址。
码云仓库(gitee):https://gitee.com/fishme9/logistics_system.git
百度网盘:https://pan.baidu.com/s/1fgMG89ZpohAVRgk1fHeOPQ?pwd=58e2
提取码:58e2
MySQL文件:
百度网盘:https://pan.baidu.com/s/1SIOKTboJe4MWV6z15mFL0A?pwd=0ymg
提取码:0ymg
提示:以下是本篇文章正文内容,下面案例可供参考

一、项目构造

1.文件构造

电商订单后台管理系统-1.jpg

这里有些文件没有显示,详细的目录下面有哪些文件显示,会在下面的详细实现中,展示出来。
2.部分显示效果图

用户列表

电商订单后台管理系统-2.jpg

订单管理

电商订单后台管理系统-3.jpg


管理员列表

电商订单后台管理系统-4.jpg

文件上传下载

电商订单后台管理系统-5.jpg

登录个人信息及密码修改

电商订单后台管理系统-6.jpg


二、项目配置文件

电商订单后台管理系统-7.jpg


pom.xml

maven依赖包
  1. <?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.hqyj.psl</groupId><artifactId>ssmjavaweb</artifactId><version>1.0-SNAPSHOT</version><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build><packaging>war</packaging><dependencies><!--dao依赖--><!--mybatis相关--><!--1. mybatis--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.9</version></dependency><!--2.mybatis整合spring--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.7</version></dependency><!--3.mysql--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!--4.lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency><!--5.log4j--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><!--6.junit--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency><!--7.spring相关--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.19</version></dependency><!--spring-test--><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.3.19</version></dependency><!--spring-jdbc--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.19</version></dependency><!--spring-tx--><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.3.19</version></dependency><!--service层--><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.7</version></dependency><!--Druid--><!-- https://mvnrepository.com/artifact/com.alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.22</version></dependency><!--c3p0连接池--><dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.2</version></dependency><!--添加servlet的支持--><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version></dependency><!--json--><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.13.2</version></dependency><!--pagehelper 分页插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.3.1</version></dependency><!-- pagehelper的依赖包:jsqlparser --><dependency><groupId>com.github.jsqlparser</groupId><artifactId>jsqlparser</artifactId><version>4.5</version></dependency><!--文档上传下载依赖包--><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.9</version></dependency><!--shiro依赖相关--><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-all</artifactId><version>1.2.2</version></dependency><!--spring整合shiro的包--><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-spring</artifactId><version>1.2.2</version></dependency></dependencies></project>
复制代码
resouerces

mapper文件

电商订单后台管理系统-8.jpg


AdminMapper.xml
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.hqyj.psl.mapper.AdminMapper"><resultMapid="adminMap"type="Admin"><idproperty="adminId"column="id"/><resultproperty="sex"column="sex"/><resultproperty="name"column="name"/><resultproperty="phone"column="phone"/><resultproperty="email"column="email"/><resultproperty="remark"column="remark"/><resultproperty="username"column="username"/><resultproperty="password"column="password"/></resultMap><selectid="selectByName"resultMap="adminMap">
  2.         select * from admin where name=#{username}
  3.     </select><!--通过名字查询角色--><selectid="selectRolesByUsername"resultType="java.lang.String">
  4.         SELECT r.name FROM admin_role ar
  5.         left join admin a on a.admin_id=ar.admin_id
  6.         left join role r on r.role_id=ar.role_id
  7.         where a.name = #{name};
  8.     </select><!--通过名字查询权限--><selectid="selectPermsByUsername"resultType="java.lang.String">
  9.         select p.url from role_permission rp
  10.         left join role r  on r.role_id=rp.role_id
  11.         left join permission p on p.permission_id=rp.permission_id
  12.         where rp.role_id in
  13.         (SELECT r.role_id FROM admin_role ar
  14.         left join admin a on a.admin_id=ar.admin_id
  15.         left join role r on r.role_id=ar.role_id
  16.         where a.name = #{name})
  17.     </select><!--注册--><insertid="insertBySignup">
  18.         insert into admin (admin_id,name,username,password) values (null,#{arg0},"simple",#{arg1})
  19.     </insert><!--个人信息更新--><updateid="update">
  20.         update admin set phone=#{phone},email=#{email},password=#{password},remark=#{remark} where name=#{name}
  21.     </update><!--个人资料查询--><selectid="show"resultMap="adminMap">
  22.         select * from admin where name=#{username} and password=#{password}
  23.     </select></mapper>
复制代码
MyFileMapper.xml
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.hqyj.psl.mapper.MyFileMapper"><resultMapid="myFileMap"type="MyFile"><idproperty="fileId"column="file_id"/><resultproperty="fileName"column="file_name"/><resultproperty="fileUrl"column="file_url"/></resultMap><!--sql片段--><sqlid="myFileCol">
  2.         file_id,file_name,file_url
  3.     </sql><!--查询文件--><selectid="selectAll"resultMap="myFileMap">
  4.         select * from my_file
  5.     </select><!--添加文件内容到数据库--><insertid="insert"parameterType="MyFile">
  6.         insert into my_file values (null,#{fileName},#{fileUrl})
  7.     </insert><!--移除文件--><deleteid="deleteFile">
  8.         delete from my_file where file_id=#{fileId}
  9.     </delete></mapper>
复制代码
UsersMapper.xml
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.hqyj.psl.mapper.UsersMapper"><!--1.结果映射--><resultMapid="usersMap"type="Users"><idproperty="usersId"column="users_id"/><resultproperty="name"column="name"/><resultproperty="sex"column="sex"/><resultproperty="address"column="address"/><resultproperty="phone"column="phone"/><resultproperty="email"column="email"/><resultproperty="username"column="username"/><resultproperty="password"column="password"/><resultproperty="isVip"column="is_vip"/><resultproperty="deleted"column="deleted"/><resultproperty="joinDate"column="join_time"/></resultMap><!--2.数据库字段片段--><sqlid="UsersCol">
  2.         users_id,name,sex,address,phone,email,username,password,is_vip,deleted,join_time
  3.     </sql><!--分页查所有用户--><selectid="selectAll"resultMap="usersMap">
  4.         select <includerefid="UsersCol"/> from users where  deleted = 0
  5.     </select><!--根据名称查询user--><selectid="selectOneByUsername"resultMap="usersMap">
  6.         select <includerefid="UsersCol"/> from user
  7.         where username=#{username}
  8.     </select><updateid="update">
  9.         update users
  10.         set name=#{name},sex=#{sex},address=#{address},
  11.         phone=#{phone},email=#{email},username=#{username},
  12.         password=#{password},deleted=#{deleted},join_time=#{joinDate}
  13.         where users_id=#{usersId}
  14.     </update><!--逻辑删除--><updateid="deleteUpdByUserId">
  15.         update users set deleted = 1 where users_id=#{usersId}
  16.     </update><deleteid="deleteByUserId">
  17.         delete from user where user_id=#{id}
  18.     </delete><insertid="insert">
  19.         insert into users values (null,#{name},#{sex},#{address},
  20.         #{phone},#{email},#{username},#{password},#{isVip},#{deleted},#{joinDate})
  21.     </insert><selectid="search"resultMap="usersMap">
  22.         select * from users
  23.         <where>
  24.             deleted = 0
  25.             <iftest="username!=null and username!=''">
  26.                 and username like CONCAT(CONCAT('%',#{username},'%'))
  27.             </if><iftest="phone!=null and phone!=''">
  28.                 and phone like CONCAT(CONCAT('%',#{phone},'%'))
  29.             </if></where></select><!--逻辑删除全部--><updateid="deleteAll"parameterType="list">
  30.         update users set deleted=1
  31.         <where><foreachcollection="list"item="item"index="index"open="users_id in ("close=")"separator=",">
  32.                 #{item}
  33.             </foreach></where></update><!--查找被逻辑删除的--><selectid="selectByDeletedUsers"resultMap="usersMap">
  34.         select <includerefid="UsersCol"/> from users where deleted = 1
  35.     </select><!--恢复删除--><updateid="renew">
  36.         update users set deleted = 0 where users_id = #{usersId}
  37.     </update><!--全部恢复--><updateid="updateRenbit"parameterType="list">
  38.         update users set deleted = 0
  39.         <where><foreachcollection="list"item="item"index="index"open="users_id in ("close=")"separator=",">
  40.                 #{item}
  41.             </foreach></where></update><!--删除--><deleteid="phyDel">
  42.         delete from users where users_id = #{usersId}
  43.     </delete><!--条件查找--><selectid="condQuery"resultMap="usersMap">
  44.         select <includerefid="UsersCol"/> from users
  45.         <where>
  46.             deleted = 1
  47.             <iftest="username != '%%'">
  48.                 and name like #{username}
  49.             </if></where></select></mapper>
复制代码
OrdersMapper.xml(订单表映射)
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.hqyj.psl.mapper.OrdersMapper"><!--1.结果映射--><resultMapid="ordersMap"type="Orders"><idproperty="ordersId"column="orders_id"/><resultproperty="ordersNo"column="orders_no"/><resultproperty="ordersName"column="orders_name"/><resultproperty="phone"column="phone"/><resultproperty="totalAmount"column="total_amount"/><resultproperty="payAmount"column="pay_amount"/><resultproperty="ordersState"column="orders_state"/><resultproperty="payState"column="pay_state"/><resultproperty="shipmentsState"column="shipments_state"/><resultproperty="giveMethod"column="give_method"/><resultproperty="ordersTime"column="orders_time"/></resultMap><!--2.sql片段--><sqlid="ordersCol">
  2.         Orders,orders_id,orders_no,orders_name,phone,total_amount,pay_amount,orders_state,pay_state,shipments_state,give_method,orders_time
  3.     </sql><selectid="selectAll"resultMap="ordersMap">
  4.         select * from orders
  5.     </select><deleteid="delete">
  6.         delete from orders where orders_id = #{ordersId}
  7.     </delete><updateid="update">
  8.         update orders set orders_name = #{ordersName},shipments_state = #{shipmentsState},give_method = #{giveMethod} where orders_id = #{ordersId}
  9.     </update><updateid="insert">
  10.         insert into orders values (null,#{ordersNo},#{ordersName},#{phone},#{totalAmount},#{payAmount},#{ordersState},#{payState},#{shipmentsState},#{giveMethod},#{ordersTime})
  11.     </update><!--模糊查询--><selectid="selectLike"resultMap="ordersMap">
  12.         select * from orders
  13.         <where><iftest="payState!=''">
  14.                 and pay_state = #{payState}
  15.             </if><iftest="ordersState!=''">
  16.                 and orders_state = #{ordersState}
  17.             </if><iftest="ordersNo!='%%'">
  18.                 and orders_no like #{ordersNo}
  19.             </if><iftest="isVip!=null">
  20.                 and orders_id IN(
  21.                 SELECT orders_id
  22.                 FROM orders_users
  23.                 WHERE users_id IN (
  24.                 SELECT users_id
  25.                 FROM users
  26.                 WHERE is_vip = #{isVip}
  27.                 ))
  28.             </if></where></select><deleteid="deleteAll"parameterType="List">
  29.         delete from orders
  30.         <where><foreachcollection="list"index="index"item="item"open="orders_id in ("close=")"separator=",">
  31.                 #{item}
  32.             </foreach></where></delete></mapper>
复制代码
RoleMapper.xml
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.hqyj.psl.mapper.RoleMapper"><!--结果集--><resultMapid="adminVoMapper"type="AdminVo"><!--Role里面的字段--><idproperty="adminId"column="admin_id"/><resultproperty="username"column="username"/><resultproperty="rname"column="rname"/><resultproperty="url"column="url"/><!--Roles集合--><collectionproperty="roles"ofType="Role"><idproperty="roleId"column="role_id"/><resultproperty="name"column="rname"/><resultproperty="state"column="state"/></collection><!--Permission集合--><!--        <collection property="permissions" ofType="Permission">--><!--            <id property="permissionId" column="permission_id"/>--><!--            <result property="url" column="url"/>--><!--            <result property="state" column="pstate"/>--><!--        </collection>--></resultMap><!-- 根据用户名查询所有拥有的角色--><selectid="selectRolesByUsername"resultType="java.lang.String">
  2.         SELECT ad.*,r.`role_id`,r.`name` as rname,r.`state` FROM admin_role ar
  3.         LEFT JOIN admin ad ON ad.`admin_id`=ar.`admin_id`
  4.         LEFT JOIN role r ON r.`role_id`=ar.`role_id`
  5.         WHERE ad.`username`=#{username}
  6.     </select><!-- 查询所有角色--><selectid="selectRoleAll"resultMap="adminVoMapper">
  7.             SELECT role_id,NAME rname FROM role;
  8.         </select><!--    <select id="selectRoleAll" resultMap="adminVoMapper">--><!--        SELECT ad.*, r.`name` rname,r.role_id,r.state FROM admin_role ar--><!--        LEFT JOIN admin ad ON ad.`admin_id`=ar.`admin_id`--><!--        LEFT JOIN role r ON r.`role_id`=ar.`role_id`--><!--        GROUP BY ad.`admin_id`;--><!--    </select>--><!--查询所有角色的admin_id--><!--  根据角色查询所有拥有权限--><selectid="selectPermsByRole"resultType="java.lang.String">
  9.         SELECT p.`url` FROM role_permission rp
  10.     LEFT JOIN role r ON rp.`role_id`=r.`role_id`
  11.     LEFT JOIN permission p ON rp.`permission_id`=p.`permission_id`
  12.     WHERE r.`role_id`=#{roleId};
  13.     </select><!--根据用户名查询所有拥有的权限--><selectid="selectPermsByUsername"resultMap="adminVoMapper">
  14.          SELECT DISTINCT p.url FROM role_permission rp
  15.         LEFT JOIN role r  ON r.role_id=rp.role_id
  16.         LEFT JOIN permission p ON p.permission_id=rp.permission_id
  17.         WHERE rp.role_id IN
  18.         (SELECT r.role_id FROM admin_role ad
  19.         LEFT JOIN admin a ON a.admin_id=ad.admin_id
  20.         LEFT JOIN role r ON r.role_id=ad.role_id
  21.         WHERE username = #{username})
  22.     </select><!--修改角色名--><selectid="updateRoleName"resultType="java.lang.Integer">
  23.         UPDATE role SET NAME=#{name} WHERE role_id=#{roleId}
  24.     </select><!--修改权限--><!--删除权限关联表中的关联--><deleteid="deleteRole_P">
  25.             DELETE        FROM role_permission WHERE role_id=#{roleId}
  26.         </delete><!--根据权限名url查询权限id--><selectid="selectPreId"resultType="java.lang.Integer">
  27.             SELECT permission_id FROM permission WHERE url=#{url};
  28.         </select><!--添加权限关联表中的关联添加 preid roleId--><insertid="addRole_P">
  29.             INSERT INTO role_permission VALUES(null,#{arg0},#{arg1});
  30.         </insert><!--删除角色--><deleteid="deleteRole">
  31.         DELETE FROM role WHERE role_id=#{roleId}
  32.     </delete><!--添加角色--><!--1.在Role表中添加角色名--><insertid="addRoleName">
  33.             INSERT INTO role VALUES(NULL,#{name},1);
  34.         </insert><!--2.查询Role表中的roleId 通过角色名--><selectid="selectRoleByName"resultType="java.lang.Integer">
  35.             SELECT role_id FROM role WHERE NAME=#{name};
  36.         </select></mapper>
复制代码
application.xml(整合所有容器)
  1. <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans
  2.        http://www.springframework.org/schema/beans/spring-beans.xsd
  3.         http://www.springframework.org/schema/context
  4.        http://www.springframework.org/schema/context/spring-context.xsd
  5.         http://www.springframework.org/schema/aop
  6.        http://www.springframework.org/schema/aop/spring-aop.xsd"><!--整合容器--><importresource="classpath:spring-dao.xml"/><importresource="classpath:spring-service.xml"/><importresource="classpath:spring-mvc.xml"/><importresource="classpath:spring-shiro.xml"/></beans>
复制代码
db.properties(mysql配置)
  1. driver=com.mysql.jdbc.Driver
  2. url=jdbc:mysql:///ssmweb
  3. user=root
  4. password=root
  5. #c3p0.minPoolSize = 10
  6. #c3p0.maxPoolSize = 20
  7. #c3p0.initialPoolSize = 100
  8. #c3p0.maxIdleTime = 30
  9. #c3p0.acquireIncrement = 5
复制代码
logj.properties(日志容器)
  1. #假设要输出到文件,下面一行后面增加一个,File
  2. log4j.rootLogger=DEBUG, Console
  3. #配置输出log到文件
  4. #文件大小到达指定尺寸的时候产生一个新的文件
  5. log4j.appender.File = org.apache.log4j.RollingFileAppender
  6. #指定输出目录
  7. log4j.appender.File.File = logs/ssm.log
  8. #定义文件最大大小
  9. log4j.appender.File.MaxFileSize = 10MB
  10. # 输出所以日志,假设换成DEBUG表示输出DEBUG以上级别日志
  11. log4j.appender.File.Threshold = ALL
  12. log4j.appender.File.layout = org.apache.log4j.PatternLayout
  13. log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
  14. #配置输出到Console
  15. log4j.appender.Console=org.apache.log4j.ConsoleAppender
  16. log4j.appender.Console.layout=org.apache.log4j.PatternLayout
  17. log4j.appender.Console.layout.ConversionPattern=[%p][%c] - %m%n
  18. # spring框架和apache的包输出日志级别为INFO
  19. log4j.logger.org.springframework=INFO
  20. log4j.logger.org.apache=INFO
复制代码
mybits-config.xml(存储过程及映射)
  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEconfigurationPUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><!--设置日志及缓存--><settings><settingname="logImpl"value="LOG4J"/></settings><!--配置别名--><typeAliases><typeAliastype="com.hqyj.psl.entity.Users"alias="Users"/><typeAliastype="com.hqyj.psl.entity.MyFile"alias="MyFile"/><typeAliastype="com.hqyj.psl.entity.Admin"alias="Admin"/><typeAliastype="com.hqyj.psl.entity.Orders"alias="Orders"/><typeAliastype="com.hqyj.psl.entity.Role"alias="Role"/><typeAliastype="com.hqyj.psl.entity.AdminVo"alias="AdminVo"/><typeAliastype="com.hqyj.psl.entity.Permission"alias="Permission"/></typeAliases></configuration>
复制代码
spring-dao.xml
  1. <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans
  2.        http://www.springframework.org/schema/beans/spring-beans.xsd
  3.         http://www.springframework.org/schema/context
  4.        http://www.springframework.org/schema/context/spring-context.xsd
  5.         http://www.springframework.org/schema/aop
  6.        http://www.springframework.org/schema/aop/spring-aop.xsd"><!--0.扫描包--><context:component-scanbase-package="com.hqyj.psl.mapper"/><!--1.引入db.properties--><context:property-placeholderlocation="classpath:db.properties"/><!--2.dataSource--><!--        druid连接--><beanid="dataSource"class="com.alibaba.druid.pool.DruidDataSource"destroy-method="close"lazy-init="false"><propertyname="driverClassName"value="${driver}"/><propertyname="url"value="${url}"/><propertyname="username"value="${user}"/><propertyname="password"value="${password}"/><propertyname="initialSize"value="3"/><propertyname="maxActive"value="5"/><propertyname="maxWait"value="3000"/></bean><!--3.sqlSessionFactory--><beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="configLocation"value="classpath:mybatis-config.xml"/><propertyname="mapperLocations"value="classpath:mapper/*.xml"/><propertyname="plugins"><array><beanclass="com.github.pagehelper.PageInterceptor"><propertyname="properties"><!--使用下面的方式配置参数,一行配置一个 --><value>
  7.                                 helperDialect=mysql
  8.                             </value></property></bean></array></property></bean><!--4.动态生成Dao接口实现类--><beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"><!--注入sqlSessionFactory 注意其类型为String 只需要注入bean的名称就可以--><propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory"/><!--给出扫描的包,告诉他为谁生成--><propertyname="basePackage"value="com.hqyj.psl.mapper"/></bean></beans>
复制代码
spring-mvc.xml
  1. <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans
  2.        http://www.springframework.org/schema/beans/spring-beans.xsd
  3.        http://www.springframework.org/schema/context
  4.        http://www.springframework.org/schema/context/spring-context.xsd
  5.        http://www.springframework.org/schema/aop
  6.        http://www.springframework.org/schema/aop/spring-aop.xsd
  7.        http://www.springframework.org/schema/mvc
  8.        http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--开启包扫描--><context:component-scanbase-package="com.hqyj.psl.controller"/><!--2.配置注解驱动--><mvc:annotation-driven><!--json乱码问题--><mvc:message-convertersregister-defaults="true"><beanclass="org.springframework.http.converter.StringHttpMessageConverter"><constructor-argvalue="UTF-8"/></bean><beanclass="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><propertyname="objectMapper"><beanclass="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"><propertyname="failOnEmptyBeans"value="false"/></bean></property></bean></mvc:message-converters></mvc:annotation-driven><!--3配置静态资源--><mvc:resourcesmapping="/static/**"location="/static/"/><mvc:resourcesmapping="/upload/**"location="/upload/"/><!--4.静态资源的servlet配置 --><mvc:default-servlet-handler/><!--5.配置视图解析器--><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><propertyname="prefix"value="/WEB-INF/jsp/"/><propertyname="suffix"value=".jsp"/></bean><!--6.配置文档上传下载配置 ,假设没有使用文件可以不用配置,同时也不用引入pomjar--><beanid="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!--编码--><propertyname="defaultEncoding"value="utf-8"/><propertyname="maxUploadSize"value="10480000000"/><propertyname="maxInMemorySize"value="40960"/></bean></beans>
复制代码
spring-service.xml
  1. <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans
  2.        http://www.springframework.org/schema/beans/spring-beans.xsd
  3.         http://www.springframework.org/schema/context
  4.        http://www.springframework.org/schema/context/spring-context.xsd
  5.         http://www.springframework.org/schema/aop
  6.        http://www.springframework.org/schema/aop/spring-aop.xsd
  7.        http://www.springframework.org/schema/tx
  8.        http://www.springframework.org/schema/tx/spring-tx.xsd"><!--1.配置扫描包--><context:component-scanbase-package="com.hqyj.psl.service"/><!--    <!–2.配置事务对象–>--><!--    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">--><!--        <property name="dataSource" ref="dataSource"/>--><!--     </bean>--><!--3.开启事务注解支持--><!--    <tx:annotation-driven transaction-manager="transactionManager"/>--><!--4.事务的第二种方式 --><!--    <tx:advice id="accountTransaction" transaction-manager="transactionManager">--><!--        <tx:attributes>--><!--            <tx:method name="changeMoney" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>--><!--            <tx:method name="change*"/>--><!--            <!–可以写多个方法--><!--                1.直接写方法名--><!--                2.通配符:select *--><!--            –>--><!--        </tx:attributes>--><!--    </tx:advice>--><!--    --></beans>
复制代码
spring-shiro.xml
  1. <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans
  2.        http://www.springframework.org/schema/beans/spring-beans.xsd
  3.         http://www.springframework.org/schema/context
  4.        http://www.springframework.org/schema/context/spring-context.xsd
  5.         http://www.springframework.org/schema/aop
  6.        http://www.springframework.org/schema/aop/spring-aop.xsd"><!--0.密码匹配器--><beanid="passwordMatcher"class="org.apache.shiro.authc.credential.HashedCredentialsMatcher"><!--设置加密方式--><propertyname="hashAlgorithmName"value="MD5"/><!--加密次数--><propertyname="hashIterations"value="1024"/></bean><!--1.配置停止受权和认证的Realm--><beanid="myRealm"class="com.hqyj.psl.realm.UserRealm"><!--注入密码适配器--><!--        <property name="credentialsMatcher" ref="passwordMatcher"/>--></bean><!--2.配置SecurityManage--><beanid="securityManage"class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"><!--设置Realm--><propertyname="realm"ref="myRealm"/></bean><!--3.配置shiroFilter,必需和web.xml中的file-name一致,拦截恳求资源--><beanid="shiroFilter"class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"><propertyname="securityManager"ref="securityManage"/><!--假设非法访问时,设置默认跳转的资源的url  跳转回登录页面--><propertyname="loginUrl"value="/login"/><!--无权访问跳转页面--><propertyname="unauthorizedUrl"value="/noPower"/><!--配置拦截--><propertyname="filterChainDefinitions"><value><!--
  7.                     身份:
  8.                         anno 匿名访问
  9.                         authc 认证后才干访问
  10.                         roles[角色名] 注意!!!:roles[角色1,角色2],表示满足两个角色的用户才干访问
  11.                         perms[权限名] 拥有某个权限的用户
  12.                 -->
  13.                 /login=anon
  14.                 /index=authc
  15.                 /admin-role=roles[admin]
  16. <!--                /users/userList=roles[simple,admin]-->
  17.                 /users/delete=perms[delete]<!--zhangsan不能访问-->
  18.                 /users/deleteAll=perms[delete]<!--zhangsan不能访问-->
  19.                 /users/renew=perms[update]
  20.                 /users/phyDel=perms[delete]
  21.                 /users/renewAll=perms[update]
  22.                 /orders/deleteAll=perms[delete]
  23.                 /orders/delete=perms[delete]
  24.                 /myFileAjax/deleteFile=perms[delete]
  25.             </value></property></bean></beans>
复制代码
三、后端功能实现

1.实体层(entity)

Admin.java
  1. packagecom.hqyj.psl.entity;importlombok.AllArgsConstructor;importlombok.Data;importlombok.NoArgsConstructor;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/18
  5. * \* Time: 22:20
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@Data@AllArgsConstructor@NoArgsConstructorpublicclassAdmin{privateInteger adminId;privateString sex;privateString name;privateString phone;privateString email;privateString remark;privateString username;privateString password;}
复制代码
AdminVo.java
  1. packagecom.hqyj.psl.entity;importlombok.Data;importjava.util.List;@DatapublicclassAdminVoextendsAdmin{privateInteger adminId;privateString username;privateList<Role> roles;privateInteger roleId;privateString rname;privateString url;//    private List<Permission> permissions;}
复制代码
MyFile.java
  1. packagecom.hqyj.psl.entity;importlombok.Data;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/17
  5. * \* Time: 14:06
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@DatapublicclassMyFile{privateInteger fileId;privateString  fileName;privateString  fileUrl;//存储的是Tomcat中的war包中的地址}
复制代码
Orders.java
  1. packagecom.hqyj.psl.entity;importcom.fasterxml.jackson.annotation.JsonFormat;importorg.springframework.format.annotation.DateTimeFormat;importjava.util.Date;publicclassOrdersextendsUsersPage{privateInteger ordersId;privateString ordersNo;privateString ordersName;privateString phone;privateDouble totalAmount;privateDouble payAmount;privateString ordersState;privateString payState;privateString shipmentsState;privateString giveMethod;@DateTimeFormat(pattern ="yyyy-MM-dd")privateDate ordersTime;privateInteger isVip;privateString listId;publicStringgetListId(){return listId;}publicvoidsetListId(String listId){this.listId = listId;}publicIntegergetIsVip(){return isVip;}publicvoidsetIsVip(Integer isVip){this.isVip = isVip;}@OverridepublicStringtoString(){return"Orders{"+"ordersId="+ ordersId +", ordersNo='"+ ordersNo +'\''+", ordersName='"+ ordersName +'\''+", phone='"+ phone +'\''+", totalAmount="+ totalAmount +", payAmount="+ payAmount +", ordersState='"+ ordersState +'\''+", payState='"+ payState +'\''+", shipmentsState='"+ shipmentsState +'\''+", giveMethod='"+ giveMethod +'\''+", ordersTime="+ ordersTime +", isVip="+ isVip +", listId="+ listId +'}';}publicIntegergetOrdersId(){return ordersId;}publicvoidsetOrdersId(Integer ordersId){this.ordersId = ordersId;}publicStringgetOrdersNo(){return ordersNo;}publicvoidsetOrdersNo(String ordersNo){this.ordersNo = ordersNo;}publicStringgetOrdersName(){return ordersName;}publicvoidsetOrdersName(String ordersName){this.ordersName = ordersName;}publicStringgetPhone(){return phone;}publicvoidsetPhone(String phone){this.phone = phone;}publicDoublegetTotalAmount(){return totalAmount;}publicvoidsetTotalAmount(Double totalAmount){this.totalAmount = totalAmount;}publicDoublegetPayAmount(){return payAmount;}publicvoidsetPayAmount(Double payAmount){this.payAmount = payAmount;}publicStringgetOrdersState(){return ordersState;}publicvoidsetOrdersState(String ordersState){this.ordersState = ordersState;}publicStringgetPayState(){return payState;}publicvoidsetPayState(String payState){this.payState = payState;}publicStringgetShipmentsState(){return shipmentsState;}publicvoidsetShipmentsState(String shipmentsState){this.shipmentsState = shipmentsState;}publicStringgetGiveMethod(){return giveMethod;}publicvoidsetGiveMethod(String giveMethod){this.giveMethod = giveMethod;}@JsonFormat(pattern ="yyyy-MM-dd")publicDategetOrdersTime(){return ordersTime;}publicvoidsetOrdersTime(Date ordersTime){this.ordersTime = ordersTime;}}
复制代码
Permission.java
  1. packagecom.hqyj.psl.entity;importlombok.AllArgsConstructor;importlombok.Data;importlombok.NoArgsConstructor;@Data@AllArgsConstructor@NoArgsConstructorpublicclassPermission{privateInteger permissionId;privateString url="sdfasdf";privateString state;}
复制代码
Role.java
  1. packagecom.hqyj.psl.entity;importlombok.Data;@DatapublicclassRole{privateInteger roleId;privateString name;privateString state;}
复制代码
Users.java
  1. packagecom.hqyj.psl.entity;importcom.fasterxml.jackson.annotation.JsonFormat;importorg.springframework.format.annotation.DateTimeFormat;importjava.util.Date;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/19
  5. * \* Time: 13:52
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */publicclassUsersextendsUsersPage{privateInteger usersId;privateString name;//昵称privateString sex;privateString address;privateString phone;privateString email;privateString  username;privateString  password;privateInteger isVip;privateInteger deleted;//做逻辑删除的privateString bitId;privateString rbitId;publicStringgetRbitId(){return rbitId;}publicvoidsetRbitId(String rbitId){this.rbitId = rbitId;}publicStringgetBitId(){return bitId;}publicvoidsetBitId(String bitId){this.bitId = bitId;}@DateTimeFormat(pattern ="yyyy-MM-dd")privateDate joinDate;//入职日期@OverridepublicStringtoString(){return"Users{"+"usersId="+ usersId +", name='"+ name +'\''+", sex='"+ sex +'\''+", address='"+ address +'\''+", phone='"+ phone +'\''+", email='"+ email +'\''+", username='"+ username +'\''+", password='"+ password +'\''+", isVip="+ isVip +", deleted="+ deleted +", joinDate="+ joinDate +'}';}publicIntegergetUsersId(){return usersId;}publicvoidsetUsersId(Integer usersId){this.usersId = usersId;}publicStringgetName(){return name;}publicvoidsetName(String name){this.name = name;}publicStringgetSex(){return sex;}publicvoidsetSex(String sex){this.sex = sex;}publicStringgetAddress(){return address;}publicvoidsetAddress(String address){this.address = address;}publicStringgetPhone(){return phone;}publicvoidsetPhone(String phone){this.phone = phone;}publicStringgetEmail(){return email;}publicvoidsetEmail(String email){this.email = email;}publicStringgetUsername(){return username;}publicvoidsetUsername(String username){this.username = username;}publicStringgetPassword(){return password;}publicvoidsetPassword(String password){this.password = password;}publicIntegergetIsVip(){return isVip;}publicvoidsetIsVip(Integer isVip){this.isVip = isVip;}publicIntegergetDeleted(){return deleted;}publicvoidsetDeleted(Integer deleted){this.deleted = deleted;}@JsonFormat(pattern ="yyyy-MM-dd")publicDategetJoinDate(){return joinDate;}publicvoidsetJoinDate(Date joinDate){this.joinDate = joinDate;}}
复制代码
UsersPage.java
  1. packagecom.hqyj.psl.entity;importlombok.Data;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/16
  5. * \* Time: 14:07
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@DatapublicclassUsersPage{privateInteger page;//页数privateInteger num;//每页数量}
复制代码
2.耐久层(mapper)又称dao层

AdminMapper.java
  1. packagecom.hqyj.psl.mapper;importcom.hqyj.psl.entity.Admin;importorg.springframework.stereotype.Repository;importjava.util.List;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/18
  5. * \* Time: 23:13
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@RepositorypublicinterfaceAdminMapper{AdminselectByName(String username);IntegerinsertBySignup(String username,String password);Integerupdate(Admin admin);Adminshow(Admin admin);//根据用户名查询所拥有的角色List<String>selectRolesByUsername(String name);//根据用户名查询拥有的权限List<String>selectPermsByUsername(String name);}
复制代码
MyFileMapper.java
  1. packagecom.hqyj.psl.mapper;importcom.hqyj.psl.entity.MyFile;importorg.springframework.stereotype.Repository;importjava.util.List;@RepositorypublicinterfaceMyFileMapper{//查所有List<MyFile>selectAll();//添加Integerinsert(MyFile myFile);//删除//修改//根据id查询//移除文件IntegerdeleteFile(MyFile myFile);}
复制代码
OrdersMapper.java
  1. packagecom.hqyj.psl.mapper;importcom.hqyj.psl.entity.Orders;importorg.springframework.stereotype.Repository;importjava.util.List;@RepositorypublicinterfaceOrdersMapper{/*List<Orders> selectAll();*///删除Integerdelete(Orders orders);//修改Integerupdate(Orders orders);//修改Integerinsert(Orders orders);//模糊查/查所有List<Orders>selectLike(Orders orders);IntegerdeleteAll(List list);}
复制代码
RoleMapper.java
  1. packagecom.hqyj.psl.mapper;importcom.hqyj.psl.entity.AdminVo;importcom.hqyj.psl.entity.Role;importorg.springframework.stereotype.Repository;importjava.util.List;@RepositorypublicinterfaceRoleMapper{//查找所有角色List<AdminVo>selectRoleAll();//根据角色查询所有拥有权限List<String>selectPermsByRole(Integer roleId);//根据用户名查询所有拥有的角色List<String>selectRolesByUsername(String username);//根据用户名查询所有拥有的权限List<String>selectPermsByUsername(String username);//添加角色及其权限//修改角色与权限//直接修改role表修改角色名IntegerupdateRoleName(Role role);//修改权限//删除权限关联表中的关联IntegerdeleteRole_P(Integer roleId);//根据权限名url查询权限idIntegerselectPreId(String url);//添加权限关联表中的关联添加 preidIntegeraddRole_P(Integer rId,Integer pId);//删除逻辑//1.删除Role表中的关系IntegerdeleteRole(Integer roleId);//2.删除Role_Pre中的关系//上面有方法//添加角色逻辑//1.在Role表中添加角色名IntegeraddRoleName(Role role);//2.查询Role表中的roleId 通过角色名IntegerselectRoleByName(Role role);//3.根据权限名url查询权限id//修改里面有方法//4.添加权限关联表中的关联添加 preid//修改里面有方法}
复制代码
UsersMapper.java
  1. packagecom.hqyj.psl.mapper;importcom.hqyj.psl.entity.Users;importcom.hqyj.psl.entity.Users;importorg.springframework.stereotype.Repository;importjava.util.List;@RepositorypublicinterfaceUsersMapper{//查所有List<Users>selectAll();//添加Integerinsert(Users users);//删除IntegerdeleteByUserId(Integer id);//修改Integerupdate(Users users);//逻辑删除IntegerdeleteUpdByUserId(Integer usersId);List<Users>search(Users users);IntegerdeleteAll(List list);//查找逻辑删除的List<Users>selectByDeletedUsers();//恢复删除Integerrenew(Integer usersId);//物理删除IntegerphyDel(Integer usersId);//条件查找List<Users>condQuery(Users user);//批量恢复IntegerupdateRenbit(List list);/*登录*/UsersselectOneByUsername(String username);////    //根据用户名查询所拥有的角色//    List<String> selectRolesByUsername(String username);//    //根据用户名查询拥有的权限//    List<String> selectPermsByUsername(String username);}
复制代码
3.业务层(service)

service(定义接口)

AdminService.java
  1. packagecom.hqyj.psl.service;importcom.hqyj.psl.entity.Admin;importcom.hqyj.psl.entity.AdminVo;importcom.hqyj.psl.utils.ResultUtils;importjavax.servlet.http.HttpSession;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/19
  5. * \* Time: 14:06
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */publicinterfaceAdminService{ResultUtilslogin(Admin admin,HttpSession session);ResultUtilsregister(Admin admin);ResultUtilslogout(HttpSession session);ResultUtilsupdate(Admin admin);ResultUtilsshow(Admin admin);}
复制代码
MyFileService.java
  1. packagecom.hqyj.psl.service;importcom.hqyj.psl.entity.MyFile;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.http.ResponseEntity;importorg.springframework.web.multipart.MultipartFile;importjavax.servlet.http.HttpServletRequest;importjava.io.IOException;publicinterfaceMyFileService{//查所有ResultUtilsfileList();//增加ResultUtilsinsert(MyFile myFile);//文档的上传 MultipartFile.transferTo  将接受到的文件传输到给定的目的文件ResultUtilsupload(MultipartFile multipartFile,HttpServletRequest request);//文档的下载ResponseEntity<byte[]>downLoad(String fileName,HttpServletRequest request)throwsIOException;//文档移除ResultUtilsdeleteFile(MyFile myFile);}
复制代码
OrdersService.java
  1. packagecom.hqyj.psl.service;importcom.hqyj.psl.entity.Orders;importcom.hqyj.psl.utils.ResultUtils;publicinterfaceOrdersService{/*ResultUtils ordersList(Orders orders);//查所有*/ResultUtilsdelete(Orders orders);//删除ResultUtilsupdate(Orders orders);//修改ResultUtilsinsert(Orders orders);//增加ResultUtilsselectLike(Orders orders);//模糊查/查所有ResultUtilsdeleteAll(Orders orders);//批量删除}
复制代码
UsersService.java
  1. packagecom.hqyj.psl.service;importcom.hqyj.psl.entity.Users;importcom.hqyj.psl.utils.ResultUtils;importjavax.servlet.http.HttpSession;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/19
  5. * \* Time: 14:00
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */publicinterfaceUsersService{ResultUtilsusersList(Users user);ResultUtilslogin(Users user,HttpSession session);ResultUtilslogout(HttpSession session);ResultUtilsupdate(Users user);ResultUtilsdeleteUpdByUserId(Users user);ResultUtilsdelete(Integer id);ResultUtils insert (Users user);ResultUtilssearch(Users users);ResultUtilsdeleteAll(Users users);ResultUtilsselectByDeletedUsers(Users user);//查找被逻辑删除的ResultUtilsrenew(Users user);//恢复删除ResultUtilsphyDel(Users user);//物理删除ResultUtilscondQuery(Users user);//条件查找ResultUtilsrenewAll(Users user);//批量恢复}
复制代码
Impl(实现接口)

AdminServiceImpl.java
  1. packagecom.hqyj.psl.service.impl;importcom.hqyj.psl.entity.Admin;importcom.hqyj.psl.entity.AdminVo;importcom.hqyj.psl.mapper.AdminMapper;importcom.hqyj.psl.service.AdminService;importcom.hqyj.psl.utils.ResultUtils;importorg.apache.shiro.SecurityUtils;importorg.apache.shiro.authc.IncorrectCredentialsException;importorg.apache.shiro.authc.UnknownAccountException;importorg.apache.shiro.authc.UsernamePasswordToken;importorg.apache.shiro.subject.Subject;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjavax.servlet.http.HttpSession;importjava.util.List;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/19
  5. * \* Time: 14:06
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@ServicepublicclassAdminServiceImplimplementsAdminService{@AutowiredprivateAdminMapper adminMapper;@OverridepublicResultUtilslogin(Admin admin,HttpSession session){//0.非空验证if(admin.getUsername()==""|| admin.getPassword()==""){returnnewResultUtils(500,"用户名不能为空",null);}try{//1.获取当前用户对象主体Subject subject =SecurityUtils.getSubject();System.out.println("service中的subject对象:"+ subject);//2.将恳求参数封装到token中UsernamePasswordToken token =newUsernamePasswordToken(admin.getUsername(), admin.getPassword());//3。完成登录
  10.             subject.login(token);
  11.             session.setAttribute("user",admin.getUsername());
  12.             session.setAttribute("admin",admin);returnnewResultUtils(200,"登录胜利",null);}catch(UnknownAccountException e){returnnewResultUtils(500,"用户名不存在",null);}catch(IncorrectCredentialsException e){returnnewResultUtils(500,"密码错误",null);}}@OverridepublicResultUtilsregister(Admin admin){Integer integer = adminMapper.insertBySignup(admin.getUsername(),admin.getPassword());returnnewResultUtils(200,"注册胜利","success");}@OverridepublicResultUtilslogout(HttpSession session){//退出(session失效)//基于登录状态下放入session中所有的属性,如用户信息(状态),购物车等
  13.         session.invalidate();//session移除某一个属性//session.removeAttribute("user");returnnewResultUtils(200,"退出胜利","login");}//修改用户个人信息@OverridepublicResultUtilsupdate(Admin admin){System.out.println("修改里面的数据"+admin);Integer update = adminMapper.update(admin);returnnewResultUtils(200,"修改胜利","");}//数据回显@OverridepublicResultUtilsshow(Admin admin){Admin show = adminMapper.show(admin);returnnewResultUtils(200,"显示胜利",show);}}
复制代码
MyFileServiceImpl.java
  1. packagecom.hqyj.psl.service.impl;importcom.hqyj.psl.entity.MyFile;importcom.hqyj.psl.mapper.MyFileMapper;importcom.hqyj.psl.service.MyFileService;importcom.hqyj.psl.utils.ResultUtils;importorg.apache.commons.io.FileUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.http.HttpHeaders;importorg.springframework.http.HttpStatus;importorg.springframework.http.MediaType;importorg.springframework.http.ResponseEntity;importorg.springframework.stereotype.Service;importorg.springframework.web.multipart.MultipartFile;importjavax.servlet.http.HttpServletRequest;importjava.io.File;importjava.io.IOException;importjava.util.HashMap;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/17
  5. * \* Time: 14:25
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@ServicepublicclassMyFileServiceImplimplementsMyFileService{@AutowiredprivateMyFileMapper myFileMapper;@OverridepublicResultUtilsfileList(){returnnewResultUtils(200,"",myFileMapper.selectAll());}@OverridepublicResultUtilsinsert(MyFile myFile){
  10.         myFileMapper.insert(myFile);returnnewResultUtils(200,"添加胜利",null);}@OverridepublicResultUtilsupload(MultipartFile multipartFile,HttpServletRequest request){try{//1.获取文件上传目录的途径String filePath= request.getSession().getServletContext().getRealPath("upload");//虚拟途径System.out.println("上传文件的目录途径"+filePath);//2.获取上传的文件名String fileName = multipartFile.getOriginalFilename();System.out.println("上传的文件名"+fileName);//3.创建File对象File f =newFile(filePath+"/"+fileName);//4.判断文件上传的目录是否存在if(!f.isDirectory()){//创建目录System.out.println("文件上传目录是否存在");
  11.                 f.mkdirs();}//5.上传文件
  12.             multipartFile.transferTo(f);//6.创建map封装记录文件名及文件途径HashMap<String,Object> map =newHashMap<>();//localhost:8080/upload/a.txt
  13.             map.put("servicePath","/upload/"+fileName);
  14.             map.put("fileName",fileName);returnnewResultUtils(200,"上传胜利",map);}catch(IOException e){
  15.             e.printStackTrace();returnnewResultUtils(500,"上传失败",null);}}@OverridepublicResponseEntity<byte[]>downLoad(String fileName,HttpServletRequest request)throwsIOException{//1.获取文档上传的途径String filePath = request.getSession().getServletContext().getRealPath("upload");System.out.println("获取文件上传的途径"+filePath);//2.创建文件对象File file =newFile(filePath +"/"+ fileName);//3.设置httpHeaders,使阅读器响应下载HttpHeaders headers =newHttpHeaders();//4.设置响应方式
  16.         headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);//5.设置响应头/*
  17.         *  headerName:
  18.         *       contentType:响应的内容格式
  19.         *       contentDisposition
  20.         *               -inline:直接在页面展示a
  21.         *               -attachment:以附件的形式下载
  22.         *
  23.         * 乱码处置:
  24.         * */
  25.         headers.set("Content-Disposition","attachment;fileName="+newString(fileName.getBytes("utf-8"),"ISO8859-1")+"");returnnewResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers,HttpStatus.CREATED);}//移除文件@OverridepublicResultUtilsdeleteFile(MyFile myFile){Integer integer = myFileMapper.deleteFile(myFile);returnnewResultUtils(200,"移除胜利",null);}}
复制代码
OrderServiceImpl.java
  1. packagecom.hqyj.psl.service.impl;importcom.github.pagehelper.PageHelper;importcom.github.pagehelper.PageInfo;importcom.hqyj.psl.entity.Orders;importcom.hqyj.psl.mapper.OrdersMapper;importcom.hqyj.psl.service.OrdersService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjava.util.Arrays;importjava.util.Date;importjava.util.HashMap;importjava.util.List;@ServicepublicclassOrderServiceImplimplementsOrdersService{@AutowiredprivateOrdersMapper ordersMapper;/*@Override
  2.     public ResultUtils ordersList(Orders orders) {
  3.         //开启分页
  4.         PageHelper.startPage(orders.getPage(),orders.getNum());
  5.         List<Orders> orders1 = ordersMapper.selectAll();
  6.         System.out.println(orders1+"-----------");
  7.         PageInfo list = new PageInfo(orders1);
  8.         HashMap<String, Object> map = new HashMap<>();
  9.         map.put("totalPage",list.getPages());//总页数
  10.         map.put("list",list.getList());//每页的数据
  11.         map.put("total",list.getTotal());//总条数
  12.         return new ResultUtils(200,"",map);
  13.     }*/@OverridepublicResultUtilsdelete(Orders orders){
  14.         ordersMapper.delete(orders);returnnewResultUtils(200,"删除胜利",null);}@OverridepublicResultUtilsupdate(Orders orders){
  15.         ordersMapper.update(orders);returnnewResultUtils(200,"修改胜利",null);}@OverridepublicResultUtilsinsert(Orders orders){
  16.         orders.setOrdersTime(newDate());
  17.         ordersMapper.insert(orders);returnnewResultUtils(200,"添加胜利",null);}@Override//模糊查/查所有publicResultUtilsselectLike(Orders orders){System.out.println(orders);//开启分页PageHelper.startPage(orders.getPage(),orders.getNum());List<Orders> order = ordersMapper.selectLike(orders);PageInfo list =newPageInfo(order);HashMap<String,Object> map =newHashMap<>();
  18.         map.put("totalPage",list.getPages());//总页数
  19.         map.put("list",list.getList());//每页的数据
  20.         map.put("total",list.getTotal());//总条数returnnewResultUtils(200,"找到"+order.size()+"条数据",map);}@OverridepublicResultUtilsdeleteAll(Orders orders){String[] split = orders.getListId().split(",");List<String> strings =Arrays.asList(split);Integer integer = ordersMapper.deleteAll(strings);if(integer >0)returnnewResultUtils(200,"删除胜利",null);returnnull;}}
复制代码
RoleServiceImpl.java
  1. packagecom.hqyj.psl.service.impl;importcom.hqyj.psl.entity.AdminVo;importcom.hqyj.psl.entity.Role;importcom.hqyj.psl.mapper.RoleMapper;importcom.hqyj.psl.service.RoleService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjava.util.List;@ServicepublicclassRoleServiceImplimplementsRoleService{@AutowiredprivateRoleMapper roleMapper;@OverridepublicResultUtilsselectRolePerAll(){//        //测试获取所有角色//        List<AdminVo> strings = adminMapper.selectRoleAll();//        //根据角色拿去对应权限//        HashMap<String, List<String>> map = new HashMap<>();//        for (int i = 0; i < strings.size(); i++) {//            AdminVo adminVo = strings.get(i);//            String username =adminVo.getUsername();//            Integer adminId = adminVo.getAdminId();//            List<String> url = adminMapper.selectPermsByRole(username);//            url.add(adminId.toString());//            map.put(username,url);//        }//        System.out.println("数据已经拿到了:"+map);//测试获取所有角色List<AdminVo> strings = roleMapper.selectRoleAll();//根据角色拿去对应权限System.out.println(strings);//        HashMap<String, List<String>> map = new HashMap<>();for(int i =0; i < strings.size(); i++){AdminVo adminVo = strings.get(i);String username =adminVo.getUsername();Integer roleId = adminVo.getRoles().get(0).getRoleId();List<String> url = roleMapper.selectPermsByRole(roleId);
  2.             strings.get(i).setUrl(url.toString());//            map.put(username,url);}System.out.println(strings);returnnewResultUtils(200,"获取胜利",strings);}@OverridepublicResultUtilsupdateRoleAndPer(AdminVo adminVo){try{//直接修改role表修改角色名Role role =newRole();
  3.             role.setRoleId(adminVo.getRoleId());
  4.             role.setName(adminVo.getRname());
  5.             roleMapper.updateRoleName(role);//修改权限//删除权限关联表中的关联
  6.             roleMapper.deleteRole_P(role.getRoleId());//根据权限名url查询权限idString[] split = adminVo.getUrl().split(" ");System.out.println("我是权限:"+ split);for(int i =0; i < split.length; i++){if(!(split[i].equals(""))){System.out.println("我是权限......+"+split[i]);Integer preId = roleMapper.selectPreId(split[i]);System.out.println("我是preId....."+preId);//添加权限关联表中的关联添加 preid
  7.                     roleMapper.addRole_P(role.getRoleId(), preId);}}returnnewResultUtils(200,"修改胜利",null);}catch(Exception e){returnnewResultUtils(500,"修改失败",null);}}//删除Role@OverridepublicResultUtilsdeleteRole(AdminVo adminVo){try{//删除Role_pre中的关系
  8.             roleMapper.deleteRole_P(adminVo.getRoleId());//删除Role中角色
  9.             roleMapper.deleteRole(adminVo.getRoleId());returnnewResultUtils(200,"删除胜利",null);}catch(Exception e){returnnewResultUtils(500,"删除失败",null);}}//添加逻辑@OverridepublicResultUtilsaddRole(AdminVo adminVo){try{Role role =newRole();
  10.             role.setName(adminVo.getRname());//添加角色逻辑//1.在Role表中添加角色名
  11.             roleMapper.addRoleName(role);//2.查询Role表中的roleId 通过角色名Integer roleId = roleMapper.selectRoleByName(role);
  12.             role.setRoleId(roleId);//3.根据权限名url查询权限idString[] split = adminVo.getUrl().split(" ");System.out.println("我是权限:"+ split);for(int i =0; i < split.length; i++){if(!(split[i].equals(""))){Integer preId = roleMapper.selectPreId(split[i]);//添加权限关联表中的关联添加 preid
  13.                     roleMapper.addRole_P(role.getRoleId(), preId);}}returnnewResultUtils(200,"添加胜利",null);}catch(Exception e){returnnewResultUtils(500,"添加失败",null);}}}
复制代码
UsersServiceImpl.java
  1. packagecom.hqyj.psl.service.impl;importcom.github.pagehelper.PageHelper;importcom.github.pagehelper.PageInfo;importcom.hqyj.psl.entity.Users;importcom.hqyj.psl.mapper.UsersMapper;importcom.hqyj.psl.service.UsersService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjavax.servlet.http.HttpSession;importjava.util.Arrays;importjava.util.Date;importjava.util.HashMap;importjava.util.List;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/19
  5. * \* Time: 14:01
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@ServicepublicclassUsersServiceImplimplementsUsersService{@AutowiredprivateUsersMapper usersMapper;@OverridepublicResultUtilssearch(Users users){PageHelper.startPage(users.getPage(),users.getNum());List<Users> search = usersMapper.search(users);PageInfo pageInfo =newPageInfo(search);HashMap<String,Object> hashMap =newHashMap<>();
  10.         hashMap.put("totalPage",pageInfo.getPages());
  11.         hashMap.put("list",pageInfo.getList());
  12.         hashMap.put("total",pageInfo.getTotal());returnnewResultUtils(200,"模糊查询分页",hashMap);}@OverridepublicResultUtilsdeleteAll(Users users){//处置字符串String[] strings = users.getBitId().split(",");//将字符数组转为listList<String> list =Arrays.asList(strings);System.out.println(list);
  13.         usersMapper.deleteAll(list);returnnewResultUtils(200,"删除胜利",null);}@OverridepublicResultUtilsusersList(Users users){//开启分页PageHelper.startPage(users.getPage(),users.getNum());//获取所有数据List<Users> userAll = usersMapper.selectAll();System.out.println("分页");PageInfo list =newPageInfo(userAll);HashMap<String,Object> map =newHashMap<>();
  14.         map.put("totalPage",list.getPages());//总页数
  15.         map.put("list",list.getList());//每页显示的数据
  16.         map.put("total",list.getTotal());//总条数returnnewResultUtils(200,"",map);}@OverridepublicResultUtilslogin(Users users,HttpSession session){returnnull;}@OverridepublicResultUtilslogout(HttpSession session){returnnull;}@OverridepublicResultUtilsupdate(Users users){
  17.         users.setDeleted(0);System.out.println("跑了");
  18.         users.setJoinDate(newDate());Integer update = usersMapper.update(users);if(update>0){returnnewResultUtils(200,"修改胜利",null);}else{returnnewResultUtils(500,"修改失败",null);}}@OverridepublicResultUtilsdeleteUpdByUserId(Users users){
  19.         usersMapper.deleteUpdByUserId(users.getUsersId());returnnewResultUtils(200,"删除胜利",null);}@OverridepublicResultUtilsdelete(Integer id){returnnull;}@OverridepublicResultUtilsinsert(Users users){System.out.println(users);
  20.         users.setDeleted(0);
  21.         users.setJoinDate(newDate());
  22.         usersMapper.insert(users);returnnewResultUtils(200,"已添加",null);}@OverridepublicResultUtilsselectByDeletedUsers(Users user){System.out.println("当前页:"+ user.getPage());System.out.println("当前页条数:"+ user.getNum());//开启分页PageHelper.startPage(user.getPage(),user.getNum());//PageHelper.startPage(1,2);//获取所有数据List<Users> users = usersMapper.selectByDeletedUsers();PageInfo list =newPageInfo(users);HashMap<String,Object> map =newHashMap<>();
  23.         map.put("totalPage",list.getPages());//总页数
  24.         map.put("list",list.getList());//每页显示的数据
  25.         map.put("total",list.getTotal());//总条数returnnewResultUtils(200,"",map);}//恢复删除@OverridepublicResultUtilsrenew(Users user){
  26.         usersMapper.renew(user.getUsersId());returnnewResultUtils(200,"恢复胜利",null);}@OverridepublicResultUtilsphyDel(Users user){
  27.         usersMapper.phyDel(user.getUsersId());returnnewResultUtils(200,"删除胜利",null);}//查找全部被逻辑删除的@OverridepublicResultUtilscondQuery(Users user){System.out.println("当前页:"+ user.getPage());System.out.println("当前页条数:"+ user.getNum());//开启分页PageHelper.startPage(user.getPage(), user.getNum());//PageHelper.startPage(1,2);//获取所有数据List<Users> users = usersMapper.condQuery(user);PageInfo list =newPageInfo(users);HashMap<String,Object> map =newHashMap<>();
  28.         map.put("totalPage", list.getPages());//总页数
  29.         map.put("list", list.getList());//每页显示的数据
  30.         map.put("total", list.getTotal());//总条数returnnewResultUtils(200,"查找胜利", map);}//批量恢复@OverridepublicResultUtilsrenewAll(Users users){//1.处置字符串String[] strings = users.getRbitId().split(",");//2.将字符转为listList<String> list =Arrays.asList(strings);System.out.println("id为:"+list);//3.
  31.         usersMapper.updateRenbit(list);returnnewResultUtils(200,"恢复胜利",null);}}
复制代码
4.控制层(controller)

AdminController.java
  1. packagecom.hqyj.psl.controller;importcom.hqyj.psl.entity.AdminVo;importcom.hqyj.psl.service.RoleService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;@RestControllerpublicclassAdminController{@AutowiredprivateRoleService roleService;//前端角色逻辑@RequestMapping("/adminRole/{url}")publicResultUtilsadminRole(@PathVariableString url,AdminVo adminVo){System.out.println("前端发送的数据为:"+url);switch(url){case"role":return roleService.selectRolePerAll();case"updateRole":return roleService.updateRoleAndPer(adminVo);case"deleteRole":return roleService.deleteRole(adminVo);case"addRole":return roleService.addRole(adminVo);//                return adminService.addRole(adminVo);}returnnull;}}
复制代码
FileController.java
  1. packagecom.hqyj.psl.controller;importcom.hqyj.psl.entity.MyFile;importcom.hqyj.psl.service.MyFileService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.http.ResponseEntity;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web.multipart.MultipartFile;importjavax.servlet.http.HttpServletRequest;importjava.io.IOException;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/17
  5. * \* Time: 15:00
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@RestControllerpublicclassFileController{@AutowiredprivateMyFileService myFileService;//执行file的增删查改恳求@RequestMapping("/myFileAjax/{url}")publicResultUtilsmyFileAjax(@PathVariableString url,MyFile myFile){switch(url){case"insert":return myFileService.insert(myFile);case"fileList":return myFileService.fileList();case"deleteFile":return myFileService.deleteFile(myFile);}returnnull;}//文档上传恳求@RequestMapping("/file/upload")publicResultUtilsupload(@RequestParam("file")MultipartFile file,HttpServletRequest request){return myFileService.upload(file,request);}//文件下载@RequestMapping("/file/downLoad")publicResponseEntity<byte[]>downLoad(String fileName,HttpServletRequest request)throwsIOException{return myFileService.downLoad(fileName,request);}}
复制代码
  1. packagecom.hqyj.psl.controller;importcom.hqyj.psl.entity.Orders;importcom.hqyj.psl.service.OrdersService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;@RestControllerpublicclassOrdersController{@AutowiredprivateOrdersService ordersService;@RequestMapping("/orders/{url}")publicResultUtilstoOrders(@PathVariableString url,Orders orders){switch(url){/*case "ordersList"://查所有
  2.                 return ordersService.ordersList(orders);*/case"delete"://删除
  3.                 return ordersService.delete(orders);case"update"://修改
  4.                 return ordersService.update(orders);case"insert"://增加
  5.                 return ordersService.insert(orders);case"selectLike"://模糊查
  6.                 return ordersService.selectLike(orders);case"deleteAll"://模糊查
  7.                 return ordersService.deleteAll(orders);}returnnull;}}
复制代码
OrdersController.java
  1. packagecom.hqyj.psl.controller;importcom.hqyj.psl.entity.Orders;importcom.hqyj.psl.service.OrdersService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;@RestControllerpublicclassOrdersController{@AutowiredprivateOrdersService ordersService;@RequestMapping("/orders/{url}")publicResultUtilstoOrders(@PathVariableString url,Orders orders){switch(url){/*case "ordersList"://查所有
  2.                 return ordersService.ordersList(orders);*/case"delete"://删除
  3.                 return ordersService.delete(orders);case"update"://修改
  4.                 return ordersService.update(orders);case"insert"://增加
  5.                 return ordersService.insert(orders);case"selectLike"://模糊查
  6.                 return ordersService.selectLike(orders);case"deleteAll"://模糊查
  7.                 return ordersService.deleteAll(orders);}returnnull;}}
复制代码
PageController.java
  1. packagecom.hqyj.psl.controller;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/15
  5. * \* Time: 16:30
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@ControllerpublicclassPageController{@RequestMapping("/{url}")publicStringlogin(@PathVariableString url){return url;}}
复制代码
UsersController.java
  1. packagecom.hqyj.psl.controller;importcom.hqyj.psl.entity.Admin;importcom.hqyj.psl.entity.Users;importcom.hqyj.psl.entity.Users;importcom.hqyj.psl.service.AdminService;importcom.hqyj.psl.service.UsersService;importcom.hqyj.psl.service.UsersService;importcom.hqyj.psl.utils.ResultUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;importjavax.servlet.http.HttpSession;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/12
  5. * \* Time: 10:21
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@RestControllerpublicclassUsersController{@AutowiredprivateUsersService usersService;@AutowiredprivateAdminService adminService;@RequestMapping("/admin/{url}")publicResultUtilslogin(@PathVariableString url,Admin admin,HttpSession session){switch(url){case"login":return adminService.login(admin,session);case"signup":return adminService.register(admin);case"logout":return adminService.logout(session);case"update":return adminService.update(admin);case"showAdm":return adminService.show(admin);}returnnull;}@RequestMapping("/users/{url}")//    @ResponseBodypublicResultUtilstoLogin(@PathVariableString url,Users users,HttpSession session){switch(url){case"login":return usersService.login(users,session);case"deleteAll":return usersService.deleteAll(users);case"search":return usersService.search(users);case"userList":return usersService.usersList(users);case"updateUsers":return usersService.update(users);case"deleteUserById":return usersService.delete(users.getUsersId());case"insertUser":return usersService.insert(users);case"delete":return usersService.deleteUpdByUserId(users);case"userDel":return usersService.selectByDeletedUsers(users);case"renew":return usersService.renew(users);case"phyDel":return usersService.phyDel(users);case"condQuery":System.out.println("1");return usersService.condQuery(users);case"renewAll":return usersService.renewAll(users);}returnnull;//        1.接受数据}}
复制代码
5.工具层(utils)

MdFiveUtils.java
  1. packagecom.hqyj.psl.utils;importorg.apache.shiro.crypto.hash.Md5Hash;importorg.apache.shiro.crypto.hash.SimpleHash;importorg.springframework.stereotype.Component;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/20
  5. * \* Time: 9:41
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * \
  9. */@Component//注册beanpublicclassMdFiveUtils{publicStringchangePassword(String salt,String password){Md5Hash md5Hash =newMd5Hash(salt);SimpleHash pwd =newSimpleHash("MD5", password, md5Hash,1024);return pwd.toString();}publicstaticvoidmain(String[] args){MdFiveUtils md =newMdFiveUtils();String zhangsan = md.changePassword("zhangsan","123456");System.out.println(zhangsan);}}
复制代码
ResultUtils.java
  1. packagecom.hqyj.psl.utils;importlombok.AllArgsConstructor;importlombok.Data;importlombok.NoArgsConstructor;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/16
  5. * \* Time: 10:12
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description:
  8. * 结果集工具类
  9. * \
  10. */@Data@AllArgsConstructor@NoArgsConstructorpublicclassResultUtils{privateInteger code;//状态码privateString msg;//消息信息privateObject data;//返回对象}
复制代码
UserRealm.java
6.登录实现层(realm)
  1. packagecom.hqyj.psl.realm;importcom.hqyj.psl.entity.Admin;importcom.hqyj.psl.mapper.AdminMapper;importorg.apache.shiro.authc.*;importorg.apache.shiro.authz.AuthorizationInfo;importorg.apache.shiro.authz.SimpleAuthorizationInfo;importorg.apache.shiro.crypto.hash.Md5Hash;importorg.apache.shiro.realm.AuthorizingRealm;importorg.apache.shiro.subject.PrincipalCollection;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.test.context.TestConstructor;importjava.util.List;/**
  2. * \* Created with IntelliJ IDEA.
  3. * \* User: PuSongLin
  4. * \* Date: 2022/8/18
  5. * \* Time: 9:41
  6. * \* To change this template use File | Settings | File Templates.
  7. * \* Description: 领域:用于帮我们认证添加当前主体(subject--用户)的角色信息,权限信息
  8. * \
  9. */publicclassUserRealmextendsAuthorizingRealm{@AutowiredprivateAdminMapper adminMapper;@Override//受权protectedAuthorizationInfodoGetAuthorizationInfo(PrincipalCollection principalCollection){//1.获取当前登录的用户String name = principalCollection.fromRealm(this.getName()).iterator().next()+"";System.out.println("获取当前登录的用户"+name);//2.根据用户名查询角色及权限信息List<String> roles = adminMapper.selectRolesByUsername(name);List<String> perms = adminMapper.selectPermsByUsername(name);System.out.println("角色为:"+roles+"权限为:"+perms);//3.获取受权信息对象SimpleAuthorizationInfo simpleAuthorizationInfo =newSimpleAuthorizationInfo();System.out.println("受权对象"+simpleAuthorizationInfo);//4.添加角色信息
  10.         simpleAuthorizationInfo.addRoles(roles);//5.添加受权信息
  11.         simpleAuthorizationInfo.addStringPermissions(perms);System.out.println("受权信息:"+simpleAuthorizationInfo);return simpleAuthorizationInfo;}@Override//认证-- 此处可究,量力而行protectedAuthenticationInfodoGetAuthenticationInfo(AuthenticationToken authenticationToken)throwsAuthenticationException{//1.取出token对象 authenticationTokenUsernamePasswordToken token=(UsernamePasswordToken)authenticationToken;System.out.println("token对象:"+token);//2.获取身份凭证String username = token.getPrincipal()+"";System.out.println("凭证为:"+username);//3.检验是否存在Admin admin =adminMapper.selectByName(username);//4.判断用户是否存在if(admin==null){thrownewUnknownAccountException();}//  return new SimpleAuthenticationInfo(用户名,密码,盐值,realm名字);//new Md5Hash(admin.getUsername()),System.out.println("权限:"+admin.getUsername()+"密码:"+admin.getPassword()+"realm:"+this.getName());returnnewSimpleAuthenticationInfo(admin.getUsername(),admin.getPassword(),this.getName());}}
复制代码
四、前端功能实现

1.static(前端静态资源显示)

电商订单后台管理系统-9.jpg

这里下载解压到webappp文件下面
链接:https://pan.baidu.com/s/1D_EFbLyAO_faeH6uVEQvJA?pwd=9uwv
提取码:9uwv
2.upoad(文件上传目录)

电商订单后台管理系统-10.jpg

在webapp文件下创建一个upload文件用于贮存我们上传的文件。
3.jsp(显示页面格式为:xxx.jsp)

电商订单后台管理系统-11.jpg


详细实现代码我这里就不写了
源代码就放在这里了。
链接:https://pan.baidu.com/s/1gS1p2XhJTyRY0vxCaBsYfQ?pwd=tzzk
提取码:tzzk

总结

提示:这里对文章停止总结:
有什么不懂,欢送各位评论留言
都看到这里了,请各位的发财小手手点个赞。谢谢!

回复

举报 使用道具

相关帖子
全部回复
暂无回帖,快来参与回复吧
本版积分规则 高级模式
B Color Image Link Quote Code Smilies

恋梦红尘
注册会员
主题 19
回复 23
粉丝 0
|网站地图
快速回复 返回顶部 返回列表