fastsql详情
Java None
更新时间:2018-11-14T01:45:39Z

fastsql

fastsql 是一个数据库访问框架

Maven依赖



<dependency>

    <groupId>org.fastsql</groupId>

    <artifactId>fastsql</artifactId>

    <version>1.0</version>

</dependency>


范例

public interface UserDao {

     @Select("select *,age as 123age from user where auto_id=#{userId} and local=#{local}")
     public User findOne(@Param("userId") Long userId, @Param("remark") String remark, @Param("local") int local);

     @Select("select * from user")
     public ArrayList selectAll();

 }

使用UserDao进行查询

public class QueryTest {

public static void main(String[] args) throws NoSuchMethodException, SQLException {

    //定义工厂
    DefaultObjectFactory factory = new DefaultObjectFactory();
    //设置数据源
    factory.setDataSource(getDataSource());
    //从工厂获取dao实例
    UserDao userDao= factory.getBean(UserDao.class);

    //执行查询,返回单个对象
    User user= userDao.findOne( 1l, "222",1);
    System.out.println(user);

    //返回集合
    List<User> userList = userDao.selectAll();
    System.out.println(userList);
}

public static DataSource getDataSource() throws SQLException {
    //测试使用alibaba druid数据源
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
    dataSource.setUsername("root");
    dataSource.setPassword("123456");

    dataSource.setInitialSize(10);
    dataSource.setMaxActive(20);

    dataSource.init();

    return dataSource;
}

}

返回类型支持 8个基础、String、Set、List、Map 默认: Set=HashSet List=ArrayList Map=LinkedHashMap

Set和List 不指定泛型,默认为Set>和List>

评论
登录以后才可以发布评论哦, 点击登录 发布评论
评论列表 0人参与,0条评论
暂时还没有人评论,快来一条神回复吧!