当前位置:  编程技术>移动开发
本页文章导读:
    ▪20120306第一回学习笔记        20120306第一次学习笔记 学习笔记的开始,坚持住。 ......
    ▪ 关于跨进程使用 getSharedPreferences 的有关问题        关于跨进程使用 getSharedPreferences 的问题   public static final int MODE_MULTI_PROCESS Since: API Level 11 SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences inst.........
    ▪ 自个儿写的分页查询的步骤代码       自己写的分页查询的步骤代码 第一步:前台页面(核心代码)  主要是当前的页数,因为是第一次嘛,肯定是从第一页开始的。查询出来的页面我用的是iframe方式呈现。其他地方的代码不用.........

[1]20120306第一回学习笔记
    来源: 互联网  发布时间: 2014-02-18
20120306第一次学习笔记
学习笔记的开始,坚持住。

    
[2] 关于跨进程使用 getSharedPreferences 的有关问题
    来源: 互联网  发布时间: 2014-02-18
关于跨进程使用 getSharedPreferences 的问题

 

public static final int MODE_MULTI_PROCESS
Since: API Level 11

SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process. This behavior is sometimes desired in cases where the application has multiple processes, all writing to the same SharedPreferences file. Generally there are better forms of communication between processes, though.

This was the legacy (but undocumented) behavior in and before Gingerbread (Android 2.3) and this flag is implied when targetting such releases. For applications targetting SDK versions greater than Android 2.3, this flag must be explicitly set if desired.

See Also
  • getSharedPreferences(String, int)

    
[3] 自个儿写的分页查询的步骤代码
    来源: 互联网  发布时间: 2014-02-18
自己写的分页查询的步骤代码

第一步:前台页面(核心代码)

 主要是当前的页数,因为是第一次嘛,肯定是从第一页开始的。查询出来的页面我用的是iframe方式呈现。其他地方的代码不用啰嗦,该怎么写怎么写。

<form name="advertiseForm" id="advertiseForm" action="/blog_article/modules/advertisement/AdvertiseManageAction/action/searchAdvertise.do" method="POST" target="advertiseList">
    <input type="hidden" name="currentPage" id="currentPage" value="1" />
<!-- 此处省略 -->
 <iframe  name="advertiseList" id="advertiseList"
			src="" frameBorder="0" width="100%"
			onload="javascript:this.height=advertiseList.document.body.scrollHeight"
			scrolling="no"></iframe>

 

第二步:actionForm代码

 actionForm里面的字段名称和前台页面要保存一直,学过struts的同学应该明白自动填充的含义。

package com.feinar.b2c.holiday.advertise.form;

import org.apache.struts.action.ActionForm;

/**
 * 查询广告管理用到的formBean
 * @author Administrator
 *
 */
public class AdvertiseSearchForm extends ActionForm{
	public String advertiseName;//广告名称
	public int advertiseState;//广告状态
	public int advertiseType;//发布区域
	public String currentPage;//当前第几页
	public String getAdvertiseName() {
		return advertiseName;
	}

	public void setAdvertiseName(String advertiseName) {
		this.advertiseName = advertiseName;
	}

	public int getAdvertiseState() {
		return advertiseState;
	}

	public void setAdvertiseState(int advertiseState) {
		this.advertiseState = advertiseState;
	}

	public int getAdvertiseType() {
		return advertiseType;
	}

	public void setAdvertiseType(int advertiseType) {
		this.advertiseType = advertiseType;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}
}

 

第三步:action代码

 

