第五篇: Model 类增删改查及分页案例详解

CRUD 方法案例

一:生成实体类继承Model类,具体可参考第三篇sql-puls 代码生成。

以SysUser类为实例

package com.qiaoyatao.demo.model;

import com.qiaoyatao.sqlplus.annotation.model.ID;
import com.qiaoyatao.sqlplus.plus.Model;
import lombok.Data;

//@author: 王小扣
//@date: 2020-01-02 15:39:46
@Data
public class SysUser extends Model {

    //id
    @ID
    private Integer uid;

    //用户名
    private String userName;

    //名称
    private String name;

    //密码
    private String password;

    private String salt;

    //状态0-正常1-删除
    private Integer stauts;

}
UserDetailVO响应实体VO
package com.qiaoyatao.demo.vo;

import lombok.Data;

@Data
public class UserDetailVO {

    //id
    private Integer uid;

    //用户名
    private String userName;

    //名称
    private String name;

    //密码
    private String password;

}

对应表结构

CREATE TABLE `sys_user` (
  `uid` int(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `user_name` varchar(20) DEFAULT NULL COMMENT '用户名',
  `name` varchar(20) DEFAULT NULL COMMENT '名称',
  `password` varchar(50) DEFAULT NULL COMMENT '密码',
  `salt` char(50) DEFAULT NULL,
  `stauts` tinyint(20) DEFAULT '0' COMMENT '状态0-正常1-删除',
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

insert

 SysUser user = new SysUser();
        user.setName("王小扣");
        user.setPassword("admin");
        user.setSalt("盐");
        user.setStauts(0);
//        user.insert();//插入一条
        SysUser.insertList(user,user);//插入多条可以为不同类型
        SysUser.insertList(Arrays.asList(user,user));//插入多条
 

selectByid

 SysUser user = new SysUser();
        user.setUid(1);
        SysUser user1 = user.selectByid();
        UserDetailVO vo = user.selectByid(UserDetailVO.class);
        SysUser user2 = new SysUser().selectByid(2);
        UserDetailVO vo1 = user.selectByid(3, UserDetailVO.class);

selectOne

 SysUser user = new SysUser();
        user.setUid(1);
        user.setName("王小扣");
        //查询一条
        SysUser user1 = user.selectOne();
        //查询一条
        UserDetailVO vo = user.selectOne(UserDetailVO.class);
        //查询一条
        SysUser user2 = new SysUser().selectOne(vo,SysUser.class);
        //关键词查询一条
        Find find = new Find();
        find.eq("user_name","王小扣");
        SysUser user3 = new SysUser().selectOne(find);
        //关键词查询一条
        UserDetailVO vo1 = new SysUser().selectone(find, UserDetailVO.class);

selectList

SysUser user = new SysUser();
        user.setUid(1);
        user.setName("王小扣");
        //查询list
        List list = user.selectList();
        //查询list返回
        List list1 = user.selectList(UserDetailVO.class);
        //查询list返回
        UserDetailVO vo = new UserDetailVO();
        vo.setName("王小扣");
        List list2 = new SysUser().selectList(vo, UserDetailVO.class);
        List list3 = new SysUser().selectList(vo);
        //查询list返回
        Find find = new Find();
        find.eq("user_name","王小扣");
        List list4 = new SysUser().selectList(find);
        List list5 = new SysUser().selectList(find,UserDetailVO.class);

        UserDetailVO vo1 = user.copyTo(UserDetailVO.class);

        UserDetailVO vo2 = new UserDetailVO();
        user.copyTo(vo2);

        SysUser user1 = new SysUser();
        user1.copyBean(vo2);

        System.out.println(user1);
        System.out.println(vo2);

 

你可能感兴趣的:(sql-plus官方文档)