JDBC持久层框架 ExpressPersist
本文导语: Express-Persist 是 ExpressMe 建站系统所用的 JDBC 持久层框架,目标是封装JDBC并提 供简单的数据库操作接口。 示例代码: public interface UserDao { @Unique @MappedBy(UserRowMapper.class) @Query("select * from User u where u.id=:id") User que...
Express-Persist 是 ExpressMe 建站系统所用的 JDBC 持久层框架,目标是封装JDBC并提 供简单的数据库操作接口。
示例代码:
public interface UserDao {
@Unique
@MappedBy(UserRowMapper.class)
@Query("select * from User u where u.id=:id")
User queryUser(@Param("id") String id);
@MappedBy(UserRowMapper.class)
@Query("select * from User u order by u.name desc")
List queryUsers(@FirstResult int first, @MaxResults int max);
@Update("insert into User(id, password, name) values(:u.id, :u.password, :u.name)")
void createUser(@Param("u") User user);
@Update("update User set password=:u.password, name=:u.name where id=:u.id")
void updateUser(@Param("u") User user);
}
UserDao dao = createUserDao(); // discuss later
User u1 = new User("id-12345", "password", "Michael");
dao.createUser(u1);
User u2 = queryUser("abc1234");
u2.setName("Michael Liao");
u2.setPassword("abcdefg");
dao.updateUser(u2);