第一页读者评论

Comments from readers:

Thinking In Java should be read cover to cover by every Java programmer, then kept close at hand for frequent reference. The exercises are challenging, and the chapter on Collections is superb! Not only did this book help me to pass the Sun Certified Java Programmer exam; it's also the first book I turn to whenever I have a Java question. Jim Pleger, Loudoun County (Virginia) government

读者评论:

每个程序员都应该把《Java 编程思想》一读再读,同时也应该放到手边以便随时查阅。这本书里的练习很有挑战力,章节的划分也非常好!这本书不仅使我顺利通过了Sun公司指定的Java 程序员考试,这也是第一本我在任何时候有了问题都可以去寻求帮助的书。

Jim Pleger, Loudoun County (Virginia) government

 

Much better than any other Java book I've senn. Make that "by an order of magnitude" ...very complete, with excellent right-to-the-point examples and intelligent, not dumbed-down,explanations...In contrast to many other Java books I found it to be unusually mature, consistent, intellectually honest, well-written and precise.IMHO, an ideal book for studying Java.Anatoly Vorobey,Technion University,Haifa,Israel

比我以前看过的Java教材都好。能做到"循序渐进",非常完善,有着非常一语中的的例子和智慧的,条理清楚的解释。对比我看过的其他Java方面的书,我发现这本书考虑全面,结构统一,知识分子的诚实,文笔很好,并且语言准确。依我之见,这是一本理想的学习Java的书。

Anatoly Vorobey,Technion University,Haifa,Israel(这段翻的,自己都看不下去了)

 

One of the absolutely best programming tutorials I’ve seen for any language.Joakim ziegler, FIX sysop
我看过的所有编程教程中最好的一本。Joakim ziegler, FIX sysop

 

Thank you for your wonderful,wonderful book on Java. Dr. Gavin Pillay, Registrar, King Edward VIII Hospital, south Africa
感谢你的这本非常精彩的Java方面的书Dr. Gavin Pillay, Registrar, King Edward VIII Hospital, south Africa

 

Thank you again for your awesome book. I was really floundering (being a non-C programmer), but your book has brought me up to speed as fast as I could read it. It’s really cool to be able to understand the underlying principles and concepts from the start, rather than having to try to build that conceptual model through trial and error. Hopefully I will be able to attend your seminar in the not-too-distant future. Randall R. Hawley, Automation Technician, Eli Lilly&Co.
再次感谢你这本非常棒的书。我不是C程序员,看这类的书很挣扎,但是你的这本书我读起来却很快。开始的时候能够懂得基本的原则和概念要比通过实验和错误再建立起概念模型要酷多了。希望在不久的将来我能够能加你的研究小组。
Randall R. Hawley, Automation Technician, Eli Lilly&Co.

 

The best computer book writing I have seen. Tom Holland
我所见过的最好的计算机著作。Tom Holland

 

This is one of the best books I’ve read about a programming language…The best book ever written on Java. Ravindra Pai,Oracle Corporation, SUNOS product line
这是我读过的关于编程语言的最好的书之一,写的最好的Java书。Ravindra Pai,Oracle Corporation, SUNOS product line

 

This is the best book on Java that I have ever found! You have done a great job. Your depth is amazing. I will be purchasing the book when it is published. I have been learning Java since October 96. I have read a few books, and consider yours a “MUST READ.” These past few months we have been focused on a product written entirely in Java. Your book has helped solidify topics I was shaky on and has expanded my knowledge base. I have even used some of your explanations as information in interviewing contractors to help our team. I have found how much Java knowledge they have by asking them about things I have learned from reading your book(e.g., the difference between arrays and Vectors). Your book is great! Steve Wilkinson, Senior Staff Specialist, MCI Telecommunications.
这是我见过的关于Java的最好的书了!你做了件伟大的工作。你的潜力真是让人惊讶。你的书出版后我会买一本的。我从96年10月开始学习Java。我读过一些关于Java的书,认为你的这本是必读的。这几个月我们的精力主要集中在用Java进行产品开发。这本书使我本来手摇摆不定的选题终于确定下来了,同时也扩充了我的知识面。在与承包人面谈时,我甚至引用一些你的解释作为观点来帮助我的团队。通过问一些从你书上学来的问题(比如数组和?)我能了解到对方对Java了解多少。你的书太好了!Steve Wilkinson, Senior Staff Specialist, MCI Telecommunications.

