传智健康[六]

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 关于传智健康的相关知识

(3). 新增套餐

  • ①. 关于文件上传各个参数的说明

20191020100847763.png

②. 什么是UUID?

    UUID 的十六个八位字节被表示为 32个十六进制数字,以连字号分隔的五组来显示,形式为 
8-4-4-4-12,总共有 36个字符(即三十二个英数字母和四个连字号)。例如:
123e4567-e89b-12d3-a456-426655440000
    UUID.randomUUID().toString()+extention;[extention为后缀名]
    (注意:这里的toString()是转成字符串类型)


③. 用elementUI 上传文件中,在人间上传成功后的钩子函数中response相当于response.data

20191020161853798.png

①. 新增

1. 新增

前台: 
   1.点击新建按钮,显示模态框,将套餐数据 | 图片url | 检查组中的数据清空 | 选项卡选中套餐,
发送ajax查询到检查组所有的数据,将查询出来的数据赋值给检查组中表单数据,并显示在页面
   2.点击新建按钮[表单进行验证],将套餐表单数据和检查组中复选框的id作为参数传递到后台.返回
结果[如果为true,则给出成功提示;否则给出失败提示],在返回结果中,要将模态框关闭      
   3.调用findPage方法重新查询页面数据
后台:
   1.controller: 将套餐表单数据和检查组复选框ids作为参数传递给service
   2.service:
      2.1 将套餐数据作为参数传递给dao,进行数据库新增
      注意:这里要拿到当前新增的id,要在insert中使用selectKey标签
      2.2 将套餐新增的id和复选框ids传入到dao,进行中间表数据的添加[重点掌握]
   3.dao Setmeal 和 中间表的新增   
上传图片并预览
       1.点击 + 号上传图片,action路径会访问controller
       2.将图片传入到七里云中[传入的参数是UUID后缀名]
       UUID:UUID.randomUUID().toString()+extention;
       extention:[
         String originalFilename = imgFile.getOriginalFilename();//原始文件名
         String extention=originalFilename.substring
         (originalFilename.lastIndexOf("."));
       ]
       3.要将传入七牛云的图片传入到redis中
       4.在返回时,要将上传到七牛云图片的名称返回给前台[在新增套餐时,有img这个属性]   
  • ①. 新增前台代码

步骤

效果图:

20191020104226541.png

20191020104235876.png

1.新建按钮绑定单击事件,对应的处理函数为handleCreate

2019102010430950.png

20191020104426199.png

2.点击新增按钮,触发点击事件

20191020104751739.png

  • ②.新增后台步骤

图片预览步骤:

1.前台

2019102010464973 (1).png

2.后台:

20191020104952824.png


注意:别忘了在spring配置文件中配置文件上传组件

20191020105126248.png

新增套餐:

1.controller:

20191020105145314.png

2.service

2019102010524790.png

3.dao:

20191020105300610.png

20191020105319964.png

②. 定时清理垃圾

20191020192658606.png

  • ①. 创建maven工程health_jobs,打包方式为war,导入Quartz等相关坐标
  <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>com.itheima</groupId>
            <artifactId>health_interface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <!-- 指定端口 -->
                    <port>83</port>
                    <!-- 请求路径 -->
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • ②. 配置web.xml
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <!-- 加载spring容器 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>
  • ③. 配置log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, stdout
  • ④. 配置applicationContext-redis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/mvc
                          http://www.springframework.org/schema/mvc/spring-mvc.xsd
                http://code.alibabatech.com/schema/dubbo
                          http://code.alibabatech.com/schema/dubbo/dubbo.xsd
                http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context.xsd">
    <!--Jedis连接池的相关配置-->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal">
            <value>200</value>
        </property>
        <property name="maxIdle">
            <value>50</value>
        </property>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
    </bean>
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="poolConfig" ref="jedisPoolConfig" />
        <constructor-arg name="host" value="127.0.0.1" />
        <constructor-arg name="port" value="6379" type="int" />
        <constructor-arg name="timeout" value="30000" type="int" />
    </bean>
