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

以文章管理为例。

文章表结构设计

代码

1

2

3

4

5:

<?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部署

退出虚拟机
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/