什么是事务

事务是一个不可分割的工作单位,事务中包括的诸操作要么都做,要么都不做。事务可大可小,在关系数据库中,一个事务可以是一条SQL语句,一组SQL语句或整个程序。

技术背景

RuoYi-vue 前后端分离

举个例子:

订单表和订单详情表进行插入操作。

出现的问题

ps:如何查看失败的原因: 日志

插入订单表成功 但是插入订单详情表失败

解决方案:

做法非常简单,我们只需要在方法或类添加@Transactional注解即可,下面方法位于OrderService.

@Transactional
public int insertOrder(Order order)
{
    // 新增订单信息
    int rows = orderMapper.insertOrder(order);
    
    // 新增用户与订单详情
    insertOrderItem(order);
    return rows;
}

参考

https://blog.csdn.net/u012102536/article/details/123485318
http://doc.ruoyi.vip/ruoyi/document/htsc.html#%E4%BA%8B%E5%8A%A1%E7%AE%A1%E7%90%86

element ui 表单操作

1.日期选择器

date.png

例子:

   <el-date-picker
      v-model="dateRange"
      size="small"
      style="width: 240px"
      value-format="yyyy-MM-dd"
      type="daterange"
      range-separator="-"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
    ></el-date-picker>
   设置默认日期:dateRange: [this.getNowTime(new Date() - 86400000 *10), this.getNowTime(new Date())],
    getNowTime(temp) {
        var now = new Date(temp);
        var year = now.getFullYear();     //得到年份
        var month = now.getMonth() + 1; //得到月份
        var date = now.getDate();         //得到日期
        month = month.toString().padStart(2, "0");
        date = date.toString().padStart(2, "0");
        return `${year}-${month}-${date}`;
      },

2.复选框和单选框

3.下拉选择框


<el-form-item label="类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择类型(支出/收入/收款/付款/转账)">
                <el-option
                  v-for="dict in typeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
</el-form-item>
//设置默认值   
 created() {
    // 如果你想设置一个默认值,可以在组件创建时赋值
    this.form.selectedOption = this.options[0].value; // 设置默认选中第一个选项
  },

按钮

radio.png

 
  <el-form-item label="是否默认">
          <el-radio-group v-model="form.isDefault">
            <el-radio
              v-for="dict in isDefaultOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
  </el-form-item>

js:

this.getDicts("isDefault").then(response => {
  console.log("11111111"+response.data);
  this.isDefaultOptions = response.data;

});

element | el-input 绑定点击事件

@click.native

table行编辑事件

:@row-click

<el-table :data="yshopPurchaseOrderItemsList" @row-click="selectGoods" :row-class-name="rowYshopPurchaseOrderItemsIndex" @selection-change="handleYshopPurchaseOrderItemsSelectionChange" ref="yshopPurchaseOrderItems">

      <el-table-column type="selection" width="50" align="center" />

</el-table>

table 新增行 弹窗事件

参考文档:https://juejin.cn/post/7040046051306242085

https://blog.csdn.net/lh1144151563/article/details/122601746

mybatis系列教程:单表数据操作

以文章列表为例。

文章表结构设计

id :编号
article_title :标题
article_content :内容
article_type :文章类型
................:略了几个字段
代码

1:Controller

1.1 查询 List<DrArticles> list = drArticlesService.selectDrArticlesList(drArticles);

2:Bean

@Data
public class DrArticles extends BaseEntity
{
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String articleTitle;
    private String articleType;
    private String articleContent;
    private String createNickname;
}

3:Service

4:Mapper

5:mybatis xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.system.mapper.DrArticlesMapper">
    
    <resultMap type="DrArticles" id="DrArticlesResult">
        <result property="id"    column="id"    />
        <result property="articleTitle"    column="article_title"    />
        <result property="articleType"    column="article_type"    />
        <result property="articleContent"    column="article_content"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="createNickname"    column="create_nickname"    />
    </resultMap>

    <sql id="selectDrArticlesVo">
        select id, article_title, article_type, article_content, create_by, create_time, update_by, update_time, remark, create_nickname from dr_articles
    </sql>

    <select id="selectDrArticlesList" parameterType="DrArticles" resultMap="DrArticlesResult">
        <include refid="selectDrArticlesVo"/>
        <where>  
            <if test="articleTitle != null  and articleTitle != ''"> and article_title = #{articleTitle}</if>
            <if test="articleType != null  and articleType != ''"> and article_type = #{articleType}</if>
            <if test="articleContent != null  and articleContent != ''"> and article_content = #{articleContent}</if>
            <if test="createNickname != null  and createNickname != ''"> and create_nickname like concat('%', #{createNickname}, '%')</if>
        </where>
    </select>
    <select id="selectDrArticlesById" parameterType="Integer" resultMap="DrArticlesResult">
        <include refid="selectDrArticlesVo"/>
        where id = #{id}
    </select>  
    <insert id="insertDrArticles" parameterType="DrArticles" useGeneratedKeys="true" keyProperty="id">
        insert into dr_articles
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="articleTitle != null">article_title,</if>
            <if test="articleType != null">article_type,</if>
            <if test="articleContent != null">article_content,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="createNickname != null">create_nickname,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="articleTitle != null">#{articleTitle},</if>
            <if test="articleType != null">#{articleType},</if>
            <if test="articleContent != null">#{articleContent},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createNickname != null">#{createNickname},</if>
         </trim>
    </insert>
    <update id="updateDrArticles" parameterType="DrArticles">
        update dr_articles
        <trim prefix="SET" suffixOverrides=",">
            <if test="articleTitle != null">article_title = #{articleTitle},</if>
            <if test="articleType != null">article_type = #{articleType},</if>
            <if test="articleContent != null">article_content = #{articleContent},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createNickname != null">create_nickname = #{createNickname},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDrArticlesById" parameterType="Integer">
        delete from dr_articles where id = #{id}
    </delete>

    <delete id="deleteDrArticlesByIds" parameterType="String">
        delete from dr_articles where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>

PYTHON项目PYCHARM+VIRTUALENV 本地调试+LINUX部署
背景
tensorflow(tf)是一个十分流行的python机器学习库,你现在手里有两个tf项目,其中项目A需要使用python2.7 + f1.2,项目B需要使用python2.7 + tf1.6.这两个项目你得同时进行,怎么办?

愚蠢的办法是需要运行项目A时,将python2.7中的tf1.6卸载掉,安装tf1.2;需要运行项目B时,将python2.7中的tf1.2卸载掉,安装tf1.6。如果是单个模块还好,但是tf的不同版本又依赖于python中的其他已安装模块,而且tf1.2和tf1.6对依赖模块有不同的版本要求,那么转换一次得卸载安装好几个模块,是不是很爆炸?

背景2:
课题组里几个同门共用一台服务器,每个人拥有一个系统账户,其中只有一个人拥有root权限,里面每个人都需要使用python跑程序,而且每个人对python版本以及python模块的版本都有不同需求,很多人又没有root权限,如何解决?

退出虚拟机
deactivate

服务器上安装virtualenv
# python3 的 pip3
pip3 install virtualenv
# 创建环境ENV
virtualenv ENV
cd ENV
# 启用此环境,后续命令行前面出现(ENV)代表此时环境已切换,
source ./bin/activate
# 之后执行pip python3 等指令,相当于是在此环境中执行
pip3 install -r /opt/flask2/requirements.txt
# 此时看到依赖已安装,
pip3 list
# 运行,
python3 /opt/flask2/flask2.py

参考文档:https://www.freesion.com/article/5681317327/