81,094
社区成员
发帖
与我相关
我的任务
分享
<select
id="findCommon"
resultMap="CommonResultMap">
select <include refid="Common_Column_List" />
from common
<trim
prefix="where"
suffixOverrides="and">
<if test="name != null">
name = #{name,jdbcType=VARCHAR}
</if>
<if test="email != null">
email=#{email,jdbcType=VARCHAR}
</if>
<if test="qq != null">
qq=#{qq,jdbcType=VARCHAR}
</if>
<if test="idcard != null">
idcard=#{idcard,jdbcType=VARCHAR}
</if>
<if test="ethnic != null">
ethnic=#{ethnic,jdbcType=VARCHAR}
</if>
<if test="diploma != null">
diploma=#{diploma,jdbcType=VARCHAR}
</if>
<if test="bank != null">
bank=#{bank,jdbcType=VARCHAR}
</if>
</trim>
</select>
@RequestMapping(value = "findCommon", method = RequestMethod.GET)
public void findCommon(@RequestParam(value = "pn", defaultValue = "1") Integer pn, Common common,
HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter pw = response.getWriter();
System.out.println(common.getBank());
String result = "";
System.out.println("pn:" + pn);
HttpSession session = request.getSession();
List<Common> commonList = commonService.findCommon();
System.out.println("list:" + commonList.size());
PageHelper.startPage(pn, 10);
PageInfo<Common> page = new PageInfo<Common>(commonList, 5);
session.setAttribute("pageInfo", commonList);
result = "allok";
pw.write(result);
pw.flush();
pw.close();
}
<c:forEach items="${pageInfo }" var = "list">
<tr>
<td>${list.id}</td>
<td>${list.name}</td>
<td>${list.email}</td>
<td>${list.phone}</td>
<td>${list.qq}</td>
<td>${list.idcard}</td>
<td>${list.ethnic}</td>
<td>${list.diploma}</td>
<td>${list.bank}</td>
<td scope="col"><a href="#"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></td>
</tr>
</c:forEach>
......
<script type="text/javascript">
function findCommon() {
var common = {
name : $("*[name='name']").val(),
email : $("*[name='email']").val(),
phone : $("*[name='phone']").val(),
qq : $("*[name='qq']").val(),
idcard : $("*[name='idcard']").val(),
ethnic : $("*[name='ethnic']").val(),
diploma : $("*[name='diploma']").val(),
bank : $("*[name='bank']").val()
};
$.ajax({
cache : true,
type : "GET",
url : "${myappurl}findCommon.do",
data : common,
async : true,
success : function(data) {
if (data == "allok") {
alert("查询成功");
} else {
alert("查询失败");
}
}
});
}
</script>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 打印查询语句 -->
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!--解决,查询返回结果含null没有对应字段值问题 -->
<setting name="callSettersOnNulls" value="true"/>
</settings>
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库 -->
<property name="dialect" value="sqlserver"/>
</plugin>
</plugins>
</configuration>
DEBUG 2017-09-11 21:32:12,025 org.springframework.web.servlet.DispatcherServlet: Rendering view [org.springframework.web.servlet.view.JstlView: name 'myhome'; URL [/myhome.jsp]] in DispatcherServlet with name 'myhos'
DEBUG 2017-09-11 21:32:12,025 org.springframework.web.servlet.view.InternalResourceView: Forwarding to resource [/myhome.jsp] in InternalResourceView 'myhome'
DEBUG 2017-09-11 21:32:12,026 org.springframework.web.servlet.FrameworkServlet: Successfully completed request
DEBUG 2017-09-11 21:32:27,024 org.springframework.web.servlet.DispatcherServlet: DispatcherServlet with name 'myhos' processing GET request for [/issHR02/findCommon.do]
DEBUG 2017-09-11 21:32:27,025 org.springframework.web.servlet.handler.AbstractHandlerMethodMapping: Looking up handler method for path /findCommon.do
DEBUG 2017-09-11 21:32:27,025 org.springframework.web.servlet.handler.AbstractHandlerMethodMapping: Returning handler method [public void com.hcy.controller.CommonController.findCommon(java.lang.Integer,com.hcy.model.Common,org.springframework.ui.Model) throws java.io.IOException]
DEBUG 2017-09-11 21:32:27,027 org.springframework.beans.factory.support.AbstractBeanFactory: Returning cached instance of singleton bean 'commonController'
DEBUG 2017-09-11 21:32:27,027 org.springframework.web.servlet.DispatcherServlet: Last-Modified value for [/issHR02/findCommon.do] is: -1
DEBUG 2017-09-11 21:32:27,029 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: Creating a new SqlSession
DEBUG 2017-09-11 21:32:27,029 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@aed2757] was not registered for synchronization because synchronization is not active
DEBUG 2017-09-11 21:32:27,030 org.springframework.jdbc.datasource.DataSourceUtils: Fetching JDBC Connection from DataSource
DEBUG 2017-09-11 21:32:27,031 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: JDBC Connection [com.mysql.jdbc.Connection@768441d2] will not be managed by Spring
DEBUG 2017-09-11 21:32:27,031 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: ooo Using Connection [com.mysql.jdbc.Connection@768441d2]
DEBUG 2017-09-11 21:32:27,031 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: ==> Preparing: select id,name,email,phone ,qq,idcard,ethnic,diploma,bank from common
DEBUG 2017-09-11 21:32:27,032 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: ==> Parameters:
DEBUG 2017-09-11 21:32:27,034 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl: Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@aed2757]
DEBUG 2017-09-11 21:32:27,035 org.springframework.jdbc.datasource.DataSourceUtils: Returning JDBC Connection to DataSource
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.DispatcherServlet: Rendering view [org.springframework.web.servlet.view.JstlView: name 'findCommon'; URL [/findCommon.jsp]] in DispatcherServlet with name 'myhos'
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.view.AbstractView: Added model object 'common' of type [com.hcy.model.Common] to request in view with name 'findCommon'
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.view.AbstractView: Added model object 'org.springframework.validation.BindingResult.common' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'findCommon'
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.view.AbstractView: Added model object 'pageInfo' of type [com.github.pagehelper.PageInfo] to request in view with name 'findCommon'
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.view.AbstractView: Added model object 'org.springframework.validation.BindingResult.pageInfo' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'findCommon'
DEBUG 2017-09-11 21:32:27,036 org.springframework.web.servlet.view.InternalResourceView: Forwarding to resource [/findCommon.jsp] in InternalResourceView 'findCommon'
DEBUG 2017-09-11 21:32:27,037 org.springframework.web.servlet.FrameworkServlet: Successfully completed request
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Homework8341</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation2</param-name>
<param-value>
classpath:spring-mybatis.xml
</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>myhos</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myhos</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
myhos-servlet.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"
default-autowire="byName">
<!-- 扫描 注解 -->
<context:component-scan base-package="com.hcy" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<context:annotation-config />
<mvc:annotation-driven />
</beans>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--mybatis分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PaginationInterceptor">
<property name="reasonable" value="true"/>
<property name="dialect" value="mysql"/>
<!-- 该参数默认为false -->
<!-- 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 -->
<!-- 和startPage中的pageNum效果一样-->
<property name="offsetAsPageNum" value="true"/>
<!-- 该参数默认为false -->
<!-- 设置为true时,使用RowBounds分页会进行count查询 -->
<property name="rowBoundsWithCount" value="true"/>
<!-- 设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果 -->
<!-- (相当于没有执行分页查询,但是返回结果仍然是Page类型)-->
<property name="pageSizeZero" value="true"/>
<!-- 3.3.0版本可用 - 分页参数合理化,默认false禁用 -->
<!-- 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 -->
<!-- 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
</plugin>
</plugins>
</configuration>
@RequestMapping(value = "findCommon", method = RequestMethod.GET)
public void findCommon(@RequestParam(value = "pn", defaultValue = "1") Integer pn, Common common,
HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter pw = response.getWriter();
System.out.println(common.getBank());
String result = "";
System.out.println("pn:" + pn);
HttpSession session = request.getSession();
PageHelper.startPage(pn, 10);
List<Common> commonList = commonService.findCommon();
PageInfo<Common> page = new PageInfo<Common>(commonList, 10);
System.out.println("list:" + commonList.size());
session.setAttribute("pageInfo", page);
result = "allok";
pw.write(result);
pw.flush();
pw.close();
}