随笔记录select下的option 分页插件的使用

246 阅读2分钟

如何选中select下的option

    <select id="changePageSize" class="form-control" onchange="changePageSize()">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
		<option value="5">管理组</option>
	</select>
	<script>
		$(function(){
		    $('#changePageSize').find('option[value=3]').prop('selected', true);//初始话时使用哪个为默认项目
		    配合EL标签$('#changePageSize').find('option[value=${pageInfo.pageSize}]').prop('selected', true);
		    若网速和机器性能差,会在加载的时候看到<option value="1">1</option>
		})
		function changePageSize() {
		    $('select').val('1');//选中value="1"的option
		    $('select').find('option[value="2"]').prop('selected',true);//选中value="2"的option
		    $('select').find('option[value="3"]').attr('selected','selected');//选中value="3"的option
		    $(".type").find("option[text='管理组']").attr("selected",true); 
		    //选中text为管理组的option功能未得到体现
		}
	</script>

分页插件的使用

1. Using in mybatis-config.xml
    <!-- 
    In the configuration file, 
    plugins location must meet the requirements as the following order:
    properties?, settings?, 
    typeAliases?, typeHandlers?, 
    objectFactory?,objectWrapperFactory?, 
    plugins?, 
    environments?, databaseIdProvider?, mappers?
-->
<plugins>
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        <!-- config params as the following -->
        <property name="param1" value="value1"/>
	</plugin>
</plugins>
2. Using in Spring application.xml
    config org.mybatis.spring.SqlSessionFactoryBean as following:
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <!-- other configuration 
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations">
            <array>
                <value>classpath:mapper/*.xml</value>
            </array>
        </property>
        <property name="typeAliasesPackage" value="com.isea533.mybatis.model"/>
      -->
      <property name="plugins">
        <array>
          <bean class="com.github.pagehelper.PageInterceptor">
            <property name="properties">
              <!-- config params as the following -->
              <value>
                param1=value1
                <!--
                 helperDialect=mysql
                 reasonable=true
                 supportMethodsArguments=true
                 params=count=countSql
                 autoRuntimeDialect=true
                -->
              </value>
              <!--或者
              <props>
                <prop key="helperDialect">mysql</prop>
                <!--开启分页合理化-->
                <prop key="reasonable">true</prop>
              </props>
              -->
            </property>
          </bean>
        </array>
      </property>
    </bean>
3.范例    
    //获取第1页,10条内容,默认查询总数count
    PageHelper.startPage(1, 10);
    List<User> list = userMapper.selectAll();
    1.分页时,实际返回的结果list类型是Page<E>,Page<E> extends ArrayList<E> 如果想取出分页信息,需要强制转换为Page<E> ((Page) list).getTotal()但是一般用下面的方法包装
    //用PageInfo对结果进行包装
    PageInfo page = new PageInfo(list);
    //测试PageInfo全部属性
    //PageInfo包含了非常全面的分页属性
    assertEquals(1, page.getPageNum());
    assertEquals(10, page.getPageSize());
    assertEquals(1, page.getStartRow());
    assertEquals(10, page.getEndRow());
    assertEquals(183, page.getTotal());
    assertEquals(19, page.getPages());
    assertEquals(1, page.getFirstPage());
    /** @deprecated */
    @Deprecated
    public int getLastPage() {
        return this.navigateLastPage;
    }
    assertEquals(8, page.getLastPage());
    assertEquals(true, page.isFirstPage());
    assertEquals(false, page.isLastPage());
    assertEquals(false, page.isHasPreviousPage());
    assertEquals(true, page.isHasNextPage());