Task_listMapper.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.chinaGPS.song.dao.MemberDao"> <resultMap id="BaseResultMap" type="com.chinaGPS.song.pojo.Task_list"> <id column="task_id" jdbcType="VARCHAR" property="taskId" /> <result column="m_id" jdbcType="VARCHAR" property="mId" /> <result column="m_name" jdbcType="VARCHAR" property="mName" /> <result column="songId" jdbcType="VARCHAR" property="songid" /> <result column="m_phonenumber" jdbcType="VARCHAR" property="mPhonenumber" /> <result column="download_time" jdbcType="TIMESTAMP" property="downloadTime" /> <result column="download_status" jdbcType="CHAR" property="downloadStatus" /> <result column="optime" jdbcType="TIMESTAMP" property="optime" /> </resultMap><!-- 分页时使用 查询歌曲 -->
<select id="count" resultType="long" > select distinct count(*) from task_list <!--<where> t.singer_id = t1.singer_id <if test="songName != null" > and t.song_name = #{songName} </if> <if test="songType != null" > and t.song_type = #{songType} </if> <if test="singerName != null" > and t1.singer_name = #{singerName} </if> <if test="songPrice != null" > and t.song_price = #{songPrice} </if> <if test="downloadCount != null" > and t.download_count = #{download_count} </if> <if test="downloadUrl != null" > and t.download_url = #{downloadUrl} </if> </where> --></select> <!-- 分页查询已经使用Dialect进行分页,也可以不使用Dialect直接编写分页 因为分页查询将传 #offset#,#pageSize#,#lastRows# 三个参数,不同的数据库可以根于此三个参数属性应用不同的分页实现 --> <select id="pageSelect" resultMap="BaseResultMap" > select distinct * from task_list <!-- <where> t.singer_id = t1.singer_id <if test="songName != null" > and t.song_name = #{songName} </if> <if test="songType != null" > and t.song_type = #{songType} </if> <if test="singerName != null" > and t1.singer_name = #{singerName} </if> <if test="songPrice != null" > and t.song_price = #{songPrice} </if> <if test="downloadCount != null" > and t.download_count = #{download_count} </if> <if test="downloadUrl != null" > and t.download_url = #{downloadUrl} </if> </where>--> ORDER BY task_id </select>**************************
com.chinaGPS.song.dao.MemberDao
public class MemberDao extends BaseMyBatisDao<Task_list, java.lang.Integer>{
/**
* 获取 下载 任务列表 分页 * @param pageRequest * @return */ public Page<Task_list> getTaskList(PageRequest pageRequest){ Page<Task_list> page = pageQuery(pageRequest); return page; }***********************
package com.chinaGPS.song.service;
import java.util.List; import com.chinaGPS.song.pojo.Task_list; import com.chinaGPS.song.util.page.Page; import com.chinaGPS.song.util.page.PageRequest; public interface TaskInfoService { public List<Task_list>selectTaskList(); /** * 获取分页下载 任务列表 * @return */ Page<Task_list> getAllTaskList(PageRequest pageRequest); }}
*********************
package com.chinaGPS.song.util.page;
import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 分页请求信息 * 其中范型<T>为filters的类型 * @author badqiu */ public class PageRequest<T> implements Serializable { /** * 过滤参数 */ private T filters; /** * 页号码,页码从1开始 */ private int pageNumber; /** * 分页大小 */ private int pageSize; /** * 排序的多个列,如: username desc */ private String sortColumns; public PageRequest() { this(0,0); } public PageRequest(T filters) { this(0,0,filters); } public PageRequest(int pageNumber, int pageSize) { this(pageNumber,pageSize,(T)null); } public PageRequest(int pageNumber, int pageSize, T filters) { this(pageNumber,pageSize,filters,null); } public PageRequest(int pageNumber, int pageSize,String sortColumns) { this(pageNumber,pageSize,null,sortColumns); } public PageRequest(int pageNumber, int pageSize, T filters,String sortColumns) { this.pageNumber = pageNumber; this.pageSize = pageSize; setFilters(filters); setSortColumns(sortColumns); } public T getFilters() { return filters; } public void setFilters(T filters) { this.filters = filters; } public int getPageNumber() { return pageNumber; } public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public String getSortColumns() { return sortColumns; } /** * 排序的列,可以同时多列,使用逗号分隔,如 username desc,age asc * @return */ public void setSortColumns(String sortColumns) { this.sortColumns = sortColumns; } /** * 将sortColumns进行解析以便返回SortInfo以便使用 * @return */ public List<SortInfo> getSortInfos() { return Collections.unmodifiableList(SortInfo.parseSortColumns(sortColumns)); } } **********************package com.chinaGPS.song.service.impl;
import java.util.List; import com.chinaGPS.song.dao.MemberDao; import com.chinaGPS.song.pojo.Task_list; import com.chinaGPS.song.service.TaskInfoService; import com.chinaGPS.song.util.page.Page; import com.chinaGPS.song.util.page.PageRequest; public class TaskInfoServiceImpl implements TaskInfoService { private MemberDao memberDao; public MemberDao getMemberDao() { return memberDao; } public void setMemberDao(MemberDao memberDao) { this.memberDao = memberDao; } /* (non-Javadoc) * @see com.chinaGPS.song.service.TaskInfoService#getAllSongList(com.chinaGPS.song.util.page.PageRequest) */ public Page<Task_list> getAllTaskList(PageRequest pageRequest) { return memberDao.getTaskList(pageRequest); } } ************************package com.chinaGPS.song.action.sysmanage;
import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.apache.struts2.ServletActionContext; import org.displaytag.tags.TableTagParameters; import org.displaytag.util.ParamEncoder; import com.chinaGPS.song.action.BaseAction; import com.chinaGPS.song.pojo.Song_info; import com.chinaGPS.song.pojo.Task_list; import com.chinaGPS.song.service.TaskInfoService; import com.chinaGPS.song.util.page.Page; import com.chinaGPS.song.util.page.PageRequest; public class TaskListAction extends BaseAction { private static final long serialVersionUID = -1209389500331569006L; private TaskInfoService taskInfoService; private List<Task_list> list; private PageRequest<Map> pageRequest; private int pageSize = 5; private int startPage = 1; private int pageNumbers; public String songsTaskList() { String pageIndexName = new ParamEncoder("row") .encodeParameterName(TableTagParameters.PARAMETER_PAGE); // 页数的参数名 startPage = StringUtils.isBlank(getParameter(pageIndexName)) ? 1 : (Integer.parseInt(getParameter(pageIndexName))); // 当前页数 if (startPage == 0) { startPage = 1; } if(pageRequest==null) pageRequest = new PageRequest(new HashMap()); pageRequest.setPageNumber(startPage); pageRequest.setPageSize(pageSize); pageRequest.setSortColumns(null); Page<Task_list> page = taskInfoService.getAllTaskList(pageRequest); list = page.getResult(); pageNumbers = page.getTotalCount(); return SUCCESS; } public TaskInfoService getTaskInfoService() { return taskInfoService; } public PageRequest<Map> getPageRequest() { return pageRequest; } public void setPageRequest(PageRequest<Map> pageRequest) { this.pageRequest = pageRequest; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getStartPage() { return startPage; } public void setStartPage(int startPage) { this.startPage = startPage; } public int getPageNumbers() { return pageNumbers; } public void setPageNumbers(int pageNumbers) { this.pageNumbers = pageNumbers; } public void setTaskInfoService(TaskInfoService taskInfoService) { this.taskInfoService = taskInfoService; } public List<Task_list> getList() { return list; } public void setList(List<Task_list> list) { this.list = list; } } ************************JSP<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<display:table name="list" id="row" partialList="true"
pagesize="${pageSize}" size="${pageNumbers}" requestURI="songsTaskList.action" class="table"> <display:column property="taskId" title="用户"/> <display:column property="mId" title="性别"/> <display:column property="mName" title="车载" /> <display:column property="mPhonenumber" title="车牌" /> <display:column property="songid" title="歌曲" /> <display:column property="downloadTime" title="发送时间" /> <display:column property="downloadStatus" title="发送状态" /> <display:column title="基本操作"> <div align="center"> <a href="deleteUpload.action?songId=${row.songid }"> <font color="#330099">删除</font> </a> </div> </display:column> </display:table>**********************application-action-sys.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <bean id="TaskListAction" class="com.chinaGPS.song.action.sysmanage.TaskListAction"> <property name="taskInfoService" ref="taskInfoService"></property> </bean> </beans>***********************application-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <bean id="memberDao" class="com.chinaGPS.song.dao.MemberDao"> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> </beans>******************application-core.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <!-- 导入属性配置文件 --> <context:property-placeholder location="/WEB-INF/jdbc/mysql.properties" /> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> </bean> --> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="driverUrl" value="jdbc:mysql://192.168.3.60:3306/song?useUnicode=true&characterEncoding=utf-8" /> <property name="user" value="root" /> <property name="password" value="123456" /> </bean> <!-- <bean id="transactionManager" --> <!-- class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> --> <!-- <property name="dataSource" ref="dataSource" /> --> <!-- </bean> --> <!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> --> <!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> --> <!-- <property name="dataSource" ref="dataSource" /> --> <!-- </bean> --> <bean id="sqlSessionFactory" class="com.chinaGPS.song.util.SqlSessionFactoryFactoryBean"> <property name="configLocation" value="/WEB-INF/mybatis-config.xml" /> <property name="mapperLocations" > <list> <value>classpath*:/com/chinaGPS/song/mapper/Song_infoMapper.xml</value> <value>classpath*:/com/chinaGPS/song/mapper/Song_singerMapper.xml</value> <value>classpath*:/com/chinaGPS/song/mapper/Task_listMapper.xml</value> </list> </property> <property name="dataSource" ref="dataSource" /> </bean> <!-- dao的注入方式1 --> <!-- <bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> --> <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> --> <!-- <property name="mapperInterface" value="com.chinaGPS.song.dao.UserDao" /> --> <!-- </bean> --> <!-- dao的注入方式2 --> <!-- <bean id="userDao" class="com.chinaGPS.song.dao.UserDao"> --> <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> --> <!-- </bean> --> <!-- <bean id="userManagerService" class="com.chinaGPS.song.service.impl.UserManagerService"> --> <!-- <property name="userDao" ref="userDao" /> --> <!-- </bean> --> <!-- <bean id="bookDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> --> <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> --> <!-- <property name="mapperInterface" value="com.chinaGPS.song.dao.ISBookDao" /> --> <!-- </bean> --> <!-- <bean id="addressDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> --> <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> --> <!-- <property name="mapperInterface" value="com.chinaGPS.song.dao.IAddressDao" /> --> <!-- </bean> --> <!-- ================================= 事务控制相关 ============================================= --> <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="register*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="*lock*" propagation="REQUIRED" /> <tx:method name="reset*" propagation="REQUIRED" /> <!-- 将save、delete、modify开头的事务之外的事务全部设置 为只读事务,这样也可以在一定程序上提高系统性能 --> <tx:method name="find*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="query*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置那些类的那些方法参与事务 --> <aop:config> <!-- <aop:pointcut>标签指的是一个范围 --> <aop:pointcut id="allMagangerMethod" expression="execution(* com.chinaGPS.song.dao.base.BaseService.*(..))" /> <aop:pointcut id="allMagangerMethod1" expression="execution(* com.chinaGPS.song.service.impl.*ServiceImpl.*(..))" /> <aop:pointcut id="allMagangerMethod2" expression="execution(* com.chinaGPS.song.service.*Service.*(..))" /> <!-- <aop:advisor>标签相当于Aspect --> <aop:advisor pointcut-ref="allMagangerMethod" advice-ref="txAdvice" /> <aop:advisor pointcut-ref="allMagangerMethod1" advice-ref="txAdvice" /> <aop:advisor pointcut-ref="allMagangerMethod2" advice-ref="txAdvice" /> </aop:config> </beans> *********************application-service.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <bean id="taskInfoService" class="com.chinaGPS.song.service.impl.TaskInfoServiceImpl"> <property name="memberDao" ref="memberDao" /> </bean> </beans>