easyjweb ejs 2014.2.25

一 、简单 easyjweb 项目

1. 创建一个web 项目 , 将easyjweb-corejar 包 和required 包下的所有jar 包拷到项目下。

2.写一个 action  ..

package com.action;

/*
 * 要求:
 * 1.默认hello和 views 中的包名一致(),否则找不到模板。不一致是可以配置 返回值new Page
 * 2.方法名 为 index或者init为默认访问方法名,参数 webForm   访问方式 hello.ejf?cmd=index
 * 3.继承AbstractPageCmdAction 或者实现IWebAction
 * 4. 如果不return  , 方法名 和 html 页面名是一致的
 */

import java.text.SimpleDateFormat;
import java.util.Date;



import com.easyjf.web.IWebAction;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.core.AbstractPageCmdAction;

public class HelloAction extends AbstractPageCmdAction{//hello1 必须和 views 中的包名一致,否则找不到模板
    public Page index(WebForm form){//方法名 为 index
        form.addResult("msg", "你好,这是第一个easyjweb 项目");
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        form.addResult("date",df.format(new Date()));
        return new Page("/hello1/index.html");
    }
}
/*public class HelloAction implements IWebAction{
    @Override
    public Page execute(WebForm form, Module module) throws Exception {
        form.addResult("msg", "你好,这是第一个easyjweb 项目");
        form.addResult("date",new Date());
        return new Page("/hello/index.html");
    }
}*/

3. index.html默认放到 /WEB-INF/views/hello (因为默认要和 helloAction 对应),也可以为action 指定跳转 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Insert title here</title>
</head>
<body>
<div>来自easyjweb 的问候: <font color="red">${msg}</font></div>
<div>时间是 ${date}</div>
</body>
</html>

4 web.xml 配置 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>EasyWeb</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
      <context-param>
        <param-name>defaultActionPackages</param-name>
        <param-value>com.action</param-value>  action  所在路径
    </context-param>
  <servlet>
      <servlet-name>easyjf</servlet-name>
      <servlet-class>com.easyjf.web.ActionServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
      <servlet-name>easyjf</servlet-name>
      <url-pattern>*.ejf</url-pattern>
  </servlet-mapping>
  <!-- 定义字符处理Filter -->
    <filter>
        <filter-name>CharsetFilter</filter-name>
        <filter-class>com.easyjf.web.CharsetFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>ignore</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharsetFilter</filter-name>
        <servlet-name>easyjf</servlet-name>
    </filter-mapping>
</web-app>

部署启动tomcat 访问   http://localhost:8080/helloworld/hello.ejf

 

二 、 ejs  easyjweb+jpa+spring

1. 创建一个 实体类  Customer.java

注意package 

package myapp.domain;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.easyjf.container.annonation.Field;
@Entity
public class Customer {
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE)
    private Long id;
    @Field(name="姓名")
    private String name;
    @Field(name="联系人")
    private String linkName;
    @Field(name="工号")
    private String contractNo;
    @Field(name="地址")
    private String address;
    @Field(name="邮箱")
    private String email;
    @Field(name="主页")
    private String homepage;
    @Field(name="个人简介")
    private String intro;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getLinkName() {
        return linkName;
    }
    public void setLinkName(String linkName) {
        this.linkName = linkName;
    }
    public String getContractNo() {
        return contractNo;
    }
    public void setContractNo(String contractNo) {
        this.contractNo = contractNo;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getHomepage() {
        return homepage;
    }
    public void setHomepage(String homepage) {
        this.homepage = homepage;
    }
    public String getIntro() {
        return intro;
    }
    public void setIntro(String intro) {
        this.intro = intro;
    }
    
}

2.  命令行进入 easyjweb  的bin 目录 执行easyjweb project e:\myapp\ejs –ejs   e:\myapp\ejs  为生成的项目路径 

3. 讲刚才 的Customer.java  文件 放到 生成的项目中 src\main\java 的 myapp.domain  注意要和 类中的package 路径一致

4.进入 项目的 bin目录

easyjweb crud myapp.domain.Customer
../src/main/java/myapp/domain/Customer.java

5. 根据需要 更改 数据库配置文件

database.driverClassName=org.gjt.mm.mysql.Driver
database.url=jdbc:mysql://localhost:3306/myapp?createDatabaseI
fNotExist=true&useUnicode=true&characterEncoding=utf8&autoReconne
ct=true
database.username=root
database.password=123
database.show_sql=true

6. 进入项目的bin 目录下  执行 easyjweb war

打包后放到tomcat 的webapps 下 ,启动tomcat  访问 

http://localhost:8080/ejs/customer.ejf  即可 打开一个对 Customer 的 增删改查 的 页面

 

 

posted on 2014-02-25 11:55  远方的人  阅读(414)  评论(0编辑  收藏  举报

导航