Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xcaffebabe/orm
一个简单ORM框架实现
https://github.com/0xcaffebabe/orm
Last synced: about 1 month ago
JSON representation
一个简单ORM框架实现
- Host: GitHub
- URL: https://github.com/0xcaffebabe/orm
- Owner: 0xcaffebabe
- Created: 2019-02-01T05:20:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-06T10:44:55.000Z (almost 3 years ago)
- Last Synced: 2024-10-16T00:43:49.230Z (3 months ago)
- Language: Java
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# orm
2019-2-1根据个人对ORM框架理解的一个简单实现
#
2019-2-6###第一个应用:
定义接口:
```java
public interface EntityRepository {@Select(value = "SELECT * FROM entity",entity = Entity.class)
List selectAll();@Update(value = "UPDATE entity SET name = 'java' WHERE name = ?")
int updateByName(String name);@Delete("DELETE FROM entity WHERE name = ?")
int deleteByName(String name);@Insert(value = "INSERT INTO entity(name) VALUES(?)",entity = Entity.class)
int insert(String name);
}
```使用:
```java
public class MyRepositoryFactoryTest {@Test
public void getRepositoryAgent() {
// 设置数据源
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUsername("root");
dataSource.setPassword("123456");
dataSource.setUrl("jdbc:mysql:///orm?serverTimezone=Hongkong");// 创建仓库工厂
MyRepositoryFactory factory = new MyRepositoryFactory(dataSource);
// 通过工厂获取仓库代理类
EntityRepository repository = factory.getRepositoryAgent(EntityRepository.class);
assertEquals(1,repository.insert("kkk"));
assertEquals(2,repository.selectAll().size());
}
}
```