----------------------------------------------------------------------------------------------

那个,考虑到我的耐力实在有限,决定每做完一段就发上来,每一页做成一篇文章。当初看《明朝那些事儿》的时候看的很爽,后来看了明月写的一个公告的时候才发现明月已经坚持不懈的写了好几年了,要是能有明月那样的毅力就好了啊,坚持,坚持,坚持……

PS:英文格式的东东看起来真的不舒服啊

再PS:好像翻译读者评论是件很没有创意的事情啊,不过反正都开始了,那就坚持下去吧,嘿嘿

 

 

要在你的博客中添加**评论功能**,让读者可以留言,我们可以基于你之前使用 **Flask + PostgreSQL + Railway** 的架构进行扩展。 我们将实现: - ✅ 读者在每篇文章下方输入“昵称”和“留言内容” - ✅ 提交后保存到数据库 - ✅ 刷新页面仍能看到所有评论 - ✅ 数据持久化(不会丢失) --- ## 🧩 第一步:修改数据库结构 —— 添加 `comments` 表 我们需要一张新表来存储评论信息。 ```sql CREATE TABLE IF NOT EXISTS comments ( id SERIAL PRIMARY KEY, post_id INTEGER NOT NULL, author TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE ); ``` > `ON DELETE CASCADE` 表示:如果文章被删除,相关评论也会自动删除。 --- ## 🛠 第二步:修改 `app.py` —— 增加评论处理逻辑 更新后的完整 `app.py` 如下: ```python from flask import Flask, render_template, request, redirect, url_for import os import psycopg2 app = Flask(__name__) # 数据库连接 DATABASE_URL = os.getenv("DATABASE_URL") def get_db_connection(): conn = psycopg2.connect(DATABASE_URL) return conn # 初始化数据库:创建 posts 和 comments 表 def init_db(): conn = get_db_connection() cur = conn.cursor() # 创建文章表 cur.execute(""" CREATE TABLE IF NOT EXISTS posts ( id SERIAL PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); """) # 创建评论表 cur.execute(""" CREATE TABLE IF NOT EXISTS comments ( id SERIAL PRIMARY KEY, post_id INTEGER NOT NULL, author TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE ); """) conn.commit() cur.close() conn.close() @app.before_first_request def setup(): init_db() @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": # 如果是发布文章 if "title" in request.form: title = request.form["title"] content = request.form["content"] conn = get_db_connection() cur = conn.cursor() cur.execute("INSERT INTO posts (title, content) VALUES (%s, %s)", (title, content)) conn.commit() cur.close() conn.close() return redirect(url_for("index")) # 如果是提交评论 elif "author" in request.form: post_id = request.form["post_id"] author = request.form["author"] content = request.form["content"] conn = get_db_connection() cur = conn.cursor() cur.execute( "INSERT INTO comments (post_id, author, content) VALUES (%s, %s, %s)", (post_id, author, content) ) conn.commit() cur.close() conn.close() return redirect(url_for("index")) # 获取所有文章及其对应的评论 conn = get_db_connection() cur = conn.cursor() # 查询所有文章 cur.execute("SELECT * FROM posts ORDER BY created_at DESC") posts = cur.fetchall() # 查询所有评论,并按 post_id 分组 cur.execute(""" SELECT post_id, author, content, created_at FROM comments ORDER BY created_at ASC """) comments = cur.fetchall() cur.close() conn.close() # 将评论按 post_id 分类 comments_dict = {} for comment in comments: post_id = comment[0] if post_id not in comments_dict: comments_dict[post_id] = [] comments_dict[post_id].append(comment[1:]) return render_template("index.html", posts=posts, comments=comments_dict) ``` --- ## 🖼 第三步:更新 `templates/index.html` —— 添加评论表单和显示区域 替换原来的 HTML 文件内容如下: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <title>📝 我的博客</title> <style> body { font-family: Arial; margin: 40px; } h1, h2, h3 { color: #2c3e50; } .post { border: 1px solid #ddd; padding: 15px; margin: 20px 0; border-radius: 8px; background: #f9f9fb; } .comment { background: #e8f4f8; padding: 10px; margin: 10px 0; border-left: 4px solid #3498db; font-size: 0.9em; } input, textarea, button { padding: 10px; margin: 5px 0; width: 100%; box-sizing: border-box; } button { background: #3498db; color: white; border: none; cursor: pointer; font-size: 1em; } button:hover { background: #2980b9; } .add-post, .add-comment { max-width: 600px; } </style> </head> <body> <h1>📝 我的博客</h1> <!-- 发布新文章 --> <div class="add-post"> <form method="post"> <input type="text" name="title" placeholder="标题" required /> <textarea name="content" rows="4" placeholder="写一篇文章..." required></textarea> <button type="submit">发布文章</button> </form> </div> <hr /> <!-- 显示所有文章和评论 --> {% if posts %} {% for post in posts %} <div class="post"> <h3>{{ post[1] }}</h3> <p>{{ post[2] }}</p> <small>发布时间:{{ post[3] }}</small> <!-- 显示该文章的所有评论 --> <div style="margin-top: 20px;"> <h4>💬 评论({{ comments.get(post[0], []) | length }} 条):</h4> <!-- 评论列表 --> {% if comments.get(post[0]) %} {% for comment in comments[post[0]] %} <div class="comment"> <strong>{{ comment[0] }}</strong> <p>{{ comment[1] }}</p> <small>{{ comment[2] }}</small> </div> {% endfor %} {% else %} <p><i>还没有评论,快来抢沙发吧!</i></p> {% endif %} <!-- 添加评论表单 --> <form method="post" style="margin-top: 15px;"> <input type="hidden" name="post_id" value="{{ post[0] }}" /> <input type="text" name="author" placeholder="你的昵称" required /> <textarea name="content" rows="2" placeholder="写下你的想法..." required></textarea> <button type="submit">发表评论</button> </form> </div> </div> {% endfor %} {% else %} <p>还没有文章哦~快写一篇吧!</p> {% endif %} </body> </html> ``` --- ## 🔁 第四步:重新部署到 Railway 由于你已经部署过一次,现在只需: ### 方法一:自动同步(推荐) 1. 修改本地代码后,推送到 GitHub: ```bash git add . git commit -m "added comment feature" git push origin main ``` 2. Railway 会**自动检测代码变更并重新构建部署** ✅ 几分钟后访问你的网站链接,就能看到“评论功能”了! --- ### 方法二:手动触发重建 1. 打开 [Railway 控制台](https://railway.app) 2. 进入你的项目 3. 点击右上角的 “Redeploy” 按钮 --- ## ✅ 功能验证 打开你的博客网址,尝试以下操作: 1. 写一篇文章 → 成功 2. 在文章下输入昵称和留言 → 提交成功 3. 刷新页面 → 留言还在! 4. 关机第二天再打开 → 所有数据都保留着! 🎉 恭喜!你现在拥有了一个支持**文章发布 + 读者评论 + 数据永久保存**的完整博客系统! --- ## 🚀 可选增强功能(未来可扩展) | 功能 | 实现方式 | |------|----------| | 防止 XSS 攻击 | 使用 `Markup` 或转义用户输入 | | 评论排序(最新在前) | 修改 SQL 查询加 `ORDER BY created_at DESC` | | 删除评论功能 | 添加删除按钮 + 后端路由 `/delete_comment/<id>` | | 用户头像 | 引入 Gravatar 头像服务 | | 分页加载 | 限制每次查询文章/评论数量 | --- ## 💡 小贴士 - 所有数据都存在 Railway 提供的 PostgreSQL 中,**不会因重启丢失** - 免费额度足够支撑数千条评论 - 可绑定自定义域名如 `blog.yourname.com` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值