/**
	 * 查询广告
	 * @param mapping
	 * @param actionForm
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward search(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		AdvertiseSearchForm advertiseSearchForm = (AdvertiseSearchForm) actionForm;
		String action  = request.getParameter("action");
		int pageSize = 5;//默认每页显示的数量为10条
		System.out.println(action);
		List list = advertiseManageService.getAdvertiseList(advertiseSearchForm,pageSize);//获取对应的数据列表
		List list2 = advertiseManageService.getTotalCount(advertiseSearchForm,pageSize);//获取关于多少页,每页几条数据,一共多少页
		request.setAttribute("list", list);
		request.setAttribute("list2", list2);
		request.setAttribute("advertiseSearchForm", advertiseSearchForm);
		return mapping.findForward("list");
	}

 第四步:service业务逻辑层核心代码

/**
	 * 获取广告列表
	 */
	public List getAdvertiseList(AdvertiseSearchForm advertiseSearchForm,int pageSize)
			throws Exception {
		// TODO Auto-generated method stub
		List list = null;
		int currentPage = Integer.parseInt(advertiseSearchForm.getCurrentPage());
		int index = (currentPage-1)*pageSize;
		int end = currentPage*pageSize;
		try{
			String sql = getSql(advertiseSearchForm,2,index,end);
			list = advertiseManageDao.getAdvertiseList(sql);
		}catch (Exception e) {
			throw new Exception(e.getMessage().toString());
		}
		return list;
	}
	
	/**
	 * 得到查询的数据库sql语句
	 * @param advertiseSearchForm
	 * @param type
	 * @param index
	 * @param end
	 * @return
	 */
	public String getSql(AdvertiseSearchForm advertiseSearchForm,int type,int index,int end){
		String sqlwhere = " where 1=1 ";
		String sql = "";
		if(type==1){
			//获取评论总条数
			sql= "select count(*) from HOLIDAY_ADVERTISEMENT";
		}
		else if(type==2){
			//获取评论信息内容
			sql = "select * from (select ADVERTISEID,ADVERTISENAME,PIC,LINKURL,HOTELADDNUM,HOLIDAYADDNUM,HOLIDAYTYPEADDNUM,PUBLISHSTATE,rownum n " +
					"from HOLIDAY_ADVERTISEMENT ";
		}
		if(advertiseSearchForm.getAdvertiseName()!=null && !"".equals(advertiseSearchForm.getAdvertiseName().trim())){
			sqlwhere += " and ADVERTISENAME = '"+advertiseSearchForm.getAdvertiseName().trim()+"'";
		}
		if(advertiseSearchForm.getAdvertiseType()==1){
			sqlwhere += " and HOTELADDNUM is not null ";
		}
		if(advertiseSearchForm.getAdvertiseType()==2){
			sqlwhere += " and HOLIDAYADDNUM is not null ";
		}
		if(advertiseSearchForm.getAdvertiseType()==3){
			sqlwhere += " and HOLIDAYTYPEADDNUM is not null ";
		}
		if(advertiseSearchForm.getAdvertiseState()==0){
			sqlwhere += " and PUBLISHSTATE = 0 ";
		}
		if(advertiseSearchForm.getAdvertiseState()==1){
			sqlwhere += " and PUBLISHSTATE = 1 ";
		}
		if(advertiseSearchForm.getAdvertiseState()==2){
			sqlwhere += " and PUBLISHSTATE = 2 ";
		}
		if(type==2){
			sql += sqlwhere+" and rownum<="+end +" order by ADVERTISEID asc) where n>"+index;
		}else {
			sql += sqlwhere;
		}
		return sql;
	}
	
	/**
	 * 获取总共的条数,和页数,保存到一个list里面
	 */
	public List getTotalCount(AdvertiseSearchForm advertiseSearchForm,int pageSize) throws Exception {
		// TODO Auto-generated method stub
		int count = 0;
		int currentPage = Integer.parseInt(advertiseSearchForm.getCurrentPage());
		int pageCount = 0;//总共的页数
		List list = new ArrayList();
		try{
			String sql = getSql(advertiseSearchForm,1,0,0);
			count = advertiseManageDao.getTotalCount(sql);
			if (count % pageSize == 0) {
				pageCount = count / pageSize;
			} else {
				pageCount = count / pageSize + 1;
			}
			list.add(count);
			list.add(pageCount);
			list.add(advertiseSearchForm.getCurrentPage());
		}catch (Exception e) {
			throw new Exception(e.getMessage().toString());
		}
		return list;
	}

 

第五步:dao层组件代码

/**
	 * 获取某广告信息列表
	 */
	public List getAdvertiseList(String sql) throws Exception {
		// TODO Auto-generated method stub
		List list = new ArrayList();
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		try{
			connection = this.getJdbcTemplate().getDataSource().getConnection();
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			while(resultSet.next()){
				Advertisement advertisement = new Advertisement();
				advertisement.setAdvertiseid(resultSet.getLong("ADVERTISEID"));
				advertisement.setAdvertisename(resultSet.getString("ADVERTISENAME"));
				advertisement.setPic(resultSet.getBlob("PIC"));
				advertisement.setLinkurl(resultSet.getString("LINKURL"));
				advertisement.setHoteladdnum(resultSet.getLong("HOTELADDNUM"));
				advertisement.setHolidayaddnum(resultSet.getLong("HOLIDAYADDNUM"));
				advertisement.setHolidaytypeaddnum(resultSet.getLong("HOLIDAYTYPEADDNUM"));
				advertisement.setPublishstate(resultSet.getLong("PUBLISHSTATE"));
				list.add(advertisement);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(resultSet!=null){
				resultSet.close();
			}
			if(preparedStatement!=null){
				preparedStatement.close();
			}
			if(connection!=null){
				connection.close();
			}
		}
		return list;
	}

	/**
	 * 获取满足要求的广告总记录数(用于查询分页)
	 */
	public int getTotalCount(String sql) throws Exception {
		// TODO Auto-generated method stub
		int totalCount = 0;
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		try{
			connection = this.getJdbcTemplate().getDataSource().getConnection();
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			while(resultSet.next()){
				totalCount = resultSet.getInt(1);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(resultSet!=null){
				resultSet.close();
			}
			if(preparedStatement!=null){
				preparedStatement.close();
			}
			if(connection!=null){
				connection.close();
			}
		}
		return totalCount;
	}

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3