• play freamwork 框架中 调用线程保存数据


    package com.wanhua.thread;

    import models.Log;
    import play.db.jpa.JPAPlugin;

    /**
     * 保存用户操作日志的线程
     *
     * @author w_xfpenga 2014-12-18
     *
     */
    public class LogManagerThread extends Thread {

        private String content;// 日志内容
        private int type;// 日志类型:0为后台用户操作日志,1为移动用户操作日志
        private String operator;// 日志创建者
        private String path;// 操作路径,如:/users/delete/1

        /**
         * 构造函数初始化LogmanagerThread对象
         *
         * @param content
         * @param type
         * @param operator
         * @param path
         */
        public LogManagerThread(String content, int type, String operator, String path) {
            this.content = content;
            this.type = type;
            this.operator = operator;
            this.path = path;
        }

        /**
         * 重写线程中的run方法 将用户操作日志的保存到数据库中
         */
        @Override
        public void run() {
            String content = this.content;// 日志内容
            int type = this.type;// 日志类型:0为后台用户操作日志,1为移动用户操作日志
            String operator = this.operator;// 日志创建者
            String path = this.path;// 操作路径,如:/users/delete/1

            // 添加JPA环境
            JPAPlugin.startTx(false);
            // 保存用户到数据库
            Log.addLog(content, type, operator, path);
            JPAPlugin.closeTx(false);
        }
    }

    注意加上JPA环境:JPAPlugin.startTx(false);

  • 相关阅读:
    CentOS7突然出现无法连接网络的情况--VM下
    设置Linux系统的LANG变量
    习题
    Linux目录路径知识
    Linux目录详细介绍
    regexp正则
    https://github.com/rwson/awesome-javascript-cn
    JavaScript资源大全中文版(Awesome最新版)
    关于 Chrome DevTools 的 25 个实用技巧
    从前端菜鸟到大神,看这一篇就够了
  • 原文地址:https://www.cnblogs.com/xunfang123/p/4171293.html
Copyright © 2020-2023  润新知