大家的项目中不可避免的使用到SQLite,为此我们要花费心思编写一个增删改查框架。而一个好的ORM框架则能够给我们带来极大的方便,今天给大家讲解一个非常火热的ORM-GreenDao。

基本概念

GreenDao官网地址:http://greenrobot.org/greendao/

官网对GreenDao的介绍:

greenDAO is an open source library for Android providing an easy-to-use interface to SQLite to help developers handle data efficiently – relieving developers from dealing with low-level database stuff and saving development time. SQLite is an awesome embedded relational database. Still, writing SQL and parsing query results are quite tedious and time-consuming tasks. greenDAO frees you from these by mapping Java objects to database tables (often called ORM). This way you can store, update, delete, and query for Java objects using a simple object oriented API.

简单的说就是:greenDAO 是一个将对象映射到 SQLite 数据库中的轻量且快速的 ORM 解决方案。

greenDAO 设计的主要目标

  • 一个精简的库
  • 性能最大化
  • 内存开销最小化
  • 易于使用的 APIs
  • 对 Android 进行高度优化

greenDAO 设计的主要特点

  • greenDAO 性能远远高于同类的 ORMLite,具体测试结果可见官网
  • greenDAO 支持 protocol buffer(protobuf) 协议数据的直接存储,如果你通过 protobuf
    协议与服务器交互,将不需要任何的映射。
  • 与 ORMLite 等使用注解方式的 ORM 框架不同,greenDAO 使用「Code
    generation」的方式,这也是其性能能大幅提升的原因。

Dao项目代码生成

DaoMaster:一看名字就知道它是Dao中的最大的官了。它保存了sqlitedatebase对象以及操作DAO classes(注意:不是对象)。其提供了一些创建和删除table的静态方法,其内部类OpenHelper和DevOpenHelper实现了SQLiteOpenHelper并创建数据库的框架。
DaoSession:会话层。操作具体的DAO对象(注意:是对象),比如各种getter方法。
XXXDao:实际生成的某某DAO类,通常对应具体的java类,比如NoteDao等。其有更多的权限和方法来操作数据库元素。
XXXEntity:持久的实体对象。通常代表了一个数据库row的标准java properties。

了解了基本概念后我们开始动手完成一个增删改查的项目案例。

实现过程

1.在 Android 工程中配置「greenDao Generator」模块

在 .src/main 目录下新建一个与 java 同层级的「java-gen」目录,用于存放由 greenDAO 生成的 Bean、DAO、DaoMaster、DaoSession 等类。

配置 Android 工程(app)的 build.gradle,如图分别添加 sourceSets 与 dependencies

 sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java-gen']
}
}
 compile 'de.greenrobot:greendao:1.3.7'

2.新建「greenDAO Generator」模块 (纯 Java 工程)

通过 File -> New -> New Module -> Java Library -> 填写相应的包名与类名 -> Finish

配置 castielgreendaolb 工程的 build.gradle,添加 dependencie

注意主句话,配置输出路径

 def outputDir = "../app/src/main/java-gen"

接着,编写 CastielGreenDao类,注意: 我们的 Java 工程只有一个类,它的内容决定了「GreenDao Generator」的输出,你可以在这个类中通过对象、关系等创建数据库结构,下面我将以注释的形式详细讲解代码内容。

 package com.castiel.dao;

 import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema; public class CastielGreenDao {
public static void main(String args[]) throws Exception {
// 创建了一个用于添加实体(Entity)的模式(Schema)对象。
// 两个参数分别代表:数据库版本号与自动生成代码的包路径。
Schema schema = new Schema(1, "greendao");
schema.setDefaultJavaPackageDao("com.castiel.dao"); // 一旦你拥有了一个 Schema 对象后,你便可以使用它添加实体(Entities)了。
addNote(schema); // 最后我们将使用 DAOGenerator 类的 generateAll() 方法自动生成代码,此处你需要根据自己的情况更改输出目录(既之前创建的 java-gen)。
new DaoGenerator().generateAll(schema, args[0]);
} /** * @param schema */
private static void addNote(Schema schema) {
// 一个实体(类)就关联到数据库中的一张表,此处表名为「Student」(既类名)
Entity note = schema.addEntity("Student");
// 你也可以重新给表命名
// note.setTableName("Student2"); // greenDAO 会自动根据实体类的属性值来创建表字段,并赋予默认值
// 接下来你便可以设置表中的字段:
// 与在 Java 中使用驼峰命名法不同,默认数据库中的命名是使用大写和下划线来分割单词的。
note.addIdProperty();
note.addStringProperty("sName").notNull();
note.addStringProperty("sAge");
note.addStringProperty("sSex");
note.addStringProperty("sClass");
}
}

