黎活明8天快速掌握android视频教程--19_采用ListView实现数据列表显示
1、首先整个程序也是采用mvc的框架
DbOpenHelper 类
package dB; import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast; public class DbOpenHelper extends SQLiteOpenHelper
{ public DbOpenHelper(Context context) { super(context, "wy.db", null, 2);
} @Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE person(personid integer primary key autoincrement, name varchar(20), phone VARCHAR(12) NULL)"); } @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
}
数据库操作接口类:
我们可以采用下面的两种方式对数据库进行操作:
方式1:
package service; import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList;
import java.util.List; import dB.DbOpenHelper;
import domain.Person; public class OtherPersonService {
private DbOpenHelper dbOpenHelper; public OtherPersonService(Context context) {
this.dbOpenHelper = new DbOpenHelper(context);
}
public void save(Person person){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("name",person.getName());
values.put("phone",person.getPhone());
db.insert("person",null,values);
}
/**
* 删除记录
* @param name 记录ID
*/
public void delete(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
/* db.execSQL("delete from person where name=? and phone=?", new Object[]{name,phone});*/
db.delete("person", "name=? and phone= ?", new String[]{name ,phone});
}
/**
* 更新记录
* @param person
*/
public void update(Person person,String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
/* db.execSQL("update person set name=?,phone=? where name=? and phone=?",
new Object[]{person.getName(), person.getPhone(),name,phone});*/
ContentValues values = new ContentValues();
values.put("name",person.getName());
values.put("phone",person.getPhone());
db.update("person",values,"name=? and phone=?",new String[]{name ,phone});
}
/**
* 查询记录
* @param name 记录ID
* @return
*/
public Person find(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/* Cursor cursor = db.rawQuery("select * from person where name=? and phone = ?", new String[]{name, phone});*/
Cursor cursor = db.query("person",null,"name=? and phone=?",new String[]{name,phone},null,null,null);
if(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid"));
String name1 = cursor.getString(cursor.getColumnIndex("name"));
String phone1 = cursor.getString(cursor.getColumnIndex("phone"));
return new Person( name1, phone1);
}
cursor.close();
return null;
}
/**
* 分页获取记录
* @param offset 跳过前面多少条记录
* @param maxResult 每页获取多少条记录
* @return
*/
public List<Person> getScrollData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/* Cursor cursor = db.rawQuery("select * from person order by personid asc limit ?,?",*/
Cursor cursor = db.query("person",null,null,null,null,null,"personid asc",offset+ ","+ maxResult);
while(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid")); /*这里也可以写成
* String name = cursor.getString(1);
String phone = cursor.getString(2);
默认的表自带的id字段为0 ,name为第一个字段所有为1 ,phone为第二个字段为2*/
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
persons.add(new Person( name, phone));
}
cursor.close();
return persons;
} /**
* 获取记录总数
* @return
*/
public long getCount(){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/*Cursor cursor = db.rawQuery("select count(*) from person", null);*/
Cursor cursor = db.query("person", new String[]{"count(*)"}, null, null, null, null, null);
cursor.moveToFirst();
long result = cursor.getLong(0);//统计之后只有一个默认的字段,所以为0
cursor.close();
return result;
}
}
直接采用query的方式:
方式二:
package service; import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import java.util.ArrayList;
import java.util.List; import dB.DbOpenHelper;
import domain.Person; public class PersonService {
private DbOpenHelper dbOpenHelper; public PersonService(Context context) {
this.dbOpenHelper = new DbOpenHelper(context);
}
public void save(Person person){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("insert into person(name, phone) values(?,?)",
new Object[]{person.getName(), person.getPhone()});
}
/**
* 删除记录
* @param name 记录ID
*/
public void delete(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("delete from person where name=? and phone=?", new Object[]{name,phone});
}
/**
* 更新记录
* @param person
*/
public void update(Person person,String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("update person set name=?,phone=? where name=? and phone=?",
new Object[]{person.getName(), person.getPhone(),name,phone});
}
/**
* 查询记录
* @param name 记录ID
* @return
*/
public Person find(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person where name=? and phone = ?", new String[]{name,phone});
if(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid"));
String name1 = cursor.getString(cursor.getColumnIndex("name"));
String phone1 = cursor.getString(cursor.getColumnIndex("phone"));
return new Person( name1, phone1);
}
cursor.close();
return null;
}
/**
* 分页获取记录
* @param offset 跳过前面多少条记录
* @param maxResult 每页获取多少条记录
* @return
*/
public List<Person> getScrollData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person order by personid asc limit ?,?",
new String[]{String.valueOf(offset), String.valueOf(maxResult)});
while(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid")); /*这里也可以写成
* String name = cursor.getString(1);
String phone = cursor.getString(2);
默认的表自带的id字段为0 ,name为第一个字段所有为1 ,phone为第二个字段为2*/
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
persons.add(new Person( name, phone));
}
cursor.close();
return persons;
} /**
* 获取记录总数
* @return
*/
public long getCount(){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select count(*) from person", null);
cursor.moveToFirst();
long result = cursor.getLong(0);//统计之后只有一个默认的字段,所以为0
cursor.close();
return result;
} /*使用 SimpleCursorAdapter加装数据的时候,创建的数据库表的主键必须是_id,
* 这里我们使用personid as _id,将创建表的主键personid变成_id
* 返回cursor对象的时候,千万不能关闭cursor对象:cursor.close();*/
public Cursor getScrollCursorData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select personid as _id,name,phone from person order by personid asc limit ?,?",
new String[]{String.valueOf(offset), String.valueOf(maxResult)}); return cursor;//返回cursor对象之前,千万不能关闭cursor对象cursor.close();
} }
在正式的代码中建议使用方式2的这种方式进行操作:
Person对象
package domain; public class Person
{ private String name;
private String phone; @Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", phone='" + phone + '\'' +
'}';
} public Person(String name, String phone) {
this.name = name;
this.phone = phone;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPhone() {
return phone;
} public void setPhone(String phone) {
this.phone = phone;
}
}
要显示数据需要新建立一个adapter对象PersonAdapter
package adapter; import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView; import java.util.List; import domain.Person;
import test.weiyuan.sqllite1.R; public class PersonAdapter extends BaseAdapter{
private List<Person> persons;//要绑定的数据
private int resource;//布局文件资源
private Context context;//activity的上下文 public PersonAdapter(List<Person> persons, int resource, Context context) {
this.persons = persons;
this.resource = resource;
this.context = context;
} //绑定数据的数据大小
@Override
public int getCount() {
return persons.size();
} //显示数据在绑定数据List<Person>的位置,getItemAtPosition(position)来获得我们单击的item中的数据的时候,调用的就是
//getItem(int position)函数来获得我们的数据
@Override
public Object getItem(int position)
{
return persons.get(position);
}
//这个可以不管
@Override
public long getItemId(int position) {
return position;
}
//让数据如何在listview中显示出来
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/* if(convertView==null)
{
convertView = (View)LayoutInflater.from(context).inflate(resource,null);
}
Person person = persons.get(position);
TextView name = (TextView)convertView.findViewById(R.id.name);
TextView phone = (TextView)convertView.findViewById(R.id.phone);
name.setText(person.getName());
phone.setText(person.getPhone());*/
//上面的代码不够优化,我们可以使用一个优化的方法给以解决
TextView name = null;
TextView phone = null;
if(convertView==null)
{
convertView = (View)LayoutInflater.from(context).inflate(resource,null);
name = (TextView)convertView.findViewById(R.id.name);
phone = (TextView)convertView.findViewById(R.id.phone);
ViewCache cache = new ViewCache();
cache.name = name;
cache.phone = phone;
convertView.setTag(cache); }
else
{
ViewCache cache = (ViewCache)convertView.getTag();
name = cache.name;
phone =cache.phone;
}
Person person = persons.get(position); name.setText(person.getName());
phone.setText(person.getPhone()); return convertView;
}
private final class ViewCache
{
public TextView name;
public TextView phone;
} }
接下来看看activity的代码如下:
显示数据的时候采用了下面的三种方式来加载数据的显示:
1、使用下面的三种方式类进行显示
package test.weiyuan.sqllite1; import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set; import adapter.PersonAdapter;
import dB.DbOpenHelper;
import domain.Person;
import service.PersonService; public class MyActivity extends Activity {
final static String TAG = "weiyuan";
private ListView listView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
listView = (ListView) this.findViewById(R.id.listView);
/*创建数据库*/
DbOpenHelper dbOpenHelper = new DbOpenHelper(MyActivity.this);
dbOpenHelper.getWritableDatabase();
/*在数据库中保存数据*/
PersonService service = new PersonService(MyActivity.this);
for (int i = 0; i < 20; i++) {
service.save(new Person("weiyuan" + i, "12345" + i));
}
Log.i(TAG, "数据保存成功");
//拖动Listview的时候顶部和底部不会出现阴影
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
listView.setCacheColorHint(0);
//在Listview中显示数据
show();
// show1();
//show2();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/* //调用SimpleCursorAdapter方式的时候,使用getItemAtPosition(position)函数返回List的数据集合中的元素是Cursor类型
//parent就是我们单击的Listview
ListView listView1 = (ListView)parent;
Cursor cursor = (Cursor)listView1.getItemAtPosition(position);
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone =cursor.getString(cursor.getColumnIndex("phone"));
Toast.makeText(MyActivity.this,name+","+phone,Toast.LENGTH_LONG).show();*/ /* *//* 调用自定义适配器的时候,getItemAtPosition(position)函数返回的是Person类型,
getItemAtPosition(position)的实现是通过调用BaseAdapter类中的
@Override
public Object getItem(int position)
{
return persons.get(position);
}
来实现的*//*
ListView listView1 = (ListView)parent;
Person person= (Person)listView1.getItemAtPosition(position);
Toast.makeText(MyActivity.this,person.getName()+","+person.getPhone(),Toast.LENGTH_SHORT).show();*/ //调用SimpleAdapter来显示ListView的数据,getItemAtPosition(position)返回的是HashMap的数据
ListView listView1 = (ListView)parent;
HashMap<String,String> map= (HashMap<String,String>)listView1.getItemAtPosition(position);
String name =map.get("name");
String phone = map.get("phone");
Toast.makeText(MyActivity.this,name+","+phone,Toast.LENGTH_LONG).show(); /* 总结:通过适配器加载数据的时候:getItemAtPosition(position)返回的就是适配器加载的数据集合中元素的类型,是集合中元素
的类型,我们来看一下:比如是SimpleAdapter来显示ListView的数据:
SimpleAdapter simpleAdapter = new SimpleAdapter(this, datalist, R.layout.item,
new String[]{"name", "phone"}, new int[]{R.id.name, R.id.phone});
其中datalist就是我们加载的数据集合,datalist是List<Map<String, String>>类型,该集合中的元素就是Map<String, String>类型;
同理通过 SimpleCursorAdapter加载数据:
SimpleCursorAdapter simplecursoradapter = new SimpleCursorAdapter(this, R.layout.item,
cursor, new String[]{"name", "phone"}, new int[]{R.id.name, R.id.phone});
其中cursor就是加载的数据集合,该集合中的元素也是cursor类型。*/ }
}); }
/*方法三:使用自定义的适配器来加载数据*/
private void show2()
{
List<Person> persons = new ArrayList<Person>();
PersonService service = new PersonService(MyActivity.this);
persons = service.getScrollData(0, 20);
PersonAdapter personAdapter = new PersonAdapter(persons,R.layout.item,this);
listView.setAdapter(personAdapter); } /*通过 SimpleCursorAdapter加装游标适配器来显示数据
* 这里是 new String[]{"name", "phone"}对应的是数据库表中的字段名称*/
private void show1()
{
PersonService service = new PersonService(MyActivity.this);
Cursor cursor = service.getScrollCursorData(0, 20);
SimpleCursorAdapter simplecursoradapter = new SimpleCursorAdapter(this, R.layout.item,
cursor, new String[]{"name", "phone"}, new int[]{R.id.name, R.id.phone});
listView.setAdapter(simplecursoradapter);
} /*方法一:通过适配器SimpleAdapter来显示ListView的数据*/
private void show()
{ List<Person> persons = new ArrayList<Person>();
PersonService service = new PersonService(MyActivity.this);
persons = service.getScrollData(0, 20);
List<Map<String, String>> datalist = new ArrayList<Map<String, String>>();
for (Person person : persons) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", person.getName());
item.put("phone", person.getPhone());
datalist.add(item); }
/* //这里new String[]{"name", "phone"}中的name 以及phone 要和 item.put("name", person.getName());
item.put("phone", person.getPhone());中的对应起来*/
SimpleAdapter simpleAdapter = new SimpleAdapter(this, datalist, R.layout.item,
new String[]{"name", "phone"}, new int[]{R.id.name, R.id.phone});
listView.setAdapter(simpleAdapter); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
1 对应的这三种方式的总结:
调用SimpleCursorAdapter方式的时候,使用getItemAtPosition(position)函数返回List的数据集合中的元素是Cursor类型
//parent就是我们单击的Listview
ListView listView1 = (ListView)parent;
Cursor cursor = (Cursor)listView1.getItemAtPosition(position);
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone =cursor.getString(cursor.getColumnIndex("phone"));
Toast.makeText(MyActivity.this,name+","+phone,Toast.LENGTH_LONG).show();
2、调用自定义适配器的时候,getItemAtPosition(position)函数返回的是Person类型,
ListView listView1 = (ListView)parent;
Person person= (Person)listView1.getItemAtPosition(position);
Toast.makeText(MyActivity.this,person.getName()+","+person.getPhone(),Toast.LENGTH_SHORT).show();
3、调用SimpleAdapter来显示ListView的数据,getItemAtPosition(position)返回的是HashMap的数据
ListView listView1 = (ListView)parent;
HashMap<String,String> map= (HashMap<String,String>)listView1.getItemAtPosition(position);
String name =map.get("name");
String phone = map.get("phone");
Toast.makeText(MyActivity.this,name+","+phone,Toast.LENGTH_LONG).show();
我们来看看界面的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 标题 -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> <TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="姓名"
/> <TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="电话"
/> </LinearLayout>
<!-- ListView控件 -->
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"
/>
</LinearLayout>
adapter的布局文件
<?xml version="1.0" encoding="utf-8"?>
<!--item -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- 名称 -->
<TextView
android:layout_width="130dp"
android:layout_height="40dp"
android:id="@+id/name"
android:gravity="center_vertical"
/>
<!-- 电话 -->
<TextView
android:layout_width="250dp"
android:layout_height="40dp"
android:id="@+id/phone"
android:gravity="center_vertical"
/> </LinearLayout>
黎活明8天快速掌握android视频教程--19_采用ListView实现数据列表显示的更多相关文章
- 黎活明8天快速掌握android视频教程--20_采用ContentProvider对外共享数据
1.内容提供者是让当前的app的数据可以让其他应用访问,其他应该可以通过内容提供者访问当前app的数据库 contentProvider的主要目的是提供一个开发的接口,让其他的应该能够访问当前应用的数 ...
- 黎活明8天快速掌握android视频教程--15_采用Pull解析器解析和生成XML内容
1.该项目主要有下面的两个作用 (1)将xml文件解析成对象的List对象,xml文件可以来自手机本地,也可以来自服务器返回的xml数据 (2)强list对象保存成xml文件,xml保存到手机的内存卡 ...
- 黎活明8天快速掌握android视频教程--16_采用SharedPreferences保存用户偏好设置参数
SharedPreferences保存的数据是xml格式,也是存在数据保存的下面四种权限: 我们来看看 我们来看看具体的业务操作类: /** * 文件名:SharedPrecences.java * ...
- 黎活明8天快速掌握android视频教程--14_把文件存放在SDCard
把文件保存在手机的内部存储空间中 1 首先必须在清单文件中添加权限 <?xml version="1.0" encoding="utf-8"?> & ...
- 黎活明8天快速掌握android视频教程--22_访问通信录中的联系人和添加联系人
Android系统中联系人的通讯录的contentProvide是一个单独的apk,显示在界面的contact也是一个独立的apk,联系人apk通过contentProvide访问底层的数据库. 现在 ...
- 黎活明8天快速掌握android视频教程--25_网络通信之资讯客户端
1 该项目的主要功能是:后台通过xml或者json格式返回后台的视频资讯,然后Android客户端界面显示出来 首先后台新建立一个java web后台 采用mvc的框架 所以的servlet都放在se ...
- 黎活明8天快速掌握android视频教程--24_网络通信之网页源码查看器
1 该项目的主要功能就是从将后台的html网页在Android的界面上显示出来 后台就是建立一个java web工程在工程尚建立一个html或者jsp文件就可以了,这里主要看Android客户端的程序 ...
- 黎活明8天快速掌握android视频教程--23_网络通信之网络图片查看器
1.首先新建立一个java web项目的工程.使用的是myeclipe开发软件 图片的下载路径是http://192.168.1.103:8080/lihuoming_23/3.png 当前手机和电脑 ...
- 黎活明8天快速掌握android视频教程--21_监听ContentProvider中数据的变化
采用ContentProvider除了可以让其他应用访问当前的app的数据之外,还有可以实现当app的数据发送变化的时候,通知注册了数据变化通知的调用者 其他所有的代码都和第20讲的一样,不同的地方看 ...
随机推荐
- [SD心灵鸡汤]000.每月一则 - 索引
[SD心灵鸡汤]001.每月一则 - 2015.05 [SD心灵鸡汤]002.每月一则 - 2015.06 [SD心灵鸡汤]003.每月一则 - 2015.07 [SD心灵鸡汤]004.每月一则 - ...
- [工具-004]如何从apk中提取AndroidManifest.xml并提取相应信息
跟上一篇类似,我们也需要对APK的一些诸如umengkey,ADkey,TalkingData进行验证,那么我们同样需要解压apk文件,然后提取其中的AndroidManifest.xml.然后解析x ...
- 加速国内Github代码下载速度
标题: 加速国内Github代码下载速度 作者: 梦幻之心星 347369787@QQ.com 标签: [Github, 代码, 下载] 目录: 代码 日期: 2019-10-27 目录 前提说明 解 ...
- JS遍历对象修改属性名
根据接口返回数据中number属性值,对数据进行截取,并改变属性名.直接上码: 下面是需要处理的数据 let data={"minValue":7400, "maxVal ...
- Java实现 LeetCode 467 环绕字符串中唯一的子字符串
467. 环绕字符串中唯一的子字符串 把字符串 s 看作是"abcdefghijklmnopqrstuvwxyz"的无限环绕字符串,所以 s 看起来是这样的:"-zabc ...
- Java实现 LeetCode 258 各位相加
258. 各位相加 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2. 由 ...
- Java实现背包问题
1 问题描述 给定n个重量为w1,w2,w3,-,wn,价值为v1,v2,-,vn的物品和一个承重为W的背包,求这些物品中最有价值的子集(PS:每一个物品要么选一次,要么不选),并且要能够装到背包. ...
- java实现洛谷P1308统计单词数
题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...
- Java实现第九届蓝桥杯等腰三角形
等腰三角形 题目描述 本题目要求你在控制台输出一个由数字组成的等腰三角形. 具体的步骤是: 1. 先用1,2,3,...的自然数拼一个足够长的串 2. 用这个串填充三角形的三条边.从上方顶点开始,逆时 ...
- DDD之4聚合和聚合根
聚合就是归类的意思,把同类事物统一处理: 聚合根也就是最抽象,最普遍的特性: 背景 领域建模的过程回顾: 那么问题来了? 为什么要在限界上下文和实体之间增加聚合和聚合根的概念,即作用是什么? 如何设计 ...