基于 Spring-JDBC 的简易 ORM 框架(支持多数据源) simple-orm

码农软件 · 软件分类 · ORM/持久层框架 · 2019-09-22 22:43:13

软件介绍

基于 Spring-JDBC 和 javax.persistence 注解的简易 ORM 的封装。支持多数据源,通过简单的常规的 Spring 的配置就可以轻松实现,对代码无侵入。

//定义数据映射实体类
@Table(name="sys_user") // 设置对应的表名
@TargetDataSource(name="hueDataSource") //如果需要支持多数据源,添加此注解
public class SysUser implements Serializable {
    
    @Id //设置为主键值
    @Column(name="id") //设置数据库中对应的字段名
    private Long userId;

    @Column(name="status") // 设置数据库中对应的字段名
    private boolean status;
    
    @Column(name="user_name")
    private String userName;
    
    @OrderBy(value="DESC") //设置默认的排序字段,在查询时如果没有设置就按默认的排序方式查询;
    @Column(name="create_date")
    private Date createDate;

    @Column(name="sex")
    @Enumerated(EnumType.ORDINAL) //此处为枚举属性;@Enumerated(EnumType.STRING):以枚举的名称存储;@Enumerated(EnumType.ORDINAL):以枚举的ORDINAL存储;(如果不写默认按名称存储)
    private Sex sex;
}
//定义DAO操作

@Repository //通过spring注解自动加载到 bean 容器中
public class SysUserDao extends BaseDaoAdapter<SysUser>{
    // 实现对当前dao操作的扩展
   //根据名称模糊查询(样例)
   public List<SysUser> like(String name) throws SQLException {
      return getQuery().likeProperty("userName", "hao").list();
   }

    // 更新用户名称
    public Integer updateUserName(String userName,int userId) throws SQLException {
	return getUpdater().equalProperty("userId", userId).setProperty("userName", userName).update();
    }

}

详情可参考 https://gitee.com/haopeng/simple-orm

本文地址:https://www.codercto.com/soft/d/15191.html

Developing Large Web Applications

Developing Large Web Applications

Kyle Loudon / Yahoo Press / 2010-3-15 / USD 34.99

As web applications grow, so do the challenges. These applications need to live up to demanding performance requirements, and be reliable around the clock every day of the year. And they need to withs......一起来看看 《Developing Large Web Applications》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具