3.生成 DAO 文件(数据库)

执行 generator 工程,如一切正常,你将会在控制台看到如下日志,并且在主工程「java-gen」下会发现生成了DaoMaster、DaoSession、StudentDao、Student共4个类文件。

 greenDAO Generator
Copyright 2011-2013 Markus Junginger, greenrobot.de. Licensed under GPL V3.
This program comes with ABSOLUTELY NO WARRANTY
Processing schema version 1...
Written C:\Users\huangshuai\AndroidStudioProjects\CastielGreenDao\app\src\main\java-gen\com\castiel\dao\StudentDao.java
Written C:\Users\huangshuai\AndroidStudioProjects\CastielGreenDao\app\src\main\java-gen\greendao\Student.java
Written C:\Users\huangshuai\AndroidStudioProjects\CastielGreenDao\app\src\main\java-gen\com\castiel\dao\DaoMaster.java
Written C:\Users\huangshuai\AndroidStudioProjects\CastielGreenDao\app\src\main\java-gen\com\castiel\dao\DaoSession.java
Processed 1 entities in 153ms BUILD SUCCESSFUL

构建Android项目实现增删改查

先来张项目结构全景图

再来张项目效果图

在官网中,提供了一段核心初始化代码,推荐将该段代码放在Application中

 helper = new DaoMaster.DevOpenHelper( this, "notes-db", null);
db = helper.getWritableDatabase();
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
noteDao = daoSession.getNoteDao();

即:在自己的Application中先创建了一个SQLiteOpenHelper并创建连接到一个具体数据库;再根据具体的datebase创建一个master对象用于;最后通过master创建一个数据库的会话操作。

 package com.castiel.dao;

 import android.app.Application;
import android.database.sqlite.SQLiteDatabase; /** * Created by huangshuai on 2016/5/11. * Email:huangshuai@wooyun.org */
public class BaseApplication extends Application {
public DaoSession daoSession;
public SQLiteDatabase db;
public DaoMaster.DevOpenHelper helper;
public DaoMaster daoMaster; @Override
public void onCreate() {
super.onCreate();
setupDatabase();
} private void setupDatabase() {
// 通过 DaoMaster 的内部类 DevOpenHelper,你可以得到一个便利的 SQLiteOpenHelper 对象。
// 可能你已经注意到了,你并不需要去编写「CREATE TABLE」这样的 SQL 语句,因为 greenDAO 已经帮你做了。
// 注意:默认的 DaoMaster.DevOpenHelper 会在数据库升级时,删除所有的表,意味着这将导致数据的丢失。
// 所以,在正式的项目中,你还应该做一层封装,来实现数据库的安全升级。
helper = new DaoMaster.DevOpenHelper(this, "student", null);
db = helper.getWritableDatabase();
// 注意:该数据库连接属于 DaoMaster,所以多个 Session 指的是相同的数据库连接。
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
} public DaoSession getDaoSession() {
return daoSession;
} public SQLiteDatabase getDb() {
return db;
} }

Activity具体实现

 package com.castiel.dao;

 import android.app.Activity;