</beans>


  • ⑤.配置applicationContext-jobs.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/mvc
              http://www.springframework.org/schema/mvc/spring-mvc.xsd
              http://code.alibabatech.com/schema/dubbo
              http://code.alibabatech.com/schema/dubbo/dubbo.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd">
    <!--开启spring注解使用-->
    <context:annotation-config></context:annotation-config>
    <!--注册自定义Job-->
    <bean id="clearImgJob" class="com.itheima.jobs.ClearImgJob"></bean>
    <bean id="jobDetail"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 注入目标对象 -->
        <property name="targetObject" ref="clearImgJob"/>
        <!-- 注入目标方法 -->
        <property name="targetMethod" value="clearImg"/>
    </bean>
    <!-- 注册一个触发器,指定任务触发的时间 -->
    <bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <!-- 注入JobDetail -->
        <property name="jobDetail" ref="jobDetail"/>
        <!-- 指定触发的时间,基于Cron表达式 -->
        <property name="cronExpression">
            <!--
            <value>0 0 2 * * ?</value>
            -->
            <value>0/10 * * * * ?</value>
        </property>
    </bean>
    <!-- 注册一个统一的调度工厂,通过这个调度工厂调度任务 -->
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!-- 注入多个触发器 -->
        <property name="triggers">
            <list>
                <ref bean="myTrigger"/>
            </list>
        </property>
    </bean>
</beans>
  • ⑥. 创建ClearImgJob定时任务类


package com.itheima.jobs;
import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;
import java.util.Set;
/*
 * 自定义Job,实现定时清理垃圾图片
 * */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
      //根据redis中保存的两个set集合进行差值计算,获取垃圾图片名称集合
        Set<String> set = jedisPool.getResource().sdiff
                (RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(set!=null){
            for (String picName : set) {
                //删除七牛云服务器上的图片
                QiniuUtils.deleteFileFromQiniu(picName);
                //从redis集合中删除集合名称
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picName);           
            }
        }
   }
}







相关文章
|
网络安全 数据安全/隐私保护 Windows
windows通过finalshell连接服务器
通过finnalshell连接服务器的流程
windows通过finalshell连接服务器
|
存储 弹性计算 固态存储
VMware虚拟机迁移到阿里云
各种架构的主机资源如何迁移上阿里云?本文以VMware虚拟机迁移到阿里云为例,介绍一些迁移上阿里云的方式。
VMware虚拟机迁移到阿里云
|
8月前
|
关系型数据库 MySQL 数据库连接
docker拉取MySQL后数据库连接失败解决方案
通过以上方法,可以解决Docker中拉取MySQL镜像后数据库连接失败的常见问题。关键步骤包括确保容器正确启动、配置正确的环境变量、合理设置网络和权限,以及检查主机防火墙设置等。通过逐步排查,可以快速定位并解决连接问题,确保MySQL服务的正常使用。
1341 82
|
缓存 Linux 开发工具
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
260482 0
|
弹性计算 小程序
阿里云免费学生服务器购买及续费指南
阿里云高效计划:学生用户可以免费领取一台阿里云服务器,未参与过高校学生免费领取ECS活动的用户,通过学生身份认证及续费任务,最多可领取1+6个月免费ECS资源。如果你想基于ECS搭建云上博客或者学习云服务器的搭建与维护,现在可以免费申请一台云服务器。阿里云的高校计划,面向学生用户提供免费的云服务器福利,通过学生身份认证及续费任务后,最多可领取7个月免费云服务器ECS资源。
阿里云免费学生服务器购买及续费指南
|
8月前
|
JavaScript 应用服务中间件 nginx
Vue项目部署:如何打包并上传至服务器进行部署?
以上就是Vue项目打包及部署的方法,希望对你有所帮助。描述中可能会有一些小疏漏,但基本流程应该没有问题。记住要根据你的实际情况调整对应的目录路径和服务器IP地址等信息。此外,实际操作时可能会遇到各种问题,解决问题的能力是每一位开发者必备的技能。祝你部署顺利!
1718 17
|
安全 Java 应用服务中间件
如何通过 Yum 在 CentOS 7 上安装 Apache Tomcat 7
如何通过 Yum 在 CentOS 7 上安装 Apache Tomcat 7
440 0
|
开发框架 Oracle Java
JDK8和JDK17安装切换,IDEA配置多个版本JDK
JDK8和JDK17安装切换,IDEA配置多个版本JDK
|
SQL Java 关系型数据库
在IDEA中配置MySQL数据库连接以及在使用mybatis时设置sql语句的代码提示功能
在IDEA中配置MySQL数据库连接以及在使用mybatis时设置sql语句的代码提示功能
|
存储 Java BI
传智健康项目中相关知识点介绍(如图片存储,发送短信,定时调度,统计报表...)(一)
传智健康项目中相关知识点介绍(如图片存储,发送短信,定时调度,统计报表...)
传智健康项目中相关知识点介绍(如图片存储,发送短信,定时调度,统计报表...)(一)