## 项目第十五天 ##


项目前端系统


搭建前端项目环境

1. 考入前端的系统页面
2. 打开MySQL的数据库,执行sql脚本,导入数据库的表结构
3. 导入JavaBean
4. 导入dao接口
5. 导入service和实现类
6. 导入BaseAction
7. 导入Spring的配置文件
8. 导入工具类

9. 启动服务器的时候出现了问题
    * 1. 把2个项目发布到Tomcat服务器中,2个项目的虚拟路径名称是一样,发布不成功。
    * 2. 启动Tomcat服务器的时候,会出现错误

注册功能的需求分析

1. 完成系统的用户注册功能
    * 需求分析

完成图片验证码的显示

1. 编写UserAction的类,完成图片验证码的显示
    package cn.itcast.client.action;

    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts2.ServletActionContext;
    import org.apache.struts2.convention.annotation.Namespace;

    import com.opensymphony.xwork2.ModelDriven;

    import cn.itcast.client.domain.UserClient;
    import cn.itcast.utils.ImageUtil;

    /**
     * 前端用户模块
     * @author Administrator
     */
    @Namespace("/")
    public class UserAction extends BaseAction implements ModelDriven<UserClient>{

        private UserClient model = new UserClient();

        public UserClient getModel() {
            return model;
        }

        /**
         * 生成验证码的方法
         * @return
         * @throws Exception
         */
        @Action(value="userAction_genActiveCode")
        public void genActiveCode() throws Exception {
            // 生成随机的字母数字字符串
            String imageCode = ImageUtil.getRundomStr();
            // 把生产的验证码存入到session,一会做校验
            ServletActionContext.getRequest().getSession().setAttribute("imageCode", imageCode);
            // 获取到response对象
            HttpServletResponse response = ServletActionContext.getResponse();
            // 把生成的验证码使用response响应出去
            ImageUtil.getImage(imageCode, response.getOutputStream());
        }

    }

获取手机验证码功能

1. 前端页面手机号验证的js概述
2. 在ee66_client_web项目中编写程序。当用户点击获取验证码按钮后,程序应该立即向ActiveMQ的消息队列中发送一条消息,等待后台去处理。
    * 先注入JmsTemplate模板对象
        @Resource(name="jmsQueueTemplate")
        private JmsTemplate jmsQueueTemplate;

    * 编写发送消息的方法
        /**
         * 用户点击获取验证码,向消息队列发送一条消息
         * @throws Exception
         */
        @Action(value="userAction_sendVerCode")
        public void sendVerCode()throws Exception {
            // 发送消息
            jmsQueueTemplate.send("hello_sms", new MessageCreator() {
                public Message createMessage(Session session) throws JMSException {
                    // 创建消息,存入信息
                    MapMessage message = session.createMapMessage();
                    message.setString("telephone", model.getTelephone());
                    return message;
                }
            });
        }