import android.app.Dialog;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast; import java.util.List; import de.greenrobot.dao.query.Query;
import greendao.Student; /** * Created by huangshuai on 2016/5/11. * Email:huangshuai@wooyun.org * GreenDao增删改查实例 */
public class CastielActivity extends Activity implements StudentAdapter.AdapterEnterCallBack{
// 初始化组件
public static final String TAG = "WY";
private List<Student> listStudent;
private ListView list;
private EditText etQureyName;
StudentAdapter studentAdapter;
private Button btnAdd,btnQurey;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_dao);
list = (ListView) findViewById(R.id.dao_list);
btnAdd = (Button) findViewById(R.id.btn_add);
btnQurey = (Button) findViewById(R.id.btn_query);
etQureyName = (EditText) findViewById(R.id.edit_query);
listStudent = getStudentDao().loadAll();// 查询全部数据操作
studentAdapter = new StudentAdapter(CastielActivity.this,listStudent); list.setAdapter(studentAdapter);
studentAdapter.setCallback(this); btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogAdd();
}
}); btnQurey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String curCondition = etQureyName.getText().toString().trim();
if (TextUtils.isEmpty(curCondition)) {
Toast.makeText(CastielActivity.this,"查询条件不能为空",Toast.LENGTH_SHORT).show();
} else {
// Query 类代表了一个可以被重复执行的查询
Query query = getStudentDao().queryBuilder()
.where(StudentDao.Properties.SName.eq(curCondition))
.build();
// 查询结果以 List 返回
List students = query.list();
Toast.makeText(CastielActivity.this,"有" + students.size() + "个条件符合",Toast.LENGTH_SHORT).show();
}
etQureyName.setText("");// 查询后重置条件
}
});
} /** * 通过 BaseApplication 类提供的 getDaoSession() 获取具体 Dao * @return */
private StudentDao getStudentDao() {
return ((BaseApplication) this.getApplicationContext()).getDaoSession().getStudentDao();
} /** * 通过 BaseApplication 类提供的 getDb() 获取具体 db * @return */
private SQLiteDatabase getDb() {
return ((BaseApplication) this.getApplicationContext()).getDb();
} /** * 添加操作弹窗 */
protected void dialogAdd() {
final Dialog dataDialog = new Dialog(CastielActivity.this,R.style.myDialogTheme);
LayoutInflater curInfnfalater = LayoutInflater.from(this);
View view = curInfnfalater.inflate(R.layout.my_dialog, null);
Button b_ok,b_cancle;
final EditText etName,etSex,etClass,etAge;
etName = (EditText) view.findViewById(R.id.edit_name);
etSex = (EditText) view.findViewById(R.id.edit_sex);
etClass = (EditText) view.findViewById(R.id.edit_class);
etAge = (EditText) view.findViewById(R.id.edit_age); b_ok = (Button) view.findViewById(R.id.btn_ok);
b_ok.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Student ss = new Student(null,etName.getText().toString().trim(),etAge.getText().toString().trim(),etSex.getText().toString().trim(),etClass.getText().toString().trim());
getStudentDao().insert(ss);
studentAdapter.addData(ss);
dataDialog.dismiss();
}
});
b_cancle = (Button) view.findViewById(R.id.btn_cancel);
b_cancle.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
dataDialog.dismiss();
}
}); dataDialog.setContentView(view);
dataDialog.show();
} /** * 修改操作弹窗 */
protected void dialogModify(final Student curBean) {
final Dialog dataDialog = new Dialog(CastielActivity.this,R.style.myDialogTheme);
LayoutInflater curInfnfalater = LayoutInflater.from(this);
View view = curInfnfalater.inflate(R.layout.my_dialog, null);
Button b_ok,b_cancle;
final EditText etName,etSex,etClass,etAge;
etName = (EditText) view.findViewById(R.id.edit_name);
etSex = (EditText) view.findViewById(R.id.edit_sex);
etClass = (EditText) view.findViewById(R.id.edit_class);
etAge = (EditText) view.findViewById(R.id.edit_age);
etName.setText(curBean.getSName());
etSex.setText(curBean.getSSex());
etClass.setText(curBean.getSClass());
etAge.setText(curBean.getSAge()); b_ok = (Button) view.findViewById(R.id.btn_ok);
b_ok.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Student ss = new Student(curBean.getId(),etName.getText().toString().trim(),etAge.getText().toString().trim(),etSex.getText().toString().trim(),etClass.getText().toString().trim());
getStudentDao().deleteByKey(curBean.getId());
getStudentDao().insert(ss);
studentAdapter.setData(getStudentDao().loadAll());
dataDialog.dismiss();
}
});
b_cancle = (Button) view.findViewById(R.id.btn_cancel);
b_cancle.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
dataDialog.dismiss();
}
}); dataDialog.setContentView(view);
dataDialog.show();
} /**菜单弹窗 */
protected void dialogMenu(final Student curBean) {
final Dialog dataDialog = new Dialog(CastielActivity.this,R.style.myDialogTheme);
LayoutInflater curInfnfalater = LayoutInflater.from(this);
View view = curInfnfalater.inflate(R.layout.item_dialog, null);
Button b_modify,b_del; b_modify = (Button) view.findViewById(R.id.btn_modify);
b_modify.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
dialogModify(curBean);
dataDialog.dismiss();
}
});
b_del = (Button) view.findViewById(R.id.btn_del);
b_del.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// 根据Id删除对应数据
getStudentDao().deleteByKey(curBean.getId());
studentAdapter.setData(getStudentDao().loadAll());
dataDialog.dismiss();
}
}); dataDialog.setContentView(view);
dataDialog.show();
} @Override
public void onEnterClick(Student bean) {
dialogMenu(bean);
}
}

