`
lw223
  • 浏览: 99347 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

体验GAE springMVC

    博客分类:
  • GAE
阅读更多

      把gae java的教程例子改了一下,用springMVC写的,目前只是个半成品,现在bug是点击submit才能看到所有留言,点击两次submit才能看到自己发的留言。

 

      因为是springMVC是第一次接触,写的不好,东西是今天上悄悄改的,页面也没仔细弄,下午还得去忙工作。有时间再改吧。

      怎么配置gae spring 参考的是这篇帖子http://sikeh.iteye.com/blog/364043

 

由于东西bug比较多,就贴几个主要代码。具体配置参考上面给的链接,写的很详细了 呵呵、

bean

package com.fish.gae.entity;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Comment {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private User author;

	@Persistent
	private String content;

	@Persistent
	private Date date;

	@Persistent
	private String commentDate;
	
	public Comment(User author,  Date date, String content,String commentDate) {
		this.author = author;
		this.content = content;
		this.date = date;
		this.commentDate =commentDate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public User getAuthor() {
		return author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getCommentDate(){
		return commentDate;
	}
	public void setCommentdate(String commentDate){
		this.commentDate = commentDate;
	}
}

 

controller

package com.fish.gae.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fish.gae.entity.Comment;
import com.fish.gae.entity.PMF;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@Controller
@RequestMapping(value = "/commentAdd.htm")
public class CommentController {

	private static final Logger log = Logger.getLogger(CommentController.class
			.getName());

	@RequestMapping(method = RequestMethod.POST)
	public String doPost(String content, Model model) {

		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        String commentDate = sdf.format(new Date());
		model.addAttribute("content", content);
		Comment comment = new Comment(user, date, content,commentDate);

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(comment);

		} finally {
			pm.close();
		}
		return "comment";
	}

	@ModelAttribute("comments")
	public List<Comment> doGet(Model model) {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from  " + Comment.class.getName();
		List<Comment> comments = (List<Comment>)pm.newQuery(query).execute();
		if(comments.isEmpty()){
			String message= "没有留言";
			System.out.print(message);
		}else{
			for(Comment co : comments){
				if(co.getAuthor()==null){
					String author = "火星人";
				}else{
					 co.getAuthor().getNickname();
				}
				co.getContent();
			}
		}
		return comments;
	}

}

 页面 comment.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>

<c:forEach items="${comments}" var="comments" varStatus="status">
			
		<c:out value="${comments.content}"></c:out>
		<c:out value="${comments.commentDate}"></c:out>
	</c:forEach>


<form action="commentAdd.htm" method="post">
<table>

	<tr>
		<td>comment</td>
		<td><textarea rows="3" cols="10" name="content"></textarea></td>
	</tr>
	<tr>
		<td><input type="submit" value="Submit" /></td>
	</tr>
</table>
</form>
</body>
</html>

 

分享到:
评论

相关推荐

    GAE-SpringMVC_Example

    GAE-SpringMVC_Example SpringMVC 应用示例,支持:Google AppEngine v1.9.15 和 SpringMVC v3.1.1 是一个建立在[集成开发环境] Moon Eclipse Service Release 1 (4.4.1) 上的项目,因此您可以将其导入Eclipse 并...

    spring3+springmvc+jpa2+gae

    标题 "spring3+springmvc+jpa2+gae" 指的是一个集成开发环境,它结合了Spring框架的三个核心组件以及Google App Engine (GAE)。这个项目旨在展示如何在GAE上运行一个基于Spring 3、Spring MVC和JPA 2.0的应用程序。...

    gae-pytorch-master_pytorch_pytorchgae_GAE_自编码器_gaepytorchmaster_

    【标题】"gae-pytorch-master_pytorch_pytorchgae_GAE_自编码器_gaepytorchmaster_" 提供的信息表明,这是一个使用PyTorch实现的图自编码器(Graph Autoencoder, GAE)项目,其核心是将自编码器的概念应用于图数据。...

    基于GAE的Demo

    【基于GAE的Demo】是一个使用Eclipse集成开发环境构建的项目,主要展示了如何在Google App Engine(GAE)平台上整合Struts2、Spring和Tiles框架。GAE是Google提供的一个云计算平台,允许开发者在Google的基础设施上...

    GAE使用规则

    GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则GAE使用规则

    gae_in_pytorch-master_GAE_

    **图形自动编码器(GAE)在PyTorch中的实现** **一、GAE概述** 图形自动编码器(Graph Autoencoder, GAE)是一种应用于图数据的深度学习模型,它结合了自动编码器(Autoencoder)的思想与图神经网络(Graph Neural...

    spring+gae

    【标题】"Spring+GAE"揭示了将Google App Engine(GAE)与Spring框架集成的主题,这是一个在云端运行Java应用程序的关键技术组合。Spring是一个广泛使用的开源Java框架,提供了依赖注入、面向切面编程和MVC(模型-...

    GAE入门教程

    pass之GAE入门教程, 学习GAE

    GAE包(以配置好,解压可用)

    标题 "GAE包(以配置好,解压可用)" 提供的信息表明,这是一个已经预配置好的Google App Engine (GAE)开发环境的压缩包。GAE是Google提供的一项平台即服务(PaaS),允许开发者在Google的基础设施上运行自己的Web...

    GAE之webapp框架

    ### GAE之webapp框架详解 #### 一、引言 在Google App Engine (GAE) 平台上进行Web应用开发时,选择合适的框架对于提高开发效率至关重要。其中,`webapp` 框架因其简洁高效而备受开发者青睐。本篇文章将详细介绍`...

    GAE blog安装

    标题“GAE blog安装”指的是在Google App Engine (GAE)上部署一个博客应用的过程。GAE是一个由Google提供的平台即服务(PaaS)云环境,允许开发者构建、运行和维护Web应用程序,无需管理和维护底层基础设施。在这个...

    让gae支持php的方法

    1. **安装和配置Quercus**:首先,你需要下载Quercus的Java库,并将其添加到你的GAE项目类路径中。这可以通过在你的项目`lib`目录下放置Quercus的JAR文件来完成。 2. **构建PHP处理程序**:创建一个Java类作为PHP...

    关于GAE的教程、工具与文档(建站)

    **谷歌应用引擎(Google App Engine, GAE)**是谷歌提供的一种云计算平台,允许开发者构建、部署和运行基于Web的应用程序。GAE支持多种编程语言,包括Python、Java、Go、Node.js等,提供了完整的基础设施,如数据库...

    GAE编程指南

    《GAE编程指南》是一种云计算服务,跟其他的同类产品不同,它提供了一种简单的应用程序构建模型,通过这种模型,你可以轻松地构建出能够容纳数百万用户的应用程序。《GAE编程指南》是介绍使用这个强大平台的专家级...

    GAE read rss send to 腾讯微博

    标题“GAE read rss send to 腾讯微博”指的是一个使用Google App Engine(GAE)平台开发的应用程序,该程序的功能是从RSS源读取数据并将其发布到腾讯微博。RSS(Really Simple Syndication)是一种内容聚合格式,常...

    GAE和SAE的比较

    云计算下的PaaS中的GAE和SAE平台

    gtap,基于GAE的代理

    标题中的“gtap,基于GAE的代理”指的是一个名为GTAProxy的项目,它是一个构建在Google App Engine(GAE)平台上的代理服务。这个服务的主要目的是为用户提供访问Twitter API的能力,尤其在某些地区或者特定网络环境...

    GAE(Google App Engine)空间申请使用教程及 GAE域名捆绑方法

    ### GAE(Google App Engine)空间申请使用教程及 GAE域名捆绑方法 #### GAE简介与功能概述 GAE(Google App Engine)是由谷歌提供的一个强大的云服务平台,它允许开发者构建并托管各种类型的应用程序。从实用性...

    GAE上可以用的JAVA 博客源代码

    GAE上可以用的JAVA Blog源代码 可以在GAE上直接使用,支持图片上传等。 源代码是修改其他网友的普通blog程序而来,只做了必要的修改,原结构保留 最新版本请去主页下载 http://redpower1998.appspot.com 主页包括...

Global site tag (gtag.js) - Google Analytics