Spring MVC

spring mvc demo

1、
<!-- 程仁银测试 -->
<bean id="cpCryTestDao" parent="dao" class="com.linkage.cp.query.dao.CryTestDaoImpl"></bean>
<bean id="cpCryTestService" class="com.linkage.cp.query.service.CryTestServiceImpl">
<property name="cryTestDao" ref="cpCryTestDao"></property>
<dwr:remote javascript="cpCryTestService"></dwr:remote>
</bean>

2、serviceImpl

/**
* CryTestDaoImpl.java
* com.linkage.cp.query.dao
*
* Function: TODO
*
*   ver     date      author
* ──────────────────────────────────
*   Jun 4, 2010 程仁银
*
* Copyright (c) 2010,  All Rights Reserved.
*/

package com.linkage.cp.query.dao;

import java.util.List;

import com.linkage.cp.query.domain.CryTestRowMapper;
import com.linkage.cp.usermanage.domain.UserLogin;
import com.linkage.justone4.core.SQLProxy;
import com.linkage.justone4.utils.BaseDao;
import com.linkage.justone4.utils.PaginationSupport;

/**
* ClassName:CryTestDaoImpl
* Project:
* Company: LINKAGE
*
* @author   程仁银
* @version
* @since    Ver 1.1
* @Date Jun 4, 2010 10:23:31 AM
*
* @see
*/
public class CryTestDaoImpl extends BaseDao implements CryTestDao {

public PaginationSupport queryUserLogin(UserLogin userLogin,int startIndex, int countOnEachPage)
{
String sql = "select USERNAME,LOGINID,PASSWORD from myb.userlogin where username like ? ";
return super.find(new SQLProxy(sql).sql(false), new Object[]{"%"+userLogin.getUserName()+"%"}, new CryTestRowMapper(),startIndex,countOnEachPage);
}
}

3、daoImpl

/**
* CryTestDaoImpl.java
* com.linkage.cp.query.dao
*
* Function: TODO
*
*   ver     date      author
* ──────────────────────────────────
*   Jun 4, 2010 程仁银
*
* Copyright (c) 2010,  All Rights Reserved.
*/

package com.linkage.cp.query.dao;

import java.util.List;

import com.linkage.cp.query.domain.CryTestRowMapper;
import com.linkage.cp.usermanage.domain.UserLogin;
import com.linkage.justone4.core.SQLProxy;
import com.linkage.justone4.utils.BaseDao;
import com.linkage.justone4.utils.PaginationSupport;

/**
* ClassName:CryTestDaoImpl
* Project:
* Company: LINKAGE
*
* @author   程仁银
* @version
* @since    Ver 1.1
* @Date Jun 4, 2010 10:23:31 AM
*
* @see
*/
public class CryTestDaoImpl extends BaseDao implements CryTestDao {

public PaginationSupport queryUserLogin(UserLogin userLogin,int startIndex, int countOnEachPage)
{
String sql = "select USERNAME,LOGINID,PASSWORD from myb.userlogin where username like ? ";
return super.find(new SQLProxy(sql).sql(false), new Object[]{"%"+userLogin.getUserName()+"%"}, new CryTestRowMapper(),startIndex,countOnEachPage);
}
}

3、页面

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.linkage.cp.announce.service.*" %>
<%@page import="com.linkage.cp.announce.domain.*" %>
<%@page import="com.linkage.justone4.login.domain.*"%>
<%@page import="com.linkage.cp.usermanage.domain.UserLogin"%>
<%@page import="com.linkage.cp.query.service.CryTestService"%>
<%@page import="com.linkage.justone4.utils.RequestUtils"%>
<%@page import="com.linkage.justone4.utils.PaginationSupport"%>
<%
WebApplicationContext cx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
CryTestService cryTestService = (CryTestService)cx.getBean("cpCryTestService");

UserLogin userLogin = new UserLogin();
userLogin.setUserName(RequestUtils.getString(request,"userName"));

int startIndex = RequestUtils.getIntDef(request, "startIndex", 0);
PaginationSupport ps = cryTestService.queryUserLogin(userLogin,startIndex,10);
request.setAttribute("paginationSupport", ps);
List<UserLogin> userLoginList = ps.getItems();
%>

<html>
  <link rel="stylesheet" href="../css/style.css" type="text/css"/>
  <link rel="stylesheet" href="../css/table/style.css" type="text/css"/>
  <script type="text/javascript" src="../javascripts/jquery-1.3.min.js"></script>
  <script type="text/javascript" src="../javascripts/jquery.scrollTo.js"></script>
  <script type="text/javascript" src="../javascripts/jquery.localscroll.js"></script>
  <script type="text/javascript" src="../javascripts/jquery.tablesorter.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function() {
$("#announcelist").tablesorter();
});
  </script>
  <body>
  <form action="crytest.jsp" name="frm" method="post">
  <table>
  <tr><td>
  <input type="text" name="userName" id="userName" value="<%=userLogin.getUserName() %>" />
  <input type="submit" name="rn" id="rn" value="查询" />
  </td></tr>
  </table>
    <table id="announcelist" class="tablesorter">
    <thead>
    <tr>
    <th>发布时间</th>
    <th>公告标题</th>
    <th>公告内容</th>
    <th>发布人</th>
    </tr>
    </thead>
    <tbody>
    <%
    if(userLoginList!=null){
    for(int i=0;i<userLoginList.size();i++)
    {
    UserLogin ul=userLoginList.get(i);
    %>
    <tr>
    <td><%=ul.getUserName()%></td>
    <td><%=ul.getPassword()%></td>
    <td><%=ul.getLoginId()%></td>
    <td>............</td>
    </tr>
    <%
    }
    %>

    <%
    }
    %>
    </tbody>
    </table>
    <div id="showBulletin" style="display:none; background:#DBEAF5;border-style:outset; border-width:1px;"></div>
    </form>
     <div class="controlbanner" style="float:right">
            <jsp:include page="../../include/pagination.jsp"></jsp:include>
    </div>
  </body>
</html>

你可能感兴趣的:(java,spring,sql,mvc,公告)