心通达OA便签模块后台开发说明

心通达OA便签模块后台开发说明

本篇文章以新建便签,插入数据为例,加以说明
1、打开便签视图
返回视图时,方法的返回值为访问视图路径。

    @Controller
    @RequestMapping("/Notes")
    ......
    @RequestMapping("/index")
    public String Notes() {
        return "app/notes/index";
    }

添加便签
2、Controller层代码

    @RequestMapping("/insertNotes")
    @ResponseBody
    public ToJson<Notes> insertNotes(Notes notes, HttpServletRequest request){
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        return notesService.insertNotes(notes,user);
    }

返回json格式数据时,需要在方法上添加@ResponseBody注解,同时系统内置了ToJson,BaseWrapper两种工具类。具体使用请查看类定义。

3、dao层代码

@Component
public interface NotesMapper {
    int insertNotes(Notes notes);
    List<Notes> selectNotes(Integer uid);
}

数据访问层,不需要自己去写实现类,系统会根据mapper文件自动实现,注意接口类具有的方法必须在mapper文件中有对应的statement,并且返回值类型一致。

4、mapper层代码
namespace应该设置为对应dao层的接口类。例如NotesMapper的namespace为com.xoa.dao.notes.NotesMapper。

<mapper namespace="com.xoa.dao.notes.NotesMapper">
    <resultMap id="BaseResultMap" type="com.xoa.model.notes.Notes">
        <result column="NOTE_ID" property="noteId" javaType="int"/>
        <result column="UID" property="uid" javaType="int"/>
        <result column="CONTENT" property="content" javaType="string"/>
        <result column="COLOR" property="color" javaType="string"/>
        <result column="SHOW_FLAG" property="showFlag" javaType="string"/>
        <result column="CREATE_TIME" property="createTime" javaType="int"/>
        <result column="EDIT_TIME" property="editTime" javaType="int"/>
    </resultMap>
    <resultMap id="UserResultMap" type="com.xoa.model.users.Users">
        <id column="UID" property="uid" javaType="int"/>
        <result column="USER_ID" property="userId" javaType="string"/>
        <result column="USER_NAME" property="userName" javaType="string"/>
        <result column="DEPT_ID" property="deptId" javaType="int"/>
        <result column="DEPT_ID_OTHER" property="deptIdOther" javaType="string"/>
    </resultMap>
    <insert id="insertNotes" parameterType="com.xoa.model.notes.Notes">
         insert into notes
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noteId != null">
                NOTE_ID,
            </if>
            <if test="uid != null">
                UID,
            </if>
            <if test="content != null">
                CONTENT,
            </if>
            <if test="color != null">
                COLOR,
            </if>
            <if test="showFlag != null">
                SHOW_FLAG,
            </if>
            <if test="createTime != null">
                CREATE_TIME,
            </if>
            <if test="editTime != null">
                EDIT_TIME,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="noteId != null">
                #{noteId,jdbcType=INTEGER},
            </if>
            <if test="uid != null">
                #{uid,jdbcType=INTEGER},
            </if>
            <if test="content != null">
                #{content,jdbcType=VARCHAR},
            </if>
            <if test="color != null">
                #{color,jdbcType=TINYINT},
            </if>
            <if test="showFlag != null">
                #{showFlag,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=INTEGER},
            </if>
            <if test="editTime != null">
                #{editTime,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>

5、model层代码
实体类,应注意和数据库字段类型对应

public class Notes {
    private Integer noteId;// 主键
    private Integer uid;//所属用户UID
    private String content;//便签内容
    private String color;//便签颜色
    private String showFlag;//OA精灵固定显示标记(0-不显示,1-第一次显示,2-始终显示)
    private Integer createTime;//创建时间
    private Integer editTime;//最后修改时间
    public Integer getNoteId() {
        return noteId;
    }
    public void setNoteId(Integer noteId) {
        this.noteId = noteId;
    }
    public Integer getUid() {
        return uid;
    }
    public void setUid(Integer uid) {
        this.uid = uid;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getShowFlag() {
        return showFlag;
    }
    public void setShowFlag(String showFlag) {
        this.showFlag = showFlag;
    }
    public Integer getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Integer createTime) {
        this.createTime = createTime;
    }
    public Integer getEditTime() {
        return editTime;
    }
    public void setEditTime(Integer editTime) {
        this.editTime = editTime;
    }
}

#service层代码
业务层,逻辑的实现

public interface NotesService {
    public ToJson<Notes> insertNotes(Notes notes, Users user);
}

@Service
public class NotesServiceImpl implements NotesService{
    @Override
    public ToJson<Notes> insertNotes(Notes notes, Users user){
        ToJson<Notes> json = new ToJson<Notes>();
        try {
            int uId = user.getUid();
            notes.setUid(uId);
            String currentTime = String.valueOf(new Date().getTime()/1000);
            int time =Integer.valueOf(currentTime);
            //Integer createTime = IntCreateTime;
            notes.setCreateTime(time);
            notes.setEditTime(time);
            notes.setShowFlag("1");
            notesMapper.insertNotes(notes);
            json.setFlag(0);
            json.setMsg("ok");
          }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg("err");
        }
        return json;
    }
}

至此,心通达OA便签模块后台代码开发思路和主要代码完成。

附:数据表

CREATE TABLE `notes` (
  `NOTE_ID` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '便签ID',
  `UID` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所属用户UID',
  `CONTENT` text NOT NULL COMMENT '便签内容',
  `COLOR` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '便签颜色',
  `SHOW_FLAG` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'OA精灵固定显示标记(0-不显示,1-第一次显示,2-始终显示)',
  `CREATE_TIME` int(10) unsigned NOT NULL COMMENT '创建时间',
  `EDIT_TIME` int(10) unsigned NOT NULL COMMENT '最后修改时间',
  PRIMARY KEY (`NOTE_ID`) USING BTREE,
  KEY `UID` (`UID`) USING BTREE,
  KEY `CREATE_TIME` (`CREATE_TIME`) USING BTREE,
  KEY `EDIT_TIME` (`EDIT_TIME`) USING BTREE
) ENGINE=InnoDB ROW_FORMAT=COMPACT COMMENT='便签表';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人人献出爱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值