#!/usr/bin/env python
import MySQLdb
print "Content-Type: text/html\n"
print "<html><head><title>Books</title></head>"
print "<body>"
print "<h1>Books</h1>"
print "<ul>"
connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db')
cursor = connection.cursor()
cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10")
for row in cursor.fetchall():
print "<li>%s</li>" % row[0]
print "</ul>"
print "</body></html>"
connection.close()
如果不分层,UI做了一个页面,要想加进系统里面,累死。
但是如果把连接数据库和业务逻辑从里面解耦出来,那么开发人员就比较容易修改页面,最大化的利用UI的代码。
当然还有其他的优点
1万+

被折叠的 条评论
为什么被折叠?



