最近才有時間處理此事,將此設想應用到現實應用程序中。 下面從兩個方面講解如何開發與發布。
示例:講解java+php 開發模式,以菜單管理為例。
示例如下:
一:java 結構代碼
java開發結構圖如下:
java 程序代碼請看在下面上傳文件,由於上傳文件不能大於2M,所以用到的lib 沒有上傳,如需求,可留郵箱給我,我發給大家。
注:PHP和Java各有其語言內部定義的數據類型,當PHP數據傳送到Java,或Java數據傳送到PHP時,LAJP在內部自動地、准確地對他們進行轉換,程序員無需進行任何的解碼工作
二:java 應用程序發布
將編譯後的文件放到LAJP 目錄下:我的文件目錄: E:\lajp-10.05\test_service\ecard
如下圖所示:
三:php 結構代碼
<?php
class Menu extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('system/menu_model');
}
function index(){
$condition = array();
$condition['menu_id'] = $this->uri->segment(4,0);
$condition['path'] = $this->input->post('path');
$condition['start'] = $this->input->post('start');
$condition['id'] = $this->input->post('id');
$condition['order'] = $this->input->post('order');
$condition['isfresh'] = $this->input->post('isfresh');
$condition['visible'] = $this->input->post('visible');
$condition['defaultselect'] = $this->input->post('defaultselect');
$condition['name'] = $this->input->post('name');
$condition['parentid'] = $this->input->post('parent_id');
$condition['numPerPage'] = $this->input->post('numPerPage') ? $this->input->post('numPerPage') : 20;
$condition['orderField'] = $this->input->post('orderField') ? $this->input->post('orderField') : 'SMT_PARENT_ID';
$condition['pageNum'] = $this->input->post('pageNum') ? $this->input->post('pageNum') : 1;
$data = array();
$allmenus = $this->menu_model->getMenus();
$this->load->library('smart_tree');
$options = array(
'index' => 1,
'type' => 0,
'self' => 1,
'hreffromdb' => 0,
'relfromdb' => 0,
'rel' => 'system/menu/index',
'href' => 'system/menu/index/',
'hrefuseid' => 1,
'title' => '菜單管理'
);
$data['allmenus'] = $this->smart_tree->getTrees($allmenus, $options);
$data['menus'] = $this->menu_model->getMenusVoByCondition($condition);
$data['total'] = $this->menu_model->getCount($condition);
$data['condition'] = $condition;
$this->load->view('system/menu/index.phtml', $data);
}
function add(){
$data['menus'] = $this->menu_model->getMenus();
$this->load->view('system/menu/add.phtml',$data);
}
function insert(){
$vo = newObject('ecard_sys_menus_vo_MenusVo');
$vo->name = (string)$this->input->post('name');
$vo->parentid = (int)$this->input->post('parent_id');
$vodefaultselect = (int)$this->input->post('defaultselect');
$vo->visible = (int)$this->input->post('visible');
$vo->isfresh = (int)$this->input->post('isfresh');
$vo->desc = (string)$this->input->post('desc');
$vo->path = (string)$this->input->post('path');
$vo->start = (int)$this->input->post('start');
$vo->order = (int)$this->input->post('order');
$vo->cuser = 1;
if($this->menu_model->insert($vo)){
$reback = array("statusCode"=>"200","message" => "添加成功","navTabId" => "system/menu/index", "callbackType" => "closeCurrent","forwardUrl" => "" );
}else{
$reback = array("statusCode"=>"300","message" => "添加失敗","navTabId" => "", "callbackType" => "","forwardUrl" => "" );
}
echo json_encode($reback);
}
function edit(){
$menu_id = $this->uri->segment(4,0) or exit('菜單不存在');
$data['menu'] = $this->menu_model->getMenusVoById($menu_id) or exit('菜單不存在');
$data['pmenu'] = $this->menu_model->getMenusVoById($data['menu']['parentid']) or exit('菜單不存在');
$this->load->view('system/menu/edit.phtml',$data);
}
function update(){
$vo = newObject('ecard_sys_menus_vo_MenusVo');
$vo->id = (int)$this->input->post('id');
$vo->name = (string)$this->input->post('name');
$vo->path = (string)$this->input->post('path');
$vo->parentid = (int)$this->input->post('parent_id');
$vo->order = (int)$this->input->post('order');
$vo->start = (int)$this->input->post('start');
$vo->defaultselect = (int)$this->input->post('defaultselect');
$vo->visible = (int)$this->input->post('visible');
$vo->isfresh = (int)$this->input->post('isfresh');
$vo->desc = (string)$this->input->post('desc');
$vo->uuser = 1;
if($this->menu_model->update($vo)){
$reback = array("statusCode"=>"200","message" => "編輯成功","navTabId" => "system/menu/index", "callbackType" => "closeCurrent","forwardUrl" => "" );
}else{
$reback = array("statusCode"=>"300","message" => "編輯失敗","navTabId" => "", "callbackType" => "","forwardUrl" => "" );
}
echo json_encode($reback);
}
function delete(){
$ids = $this->input->post('ids');
if(!$ids){
$ids = $this->uri->segment('4',0) or exit('缺少參數');
}
if($this->menu_model->deletes($ids)){
$reback = array("statusCode"=>"200","message" => "刪除成功","navTabId" => "", "callbackType" => "","forwardUrl" => "" );
}else{
$reback = array("statusCode"=>"300","message" => "刪除失敗","navTabId" => "", "callbackType" => "","forwardUrl" => "" );
}
echo json_encode($reback);
}
function search(){
$data = array();
$data['menus'] = $this->menu_model->getMenus();
$this->load->view('system/menu/search.phtml',$data);
}
function tree(){
$menus = $this->menu_model->getMenus();
$this->load->library('smart_tree');
$data['menus'] = $this->smart_tree->getTrees($menus,array('index'=>1,'type'=>0,'self'=>1,'hreffromdb'=>0));
$this->load->view('system/menu/tree',$data);
}
}
四:應用展現
java程序開發完成後,並將編譯後程序發布到lajp文件目錄下後,點擊E:\lajp-10.05下的run-socket.bat 運行程序,如下圖所示:
啟動界面:
php界面展現如下:
應用界面
本文出自 “吹牛皮拉潛艇推火車日飛機” 博客