`

bbossgroups 开发系列文章之一 最佳实践

阅读更多
bbossgroups 开发系列文章之-最佳实践

一、概述

所谓最佳实践,就是将采用bbossgroups框架体系开发业务系统的一个最佳的实现方式介绍给大家,本最佳实践包含以下内容:



本文基本功能点如下:

1.bboss mvc框架基础配置
2.bboss mvc控制器配置文件
3.数据库访问组件及sql语句配置文件
4.dao组件管理及注入数据库访问组件
5.业务组件管理及注入dao组件
6.业务开发前台和后台衔接的粘合剂-mvc控制器,注入业务组件
7.附带介绍一下jsp页面的内容
8.bboss mvc请求分派器及url映射配置
9.bboss mvc参数编码过滤器配置

下面详细介绍各个部分。

1.bboss mvc框架基础配置

bboss mvc框架基础配置,主要介绍bboss-mvc.xml文件的配置内容,bboss-mvc.xml是bboss mvc框架的系统配置文件,一般开发人员无需关心。详细介绍请参考博客文章:
《bboss mvc基础配置介绍》http://yin-bp.iteye.com/blog/1139608

2.bboss mvc控制器配置文件

本节介绍mvc框架的一个典型的控制器配置文件的内容:
<properties>
	<property name="/uddi/requester/*.page"
		path:main="/uddi/requester/main.jsp"
		path:add-requester="/uddi/requester/addRequester.jsp"
		path:edit-requester="/uddi/requester/editRequester.jsp"
		path:query-requester="/uddi/requester/RequesterListInfo.jsp"
		class="com.chinacreator.esb.uddi.requester.web.RequesterController"
		f:fuzzySearch="true" f:requesterService="attr:uddi.requester.requesterService"
		f:businessLineService="attr:businessLineService"/>
	
	<property name="uddi.requester.requesterService"
		class="com.chinacreator.esb.uddi.requester.service.impl.RequesterServiceImpl" f:requesterDao="attr:uddi.requester.requesterDao"/>
	
	<property name="uddi.requester.requesterDao"
		class="com.chinacreator.esb.uddi.requester.dao.impl.RequesterDaoImpl" f:executor="attr:uddi.requester.Configexecutor"/>
	
	<property name="uddi.requester.Configexecutor"
		class="com.frameworkset.common.poolman.ConfigSQLExecutor">
		<construction>
			<property value="com/chinacreator/esb/uddi/requester/dao/impl/sqlfile.xml"/>
		</construction>
	</property>
</properties>


从文件内容可以看出控制器配置文件中包含四大部分内容:
1.控制器配置(url映射规则,跳转路径配置,依赖的业务组件配置)
2.业务组件配置(组件及组件依赖的dao组件的配置)
3.dao组件的配置(dao组件及持久层操作对象配置)
4、持久层组件配置(持久层组件及组件引用的sql文件路径配置)

这四部分内容基本上郎阔了当今企业信息系统开发的各个方面,表示层,控制层,业务层,持久层。从这里也可以看出bbossgroups为企业j2ee项目架构提供了完整的解决方案,它通过aop/ioc、mvc将各个层面很好地编织起来,下面的章节会逐个介绍每部分,我们从持久层开始介绍。

3.数据库访问组件及sql语句配置文件
数据库访问组件及注入dao组件,下面的配置声明了一个com.frameworkset.common.poolman.ConfigSQLExecutor组件名字叫uddi.requester.Configexecutor:
    <property name="uddi.requester.Configexecutor"  
        class="com.frameworkset.common.poolman.ConfigSQLExecutor">  
        <construction>  
            <property value="com/chinacreator/esb/uddi/requester/dao/impl/sqlfile.xml"/>  
        </construction>  
    </property> 


dao组件通过名称uddi.requester.Configexecutor来注入和引用该组件。这个持久组件配置了一个sql文件:
com/chinacreator/esb/uddi/requester/dao/impl/sqlfile.xml
非常明显我们将sql语句配置在了一个xml文件中,我们来看看这个文件的内容,其实配置文件中我们用key和value的方式管理sql语句,我们在dao中通过key来引用每个sql语句。在开发环境可以将这个sql文件配置为热加载,即修改后不用重启应用服务器就生效,sqlfile.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<properties>
	<property name="getRequesterDaoListInfo">
		<![CDATA[
			select r.*, o.ORG_NAME as service_requester_org_name from TD_ESB_REQUESTER r left join TD_SM_ORGANIZATION o 
			 on r.SERVICE_REQUESTER_ORG = o.ORG_ID
			 where 1=1
			#if($service_requester_code && !$service_requester_code.equals(""))
			 and SERVICE_REQUESTER_CODE = #[service_requester_code]
			#end
			#if($service_requester_account && !$service_requester_account.equals(""))
			 and SERVICE_REQUESTER_ACCOUNT like #[service_requester_account]
			#end
			#if($service_requester_name && !$service_requester_name.equals(""))
			 and SERVICE_REQUESTER_NAME like #[service_requester_name]
			#end
			#if($service_requester_org && !$service_requester_org.equals(""))
			 and SERVICE_REQUESTER_ORG = #[service_requester_org]
			#end
			
			order by create_time desc
		]]>
	</property>
	<property name="delete">
		<![CDATA[
			delete from TD_ESB_REQUESTER where SERVICE_REQUESTER_ID = ?
		]]>
	</property>
	<property name="findObjectById">
		<![CDATA[
			select r.*, o.ORG_NAME as service_requester_org_name from TD_ESB_REQUESTER r left join TD_SM_ORGANIZATION o 
			 on r.SERVICE_REQUESTER_ORG = o.ORG_ID where SERVICE_REQUESTER_ID = ?
		]]>
	</property>
	<property name="insert">
		<![CDATA[
			insert into TD_ESB_REQUESTER(ADDRESS ,BUSINESS_LINE_CODE ,CONTACT ,CREATE_TIME ,CREATOR ,EMAIL ,MODIFIER ,MODIFY_TIME ,PHONE ,SERVICE_REQUESTER_ACCOUNT ,SERVICE_REQUESTER_DESP ,SERVICE_REQUESTER_ID ,SERVICE_REQUESTER_NAME ,SERVICE_REQUESTER_ORG ,SERVICE_REQUESTER_PASSWORD ,USED_FLAG) values(#[address] ,#[business_line_code] ,#[contact] ,#[create_time] ,#[creator] ,#[email] ,#[modifier] ,#[modify_time] ,#[phone] ,#[service_requester_account] ,#[service_requester_desp] ,#[service_requester_id] ,#[service_requester_name] ,#[service_requester_org] ,#[service_requester_password] ,#[used_flag])
		]]>
	</property>
	<property name="update">
		<![CDATA[
			update TD_ESB_REQUESTER set ADDRESS=#[address] ,BUSINESS_LINE_CODE=#[business_line_code] ,CONTACT=#[contact] ,EMAIL=#[email] ,MODIFIER=#[modifier] ,MODIFY_TIME=#[modify_time] ,PHONE=#[phone] ,SERVICE_REQUESTER_ACCOUNT=#[service_requester_account] ,SERVICE_REQUESTER_DESP=#[service_requester_desp] ,SERVICE_REQUESTER_ID=#[service_requester_id] ,SERVICE_REQUESTER_NAME=#[service_requester_name] ,SERVICE_REQUESTER_ORG=#[service_requester_org] ,SERVICE_REQUESTER_PASSWORD=#[service_requester_password] where SERVICE_REQUESTER_ID = #[service_requester_id]
		]]>
	</property>
	<property name="updateFlag">
		<![CDATA[
			update TD_ESB_REQUESTER set USED_FLAG = #[used_flag], Modifier = #[modifier], Modify_time = #[modify_time] 
			where SERVICE_REQUESTER_ID = #[service_requester_id]
		]]>
	</property>	
	
</properties>


另外文件中的sql语句包含了模板sql(带#[service_requester_id]形态变量的sql语句)、动态sql(带逻辑判断的sql,#if()#end),预编译sql(带?号占位符的sql),最终持久层全部采用预编译方式执行这些sql语句。


需要说明的是,bbossgroups 3.x 中sql文件的刷新机制配置在bboss-aop.jar的aop.properties文件中,为<0时,将屏蔽刷新功能:
sqlfile.refresh_interval=5000

4.dao组件管理及注入数据库访问组件
dao组件管理及注入数据库访问组件 本节内容介绍dao组件的配置和代码,以及其如何通过注入方式引用上节中配置的持久层组件

uddi.requester.Configexecutor

首先看配置:
<property name="uddi.requester.requesterDao"
		class="com.chinacreator.esb.uddi.requester.dao.impl.RequesterDaoImpl" f:executor="attr:uddi.requester.Configexecutor"/>


配置非常简单,指定了dao组件的名字uddi.requester.requesterDao(我们将通过这个名称将dao组件注入到业务组件中),实现类
com.chinacreator.esb.uddi.requester.dao.impl.RequesterDaoImpl
以及指定了属性executor的值attr:uddi.requester.Configexecutor,这是一个引用,引用uddi.requester.Configexecutor对应的数据库组件。

然后我们看看dao组件的实现类,从中我们可以看出dao中的方法是怎样通过ConfigSQLExecutor来操作访问数据库的:

package com.chinacreator.esb.uddi.requester.dao.impl;



import java.util.UUID;

import com.chinacreator.esb.datareuse.util.Constants;
import com.chinacreator.esb.uddi.requester.dao.RequesterDao;
import com.chinacreator.esb.uddi.requester.entity.Requester;
import com.frameworkset.common.poolman.ConfigSQLExecutor;
import com.frameworkset.util.ListInfo;

public class RequesterDaoImpl implements RequesterDao {
	
	private static String dbName = Constants.DATAREUSE_DBNAME;
	
	private ConfigSQLExecutor executor;
	

	public ConfigSQLExecutor getExecutor() {
		return executor;
	}

	public void setExecutor(ConfigSQLExecutor executor) {
		this.executor = executor;
	}

	public ListInfo getRequesterDaoListInfo(String sortKey, boolean desc,
			long offset, int pagesize, Requester queryCondObj) throws Exception {
		// TODO Auto-generated method stub
		return executor.queryListInfoBeanWithDBName(Requester.class, 
				dbName, "getRequesterDaoListInfo", offset, pagesize, queryCondObj);
	}

	public void delete(String id) throws Exception {
		// TODO Auto-generated method stub
		String delId = (String)id;
		executor.deleteByKeysWithDBName(dbName, "delete", delId);

	}

	public Requester findObjectById(String id) throws Exception {
		// TODO Auto-generated method stub
		String findId = (String)id;
		Requester requester = executor.queryObjectWithDBName(Requester.class, dbName, "findObjectById", findId);
		return requester;
	}

	public void insert(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		if(obj.getService_requester_id()== null||obj.getService_requester_id().equals("")){
			obj.setService_requester_id(UUID.randomUUID().toString());}
		executor.insertBean(dbName, "insert", obj);
	}

	public void update(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		executor.updateBean(dbName, "update", obj);
	}
	
	public void updateFlag(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		executor.updateBean(dbName, "updateFlag", obj);
	}

}


其中我们可以看到dao在利用executor执行数据库增删改查操作时,每个操作的参数分为3部分,一部分时dbName,指定操作针对poolman.xml文件中配置的数据源datasource的名称dbname的值,第二部分就是我们在sql文件中配置的sql语句对应的名称,第三部分就是相应操作需要的业务参数。其实还有可选的一部分就是分页参数,例如
return executor.queryListInfoBeanWithDBName(Requester.class,
dbName, "getRequesterDaoListInfo", offset, pagesize, queryCondObj);
中的offset,pagesize两个分别代表了分页查询的记录起始位置和每页最多返回的记录数。

补充一下dbname的在数据源配置文件poolman.xml文件(该文件一般部署于classes目录下)中是怎么配置的:
<?xml version="1.0" encoding="gb2312"?>

<poolman>

  

<datasource>

    <dbname>bspf</dbname>
	<loadmetadata>false</loadmetadata>
    <jndiName>jdbc/mysql-ds</jndiName>
    <driver>oracle.jdbc.driver.OracleDriver</driver>
	
     <url>jdbc:oracle:thin:@172.16.25.219:1521/orcl</url>      
    <username>esb</username>
    <password>esb</password>

   .........

  </datasource>
  
  <datasource external="true">
    <dbname>datareuse</dbname>
    <externaljndiName>jdbc/mysql-ds</externaljndiName>
	<showsql>true</showsql>
  </datasource>
  
</poolman>


更加详细的配置请参考文章《bbossgroups持久层框架数据源配置文件实例


5.业务组件管理及注入dao组件

业务组件管理及注入dao组件,本节讲解业务组件配置部分的内容:
<property name="uddi.requester.requesterService"
		class="com.chinacreator.esb.uddi.requester.service.impl.RequesterServiceImpl" f:requesterDao="attr:uddi.requester.requesterDao"/


业务组件配置和dao组件配置差不多,首先是业务组件的名字uddi.requester.requesterService(该名称用来作为控制器引用业务组件的名称),组件的实现类com.chinacreator.esb.uddi.requester.service.impl.RequesterServiceImpl,该业务组件引用的dao组件requesterDao,attr:uddi.requester.requesterDao,这里引用的就是上节中介绍的dao组件,我们可以看看业务组件是怎么通过dao来完成具体的业务操作的:
package com.chinacreator.esb.uddi.requester.service.impl;

import com.chinacreator.esb.uddi.requester.dao.RequesterDao;
import com.chinacreator.esb.uddi.requester.entity.Requester;
import com.chinacreator.esb.uddi.requester.service.RequesterService;
import com.frameworkset.util.ListInfo;

public class RequesterServiceImpl implements RequesterService {
	
	private RequesterDao requesterDao;	
	
	
	public RequesterDao getRequesterDao() {
		return requesterDao;
	}

	public void setRequesterDao(RequesterDao requesterDao) {
		this.requesterDao = requesterDao;
	}
	

	public void insertRequester(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		requesterDao.insert(obj);
	}

	public void updateRequester(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		requesterDao.update(obj);
	}
	
	public void updateRequesterFlag(Requester obj) throws Exception {
		// TODO Auto-generated method stub
		requesterDao.updateFlag(obj);
	}

	public void deleteRequester(String id) throws Exception {
		// TODO Auto-generated method stub
		requesterDao.delete(id);
	}

	public Requester findRequesterById(String id) throws Exception {
		// TODO Auto-generated method stub
		return requesterDao.findObjectById(id);
	}

	public ListInfo getRequseterListInfo(String sortKey, boolean desc,
			long offset, int pagesize, Requester req) throws Exception {
		// TODO Auto-generated method stub
		return requesterDao.getRequesterDaoListInfo(sortKey, desc, offset, pagesize, req);
	}

}

业务组件的内容再简单不过,这里无需多说,我们直接看下节mvc如何使用业务组件来完成前端请求处理,并调整到结果处理页面的。

6.业务开发前台和后台衔接的粘合剂-mvc控制器,注入业务组件

业务开发前台和后台衔接的粘合剂-mvc控制器 ,介绍控制器是如何承前启后地完成一个完整的业务处理请求的。

首先我们来看看mvc控制的的配置部分:
	<property name="/uddi/requester/*.page"
		path:main="/uddi/requester/main.jsp"
		path:add-requester="/uddi/requester/addRequester.jsp"
		path:edit-requester="/uddi/requester/editRequester.jsp"
		path:query-requester="/uddi/requester/RequesterListInfo.jsp"
		class="com.chinacreator.esb.uddi.requester.web.RequesterController"
		f:fuzzySearch="true" f:requesterService="attr:uddi.requester.requesterService"
		f:businessLineService="attr:businessLineService"/>

这个配置非常简洁(bbossgroups aop框架配置简洁的优良特质得以充分体现),也非常直观,配置可以大致分为以下部分:
1.控制url映射规则/uddi/requester/*.page,这个规则可以让前端请求精确匹配到具体的控制器,*代表将控制器实现类中的所有业务方法开放接收前台提交请求。
2.控制方法跳转地址配置
path:main="/uddi/requester/main.jsp"
		path:add-requester="/uddi/requester/addRequester.jsp"
		path:edit-requester="/uddi/requester/editRequester.jsp"
		path:query-requester="/uddi/requester/RequesterListInfo.jsp"

我们把控制器节点上的path:前缀的属性当成是跳转页面地址配置,而把f:开头的属性作为控制组件的属性注入参数来处理
3.控制器类配置
class="com.chinacreator.esb.uddi.requester.web.RequesterController"
4.需要注入到控制器的业务组件和其他属性配置:
f:fuzzySearch="true" f:requesterService="attr:uddi.requester.requesterService"
		f:businessLineService="attr:businessLineService"


好,我们来具体看看控制器类得代码吧(辛苦了,呵呵),控制器类得实现也很简单:
package com.chinacreator.esb.uddi.requester.web;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.frameworkset.util.annotations.PagerParam;
import org.frameworkset.util.annotations.RequestParam;
import org.frameworkset.web.servlet.ModelAndView;
import org.frameworkset.web.servlet.ModelMap;

import com.chinacreator.esb.AjaxResponseBean;
import com.chinacreator.esb.DropListEntity;
import com.chinacreator.esb.datareuse.businessline.service.BusinessLineService;
import com.chinacreator.esb.datareuse.util.Constants;
import com.chinacreator.esb.tools.StringTool;
import com.chinacreator.esb.uddi.requester.entity.Requester;
import com.chinacreator.esb.uddi.requester.service.RequesterService;
import com.chinacreator.security.AccessControl;
import com.frameworkset.util.ListInfo;

public class RequesterController {
	
	private RequesterService requesterService;
	private BusinessLineService businessLineService;
	
	
	public BusinessLineService getBusinessLineService() {
		return businessLineService;
	}

	public void setBusinessLineService(BusinessLineService businessLineService) {
		this.businessLineService = businessLineService;
	}

	public RequesterService getRequesterService() {
		return requesterService;
	}

	public void setRequesterService(RequesterService requesterService) {
		this.requesterService = requesterService;
	}
	
	private boolean fuzzySearch;
	
	
	public boolean isFuzzySearch() {
		return fuzzySearch;
	}

	public void setFuzzySearch(boolean fuzzySearch) {
		this.fuzzySearch = fuzzySearch;
	}

	/*
	 * 进入主页面
	 */
	
	public ModelAndView main(){
		ModelAndView view = new ModelAndView("path:main");
		return view;
	}
	

	
	/**
	 * 将字符串转成utf-8编码
	 * @param str
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String encode(String str) throws UnsupportedEncodingException {
		return java.net.URLEncoder.encode(str, "utf-8");
	}

	/**
	 * 转成json对象,直接用response的print方法
	 * @param response
	 * @param ajaxResponseBean
	 * @throws IOException
	 */
	private void write(HttpServletResponse response,
			AjaxResponseBean ajaxResponseBean) throws IOException {
		ObjectMapper objectMapper = new ObjectMapper();
		String responseText = objectMapper.writeValueAsString(ajaxResponseBean);
		response.getWriter().print(responseText);
	}

	/**
	 * 取得当前用户的ID
	 * @param request
	 * @param response
	 * @return
	 */
	private String getUserId(HttpServletRequest request,
			HttpServletResponse response) {
		AccessControl accessControl = AccessControl.getInstance();
		accessControl.checkAccess(request, response);
		return accessControl.getUserID();
	}
	
	/*
	 * 查询请求方数据
	 */
	
	public ModelAndView queryRequester(Requester requester,
			@PagerParam(name = PagerParam.SORT)String sortKey,
			@PagerParam(name = PagerParam.DESC)boolean desc,
			@PagerParam(name = PagerParam.OFFSET)long offset,
			@PagerParam(name = PagerParam.PAGE_SIZE)int pagesize,
			ModelMap model){
	
		String srAccount = requester.getService_requester_account();
		String srName = requester.getService_requester_name();

		
		if (isFuzzySearch()){
			requester.setService_requester_account(StringTool.buildFuzzySearchString(srAccount, false));
			requester.setService_requester_name(StringTool.buildFuzzySearchString(srName, false));
		}	
		ListInfo listinfo = null;
		try {
			listinfo = requesterService.getRequseterListInfo(sortKey, desc, offset, pagesize, requester);
			listinfo.setMaxPageItems(pagesize);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ModelAndView view = new ModelAndView("path:query-requester", "listinfo", listinfo);
		return view;
		
	}
	
	/*
	 * 进入新增请求方页面
	 */
	
	public ModelAndView addRequester(Requester requster, ModelMap model)  throws Exception {
		
		addBusinessLineDropList(model);
		ModelAndView view = new ModelAndView("path:add-requester");
		return view;
	}
	
	
	
	public void createRequester(Requester requester,
			@RequestParam(name = "service_requester_id") String service_requester_id,
			ModelMap model, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		AjaxResponseBean ajaxResponseBean = new AjaxResponseBean();
		String userId = this.getUserId(request, response);

		
		try {			
			Date date = new Date();
			Timestamp timestamp = new Timestamp(date.getTime());
			requester.setCreator(userId);
			requester.setCreate_time(timestamp);
			requester.setModifier(userId);
			requester.setModify_time(timestamp);
			//账号创建后默认为启用
			requester.setUsed_flag(Constants.UsedBoolean.TRUE.getValue());
			requesterService.insertRequester(requester);

			ajaxResponseBean.setStatus("success");
			ajaxResponseBean.setData(requester.getService_requester_id());		
		} catch (Exception e) {
			e.printStackTrace();
			ajaxResponseBean.setStatus("error");
			if (e.getMessage() != null && e.getMessage().indexOf("unique") > 0) {
				ajaxResponseBean.setData(encode("账号已存在!"));
			} else {
				throw e;
			}
		}

		write(response, ajaxResponseBean);
	}
	
	
	/*
	 * 进入修改请求方页面
	 */
	
	public ModelAndView editRequester(@RequestParam(name = "service_requester_id")String service_requester_id,
			ModelMap model) throws Exception{		
		addBusinessLineDropList(model);
		
		Requester obj = requesterService.findRequesterById(service_requester_id);
		
		ModelAndView view = new ModelAndView("path:edit-requester", "obj", obj);
		view.addObject("close", model.get("close"));
		return view;
	}
	
	private void addBusinessLineDropList(ModelMap model) throws Exception{
		List<DropListEntity> businessLines = businessLineService.getBusinessLineDropList();
		model.addAttribute("businessLines", businessLines);
	}
	

	public void updateRequester(Requester requester,
			@RequestParam(name = "service_requester_id") String service_requester_id,
			ModelMap model, HttpServletRequest request,
			HttpServletResponse response) throws Exception {		
		String userId = this.getUserId(request, response);
		AjaxResponseBean ajaxResponseBean = new AjaxResponseBean();
		try {
			Date date = new Date();
			Timestamp timestamp = new Timestamp(date.getTime());
			requester.setModifier(userId);
			requester.setModify_time(timestamp);
			requesterService.updateRequester(requester);		
			
			ajaxResponseBean.setStatus("success");		
		} catch (Exception e) {
			e.printStackTrace();			
			throw e;			
		}

		write(response, ajaxResponseBean);	
	}
	
	
	public void updateRequesterFlag(Requester requester,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		String userId = this.getUserId(request, response);
		AjaxResponseBean ajaxResponseBean = new AjaxResponseBean();
		try {
			Date date = new Date();
			Timestamp timestamp = new Timestamp(date.getTime());
			requester.setModifier(userId);
			requester.setModify_time(timestamp);
			requesterService.updateRequesterFlag(requester);	
			
			ajaxResponseBean.setStatus("success");
		} catch (Exception e) {
			e.printStackTrace();			
			throw e;			
		}

		write(response, ajaxResponseBean);		
	}
	
	
	/*
	 * 启用请求方
	 */
	public void startRequester(Requester requester,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		requester.setUsed_flag(Constants.UsedBoolean.TRUE.getValue());
		updateRequesterFlag(requester, request, response);
	}
	
	/*
	 * 停用请求方
	 */
	public void stopRequester(Requester requester,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		requester.setUsed_flag(Constants.UsedBoolean.FALSE.getValue());
		updateRequesterFlag(requester, request, response);
	}
	


	public void deleteRequester(
			@RequestParam(name = "service_requester_id") String service_requester_id,
			HttpServletResponse response) throws Exception {
		AjaxResponseBean ajaxResponseBean = new AjaxResponseBean();
		try {
			requesterService.deleteRequester(service_requester_id);
			ajaxResponseBean.setStatus("success");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxResponseBean.setStatus("error");
			if (e.getMessage() != null && e.getMessage().indexOf("constraint") > 0) {
				ajaxResponseBean.setData(encode("存在关联数据,不能删除!"));
			} else {
				throw e;
			}
		}

		write(response, ajaxResponseBean);
	}
	
}



7.附带介绍一下jsp页面的内容
附带介绍一下jsp页面的内容 ,通过这个页面内容我们可以看出视图层是如何提交请求到控制器的,以及控制器处理完请求后怎么把处理结果反馈给视图层的。
jsp页面代码片段,其它部分全部省略掉,js提交请求到控制 器,然后通过回调将响应添加到div的代码片段:
$(document).ready(function(){
queryRequester();	
}
function queryRequester(){					
				$('#queryForm').form('submit', {
				    "url": "queryRequester.page",
				    onSubmit:function(){			
						//显示遮罩							
						blockUI();	
				    },
				    success:function(responseText){	
				    	//去掉遮罩	
						unblockUI();				
						$("#RequesterListInfoContainer").html(responseText);				    			    					    											
				    }
				});	
			}		




jsp代码片段:
<div>
		<form id="theForm" method="post">
			
			
					<tr>
						<td nowrap="nowrap" class="c2">
							账号:
						</td>
						<td width="30%">
							<input class="input_default  easyui-validatebox" 
								name="service_requester_account" type="text" validType="Caracters"
								required="true" missingMessage="必填!" />
						</td>
						
						<td nowrap="nowrap" class="c2">
							密码:
						</td>
						<td width="30%">
							<input class="input_default  easyui-validatebox" 
								name="service_requester_password" type="password" validType="Caracters"
								required="true" missingMessage="必填!" />
						</td>
					</tr>
					
					
				</tbody>

				<tfoot>
					<tr>
						<td align="center" colspan="4">
							<button type="submit" class="button">
									保存
							</button>
						
						</td>
					</tr>
				</tfoot>
			</table>
			
		</form>		

		<div id="RequesterListInfoContainer">
		</div>


呵呵,相信熟悉jquery的朋友对上述代码并不陌生。
8.bboss mvc请求分派器及url映射配置

本节介绍bboss mvc请求分派器、url映射规则以及mvc配置文件在web.xml文件中的配置方法:
<servlet>
        <servlet-name>mvc</servlet-name>
        <servlet-class>org.frameworkset.web.servlet.DispatchServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/conf/uddi/bboss-*.xml,/WEB-INF/conf/datareuse/bboss-*.xml,/WEB-INF/conf/commons/bboss-*.xml,/WEB-INF/conf/bboss-*.xml</param-value>
        </init-param>
       
	<load-on-startup>0</load-on-startup>
    </servlet>
	 <servlet-mapping>
        <servlet-name>mvc</servlet-name>
        <url-pattern>*.page</url-pattern>
    </servlet-mapping>


9.bboss mvc参数编码过滤器配置

本节是本文的最后一节,介绍bboss mvc参数编码过滤器在web.xml文件中的配置:
   <filter>
    <filter-name>CharsetEncoding</filter-name>
    <filter-class>com.frameworkset.common.filter.CharsetEncodingFilter</filter-class>
    <init-param>
      <param-name>RequestEncoding</param-name>
      <param-value>GBK</param-value>
    </init-param>
    <init-param>
      <param-name>ResponseEncoding</param-name>
      <param-value>GBK</param-value>
    </init-param>
    <init-param>
      <param-name>mode</param-name>
      <param-value>0</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharsetEncoding</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>CharsetEncoding</filter-name>
    <url-pattern>*.do</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>CharsetEncoding</filter-name>
    <url-pattern>*.frame</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>CharsetEncoding</filter-name>
    <url-pattern>*.page</url-pattern>
  </filter-mapping>






分享到:
评论
3 楼 yin_bp 2012-06-29  
另外,也可以参考bboss培训文档中关于事务部分的介绍:
http://sourceforge.net/projects/bboss/files/bbossgroups-3.4/bbossgroups%20training.ppt/download
2 楼 yin_bp 2012-06-29  
liuxuehua12 写道
标哥,你没讲在业务逻辑层处理进行事务管理啊?默认的事务都是dao层处理的吧


默认环境是没有事务的,事务可以放到控制层,业务层,dao层,bboss没有严格的要求,如果要开启事务请参考文章:

http://yin-bp.iteye.com/blog/769026
http://yin-bp.iteye.com/blog/1487101
http://yin-bp.iteye.com/blog/727701

bboss持久层SQLExecutor和ConfigSQLExecutor组件的介绍文章分别为:
http://yin-bp.iteye.com/blog/1035991
http://yin-bp.iteye.com/blog/1112997

bboss的各种数据库操作组件都可以涵盖在事务控制代码中:
TransactionManager tm = new TransactionManager();
			try {
				tm.begin(tm.RW_TRANSACTION);
                              //db操作
                               tm.commit();
			} catch (Throwable e) {
				try {
					tm.rollback();
				} catch (RollbackException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				e.printStackTrace();
			}

或者
TransactionManager tm = new TransactionManager();
			try {
				tm.begin();
                              //db操作
                               tm.commit();
			} catch (Throwable e) {
				try {
					tm.rollback();
				} catch (RollbackException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				e.printStackTrace();
			}
1 楼 liuxuehua12 2012-06-29  
标哥,你没讲在业务逻辑层处理进行事务管理啊?默认的事务都是dao层处理的吧

相关推荐

    bbossgroups 3.0 培训教程

    本教程将围绕bbossgroups 3.0版本,深入讲解其核心概念、使用方法以及最佳实践。 首先,我们要理解bbossgroups的核心设计理念。它基于模块化架构,使得开发者可以根据项目需求选择合适的组件,避免了不必要的性能...

    bbossgroups 3.1SQLExecutor组件ap使用实例

    在Java开发中,bbossgroups 3.1框架提供了一个名为SQLExecutor的组件,用于简化数据库操作。这个组件提供了一种高效的批处理和单条SQL执行的方式,它基于Apache License 2.0开源,允许开发者在遵守相应条款的情况下...

    Bbossgroups体系架构.ppt

    Bbossgroups是一个全面的、开源的企业级应用框架,旨在简化Java开发过程,提供一套完整的系统构建解决方案。它的核心设计理念是模块化和可扩展性,使得开发者能够灵活地搭建各种复杂的企业级系统。本文将深入探讨...

    bbossgroups 3.1培训教程.ppt

    bbossgroups 3.1是一个企业级J2EE开发框架,自2005年以来不断发展和完善,旨在提供高效、稳定的开发工具和解决方案。本教程将深入介绍bbossgroups 3.1的主要特性、发展历程以及其在企业项目中的应用。 ### 发展历程...

    bbossgroups 3.0 发布,国内首款集

    bbossgroups 3.0作为一款集成多项关键技术的企业级J2EE开发框架,不仅大大提升了开发效率,还极大地降低了系统的复杂度。对于正在寻找全面且成熟的Java企业应用开发解决方案的团队来说,这无疑是一个值得考虑的选择...

    企业级J2EE开源框架bboss

    BBoss(全称为bbossgroups)是一个专为企业级J2EE应用设计的开源框架,它为Java开发者提供了一系列强大的工具和服务,以简化Web应用程序的开发过程。该框架旨在提高开发效率,降低维护成本,同时保持高度的灵活性和...

    2013年度中国优秀开源项目列表

    12. bboss:bbossgroups是首个集成AOP、MVC、持久层、JSP标签库、分布式RPC服务和序列化组件的JavaEE企业级开发框架。 13. BeeFramework:BeeFramework是iOS平台的快速开发框架,特点包括易学易用、组件丰富,提供...

    bboss mvc 通过jsonp实现跨站跨域远程访问

    标签中的“源码”意味着可能需要查看bboss mvc框架的源代码来了解其内部实现机制,而“工具”可能指的是bboss mvc框架本身作为一个开发工具,帮助开发者实现上述功能。 提供的压缩包文件"bbossgroups 框架培训教程....

    基于Java和Shell的bboss session framework跨域集群节点会话共享与监控设计源码

    该项目是一款基于Java和Shell语言的bboss session framework设计源码,专注于实现跨域集群节点之间的会话共享,并具备良好的会话监控和数据统计功能。该框架包含222个文件,包括164个Java源文件、14个XML配置文件、6...

    bboss-elastic-tran:bboss 数据同步工具

    弹性Tran老板数据交换模块使用文档: : Bboss是一个很好的Elasticsearch Java Rest客户端。 它运行并访问像mybatis这样的elasticsearch来关联数据库。环境要求JDK要求:JDK 1.7+ Elasticsearch版本要求:1.X,2.X,5...

    java版地图源码-bboss-elasticsearch:最好的elasticsearch高级javarest客户端api-----bbos

    是一个很好的 elasticsearch Java rest 客户端。 它以类似于mybatis的方式操作和访问elasticsearch。 环保要求 JDK 要求:JDK 1.7+ Elasticsearch 版本要求:1.X,2.X,5.X,6.X,7.x,+ Spring Booter 1.x,2.x,+ bbos 降...

Global site tag (gtag.js) - Google Analytics