3. 在ee66_jms项目中编写消息监听器,监听短信的消息,准备发送短信的代码。
    * 先在web.xml配置文件中添加监听器的配置
        <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:applicationContext-mq-listener.xml</param-value>
        </context-param>

    * 因为在jms的项目中需要使用ee66_cache项目中的RedisTemplate对象,所以需要完成依赖注入,有如下3步
        * 开启注解扫描:<context:component-scan base-package="cn.itcast"/>
        * 引入缓存的配置文件:<import resource="classpath:applicationContext-redis.xml"/>
        * 使用注解的方式注入RedisTemplate对象

    * 具体的代码如下
        package cn.itcast.jms.listener;

        import java.util.concurrent.TimeUnit;

        import javax.jms.MapMessage;
        import javax.jms.Message;
        import javax.jms.MessageListener;

        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.data.redis.core.RedisTemplate;

        import cn.itcast.utils.RandomCode;
        import cn.itcast.utils.SmsUtils;

        /**
         * 处理手机发短信的监听器
         * @author Administrator
         */
        public class SmsClientListener implements MessageListener{

            // 如果想存入redis的缓存中,需要注入redisTemplate对象
            @Autowired
            private RedisTemplate<String, String> redisTemplate;

            public void onMessage(Message msg) {
                MapMessage message = (MapMessage) msg;
                try {
                    // 从消息队列获取到消息
                    String telephone = message.getString("telephone");
                    // 生成验证码
                    String code = RandomCode.genCode()+"";

                    // 存入到redis的缓存中,默认存储30分钟,过时间会清除掉
                    redisTemplate.opsForValue().set(telephone, code,30,TimeUnit.MINUTES);
                    System.out.println("手机号:"+telephone);
                    System.out.println("验证码:"+code);

                    // 发送手机短信
                    SmsUtils.sendSms(telephone, code);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

用户的注册功能

1. 先注入redisTemplate
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

2. 再注入UserClientService
    @Autowired
     UserClientService userClientService;

3. 具体的代码如下
    /**
     * 用户的注册功能的编写
     */
    @Action(value="userAction_register")
    public String register() throws Exception {
        String result = "2";
        // 验证码校验
        String imageCode = (String) ServletActionContext.getRequest().getSession().getAttribute("imageCode");
        if(!vercode.equals(imageCode)){
            // 说明,不正确,不能注册
            result = "0";
            return NONE;
        }

        // 手机验证码校验
        // 先从redis中获取到手机验证码
        String code = redisTemplate.opsForValue().get(model.getTelephone());
        if(!phoneVercode.equals(code)){
            result = "1";
            return NONE;
        }

        // 注册用户
        userClientService.saveOrUpdate(model);

        // 清除一些缓存
        // 从session清除验证码
        ServletActionContext.getRequest().getSession().removeAttribute("imageCode");
        // 从redis清除手机验证码
        redisTemplate.delete(model.getTelephone());

        HttpServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("UTF-8");
        response.getWriter().print(result);
        return NONE;
    }

    private String vercode;
    private String phoneVercode;
    public String getVercode() {
        return vercode;
    }
    public void setVercode(String vercode) {
        this.vercode = vercode;
    }
    public String getPhoneVercode() {
        return phoneVercode;
    }
    public void setPhoneVercode(String phoneVercode) {
        this.phoneVercode = phoneVercode;
    }

项目实战需求分析


准备实现环境

1. 组长负责把一份运行完好的、符合命名规范的代码上传到SVN服务器上去,其他组员把代码检出到本地。
    * 拿一台主机服务器,主机服务器上安装了SVN软件、安装了Oracle数据库,以后大家编写代码上传到SVN服务器上,连接的是服务器的Oracle数据库。
    * Oracle数据库上可能没有数据库表结构,组长负责找人创建表,导入数据等。

出口报运单模块

1. 出口报运单的打印功能。(可选项)
    * 使用了POI报表技术

装箱单模块需求

1. 装箱单与报运单是一对多的关系,但是数据库的设计采用的是打断设计(没有主外键关联,装箱单中有报运单的id集合,默认使用逗号隔开)
2. 再做装箱单的新增的时候,提供报运单的选项,保存装箱单操作。

委托单模块需求

1. 委托单与装箱单是一对一的关系

发票管理模块需求

1. 发票也称为催款管理,海外客户根据提单提取了货物,咱们需要发出催款通知单
2. 发票和委托单是一对一的关系

财务报运单

1. 财务报运单核发票管理是一对一的关系

生成厂家和系统代码模块

1. 单表来完成

记录登录的日志模块

1. 需求:现在我的代码已经编写完成了,希望不要修改源代码,把功能加上!!
    * Spring的AOP技术来完成(要求)
    * 提示:使用Spring的AOP的注解的方式对Action增强!!

系统扩展模块


SVN提交和下载代码

1. https://W7X64-20161009R:8443/svn/jk51/

2. 每个人都需要做,如果不做,谁不做谁是小狗!!
    * 提交代码的时候要注意,把一些不需要提交的内容过滤掉
    * Window -- prefrences -- team -- Ignored Resource -- Add Pattern -- 添加过滤的内容(.settings .project .classpath .class target文件夹)

3. SVN的代码下载
    * 下载的是jk231_parent项目,右键 -- import -- 选择maven -- 选择Existing Maven Project -- next -- finsh

猜你喜欢

转载自blog.csdn.net/qq_32332777/article/details/79004158