手机开发之后台开发认识

后台的开发需要支持不同系统手机客户端的开发(包括塞班、安卓、IOS)系统提供后台接口,由于客户来解析接口提供的数据格式(XML、Json)目前采用XML格式返回。
后台组织上面可以采用简单的JSP格式,JSP直接访问后台的服务层,省掉传统MVC中的C层,直接是MV层,视图层直接访问管理层得到相应的数据返回,并组织成客户端定义的数据格式!

例如 下面的JSP代码
<%@page import="com.migu.util.ConfigurationUtil"%>
<%@ page language="java" contentType="text/xml;charset=UTF-8"%><?xml version="1.0" encoding="UTF-8" ?>
<%@page import="com.migu.model.PsAlbumExample"%>
<%@page import="com.migu.model.PsAlbum"%>
<%@page import="com.migu.service.PsAlbumServiceImpl"%>
<%@page import="java.util.List"%>
<%@page import="com.migu.model.PageBean"%>
<%@page import="java.math.BigDecimal"%>
<%@page
	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="com.migu.service.PsUserInvServiceImpl"%>
<%@page import="com.migu.model.PsUserInv"%>
<%@page import="java.util.Date"%>
<%@page import="com.migu.model.PsUserInvExample"%>
<%@taglib uri="oscache" prefix="cache"%>
<rsp> <%
	int pageSize = 10;//默认size
	int pageNo = 1;//默认页码
	String pagesize = request.getParameter("pagesize");
	String pageno = request.getParameter("pageno");
	if(null!=pageno) pageNo = Integer.parseInt(pageno);
	if(null!=pagesize) pageSize = Integer.parseInt(pagesize);
	WebApplicationContext context =(WebApplicationContext)WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	PsAlbumServiceImpl psAlbumServiceImpl = (PsAlbumServiceImpl)context.getBean("psAlbumServiceImpl");
	PsUserInvServiceImpl psUserInvServiceImpl = (PsUserInvServiceImpl)context.getBean("psUserInvServiceImpl");
	String singerid = request.getParameter("singerid");
	String mobile=request.getHeader("x-up-calling-line-id");
	//插入用户的访问专辑的日期记录
	if(null!=singerid&&null!=mobile){
	PsUserInvExample e=new PsUserInvExample();
	e.createCriteria().andInvArtistIdEqualTo(Long.parseLong(singerid)).andInvUidEqualTo(BigDecimal.valueOf(Long.parseLong(mobile)));
	List<PsUserInv> ll=psUserInvServiceImpl.selectByExample(e);
	PsUserInv pui=new PsUserInv();
    pui.setInvAlbumTime(new Date());
	pui.setInvArtistId(Long.parseLong(singerid));
	pui.setInvUid(BigDecimal.valueOf(Long.parseLong(mobile)));
	//如果用户已经访问了歌手的有其它类型(如图片),则进行更新
	if(ll.size()>0){
	pui.setInvId(ll.get(0).getInvId());
	psUserInvServiceImpl.updateByPrimaryKeySelective(pui);
	}
	//插入访问日期记录
	else{
    psUserInvServiceImpl.insert(pui);

	}}
	if(null!=singerid){
	PsAlbumExample example = new PsAlbumExample();
	example.createCriteria().andAlbArtidEqualTo(BigDecimal.valueOf(Long.parseLong(singerid)));
	example.setOrderByClause("ALB_ID");
	/*OSCACHE缓存配置START*/
	StringBuffer cache_key = request.getRequestURL().append("_").append(singerid).append("_").append(pageno).append("_").append(pagesize);
	
%> <cache:cache time="180" key="<%=cache_key.toString()%>" refresh="false">
	<%
	/*OSCACHE缓存配置END*/
	PageBean pageBean  =psAlbumServiceImpl.queryByPage( pageNo, pageSize,example);
	List<PsAlbum> list =pageBean.getResultList();
%>
	<pagecount><%=pageBean.getPageCount()%></pagecount>
	<list> <%
	for(PsAlbum obj:list){
		if(null!=obj){
		 String pic_path = "";
		 try{
			  pic_path = ConfigurationUtil.getFullPicPath(obj.getAlbPicPath());
			  if(null!=pic_path&&pic_path.indexOf(".")>0) pic_path = pic_path.substring(0,pic_path.lastIndexOf("."))+"_150x150.jpg";
			  }catch(Exception e){
				  
			  }
%> <item> <id><%=obj.getAlbId()%></id> <img><%=ConfigurationUtil.filterNull(pic_path)%></img>
	<title><%=ConfigurationUtil.filterNull(obj.getAlbName())%></title> </item> <%		
	}
}
%> </list>
</cache:cache> <%}%> </rsp>


实现的是返回给客户端的专辑列表!

你可能感兴趣的:(java,xml,mobile)