列表相关Adapter

 package com.castiel.dao;

 import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView; import java.util.List; import greendao.Student; /** * Created by huangshuai on 2016/5/11. * Email:huangshuai@wooyun.org * Student列表的Adapter */
public class StudentAdapter extends BaseAdapter {
private AdapterEnterCallBack callback;
private LayoutInflater inflater;
private List<Student> list_student; public StudentAdapter(Context context, List<Student> list_student) {
this.inflater = LayoutInflater.from(context);
this.list_student = list_student;
} @Override
public int getCount() {
return list_student.size();
} @Override
public Object getItem(int position) {
return list_student.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(final int position, View convertView, ViewGroup parent) {
StudentViewHodler sv;
if (convertView == null) {
sv = new StudentViewHodler();
convertView = inflater.inflate(R.layout.list_item, null);
sv.uAge = (TextView) convertView.findViewById(R.id.tv_age);
sv.uName = (TextView) convertView.findViewById(R.id.tv_name);
sv.uSex = (TextView) convertView.findViewById(R.id.tv_sex);
sv.uClass = (TextView) convertView.findViewById(R.id.tv_class);
sv.litem = (LinearLayout) convertView.findViewById(R.id.ll_item); convertView.setTag(sv);
} else {
sv = (StudentViewHodler) convertView.getTag();
} sv.uSex.setText(list_student.get(position).getSSex());
sv.uName.setText(list_student.get(position).getSName());
sv.uAge.setText(list_student.get(position).getSAge());
sv.uClass.setText(list_student.get(position).getSClass());
sv.litem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != callback) {
callback.onEnterClick(list_student.get(position));
}
}
});
return convertView;
} public void addData(Student data) {
if (data != null) {
this.list_student.add(data);
notifyDataSetChanged();
}
} public void setData(List<Student> data) {
if (data != null) {
list_student.clear();
list_student.addAll(data);
notifyDataSetChanged();
}
} public class StudentViewHodler {
TextView uName;
TextView uSex;
TextView uAge;
TextView uClass;
LinearLayout litem;
} public interface AdapterEnterCallBack {
void onEnterClick(Student bean);
} public void setCallback(AdapterEnterCallBack callback) {
this.callback = callback;
} }

布局文件实现

item_dialog.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="60dp" android:background="@android:color/white" android:orientation="horizontal"> <Button android:id="@+id/btn_del" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="删除" /> <Button android:id="@+id/btn_modify" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="修改" />
</LinearLayout>

list_item.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/tv_name" android:layout_width="0dp" android:layout_height="24dp" android:layout_weight="1" android:textSize="22sp" android:text="姓名" /> <TextView android:id="@+id/tv_age" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="22sp" android:text="年龄"/> <TextView android:id="@+id/tv_sex" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="22sp" android:text="性别"/> <TextView android:id="@+id/tv_class" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="22sp" android:text="班级"/> </LinearLayout>

main_dao.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn_add" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="增加数据" /> <Button android:id="@+id/btn_query" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="姓名查询" /> <EditText android:id="@+id/edit_query" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="输入姓名" android:textColor="@android:color/black" />
</LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/tv_name" android:layout_width="0dp" android:layout_height="24dp" android:layout_weight="1" android:textSize="18sp" android:text="姓名" /> <TextView android:id="@+id/tv_age" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="18sp" android:text="年龄"/> <TextView android:id="@+id/tv_sex" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="18sp" android:text="性别"/> <TextView android:id="@+id/tv_class" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="18sp" android:text="班级"/> </LinearLayout> <ListView android:id="@+id/dao_list" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>

my_dialog.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="姓名:" /> <EditText android:id="@+id/edit_name" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@android:color/black" />
</LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="性别:" /> <EditText android:id="@+id/edit_sex" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="班级:" /> <EditText android:id="@+id/edit_class" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@android:color/black" />
</LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="年龄:" /> <EditText android:id="@+id/edit_age" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn_ok" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="确认" /> <Button android:id="@+id/btn_cancel" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" />
</LinearLayout>
</LinearLayout>

运行程序,执行增删改查

项目源码链接:http://download.csdn.net/detail/mynameishuangshuai/9518322

参考链接:http://itangqi.me/2015/07/26/orm-greendao-summary/

via: http://blog.csdn.net/mynameishuangshuai/article/details/51386402

快速入门GreenDao框架并实现增删改查案例的更多相关文章

  1. ssm项目框架搭建(增删改查案例实现)——(SpringMVC+Spring+mybatis项目整合)

    Spring 常用注解 内容 一.基本概念 1. Spring 2. SpringMVC 3. MyBatis 二.开发环境搭建 1. 创建 maven 项目 2. SSM整合 2.1 项目结构图 2 ...

  2. Spring JdbcTemplate框架搭建及其增删改查使用指南

    Spring JdbcTemplate框架搭建及其增删改查使用指南 前言: 本文指在介绍spring框架中的JdbcTemplate类的使用方法,涉及基本的Spring反转控制的使用方法和JDBC的基 ...

  3. SQLite 入门教程(四)增删改查,有讲究 (转)

    转于: SQLite 入门教程(四)增删改查,有讲究 一.插入数据 INSERT INTO 表(列...) VALUES(值...) 根据前面几篇的内容,我们可以很轻送的创建一个数据表,并向其中插入一 ...

  4. MongoDB入门(介绍、安装、增删改查)

    文章作者公众号bigsai,已收录在回车课堂,如有帮助还请不吝啬点个赞赞支持一下! 课程导学 大家好我是bigsai,我们都学过数据库,但你可能更熟悉关系(型)数据库例如MySQL,SQL SERVE ...

  5. SSHE框架整合(增删改查)

    1.前期准备:jar包(c3p0.jdbc ,各个框架) web.xml文件:spring的   转码的,和Struts2的过滤器 <?xml version="1.0" e ...

  6. hibernate框架(1)---Hibernate增删改查

    Hibernate增删改查 1.首先我们要知道什么是Hibernate Hibernate是一个轻量级的ORMapping对象.主要用来实现Java和数据库表之间的映射,除此之外还提供数据查询和数据获 ...

  7. Mybatis框架二:增删改查

    这里是搭建框架和准备数据: http://www.cnblogs.com/xuyiqing/p/8600888.html 实现增删改查功能: 测试类: package junit; import ja ...

  8. MongoDB基础入门002--基本操作,增删改查

    一.这里只是演示最基本的操作,更多的信息可以去官网.https://docs.mongodb.com/manual 打开一个cmd,输入mongo命令打开shell,其实这个shell就是mongod ...

  9. SQLite 入门教程(四)增删改查,有讲究

    增删改查操作,其中增删改操作被称为数据操作语言 DML,相对来说简单一点. 查操作相对来说复杂一点,涉及到很多子句,所以这篇先讲增删改操作,以例子为主,后面再讲查操作. 一.插入数据 INSERT I ...

随机推荐

  1. 大熊君大话NodeJS之------Buffer模块

    一,开篇分析 所谓缓冲区Buffer,就是 "临时存贮区" 的意思,是暂时存放输入输出数据的一段内存. JS语言自身只有字符串数据类型,没有二进制数据类型,因此NodeJS提供了一 ...

  2. python4delphi 使用

    Python 开发桌面程序, 之前写过一个使用IronPython的博客. 下面这个方案使用 delphi 作为主开发语言,通过 python4delphi 控件包将 python 作为 script ...

  3. linq和lanmbda表达式比较解析

  4. POJ 2635 The Embarrassed Cryptographer

    大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...

  5. Swift2.1 语法指南——析构过程

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  6. Java之enumeration(枚举)

    enumeration(枚举)是JDK1.5引入的新特性,放在java.lang包中. 1.枚举类方法介绍 package com.enums; public class TestEnum { pub ...

  7. 如何让网页在浏览器标题栏显示自己制作的图标ico

    第一步,制作一个尺寸16x16大小的PNG图片,可以用photoshop等图片处理工具来设计,然后保存到本地电脑上,通过ico在线制作或使用IconWorkshop工具制作ICO图标,ico图标命名为 ...

  8. webpack 教程 那些事儿02-从零开始

    接着上篇我们有了最简单的安装了webpack的项目目录这节我们从零开始搭建一个简单的基于webpack的spa应用demo本节只说基础常用配置项,复杂后续讲解. 文章目录 1. 新建项目结构目录,如下 ...

  9. tab切换,滑动门

    <SCRIPT type=text/javascript>  jQuery(document).ready(function () {          changediv([" ...

  10. linux下使用rdp

    简单的说就是在linux下如何远程终端连接一台windows的服务器. 在windwos下我们直接可以mstsc开启远程终端的连接.而linux下呢.就需要安装一款工具了. 命令:sudo apt-g ...