- 浏览: 10308 次
- 性别:
最新评论
说明:
1、后台程序是参考本公司“杜师傅”的例子!加上自学了ligerui,整合来使用!
2、最近在做一个项目,使用到了上面的技术,不知道现在ssh发展到了上面地步,是不是已经快淘汰了,发现springMVC+mybatis、hibernate+esayui、juqeryui等是企业级应用比较广泛,本人在大学期间,就是学习ssh整合开发,个人感觉现在ssh在java企业应用中还是普遍存在的吧!
3、重在个人总结,技术积累,有什么不好的地方,还请各位牛人指点!相互学习、相互进步。
话不多说,下面是整合信息
一、项目结构:
二、把需要的jar包添加到lib目录,配置web.xml、applicationContext.xml
web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoader</listener-class>
</listener>
<display-name>Struts Blank</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <filter>
<filter-name>loginFilter</filter-name>
<filter-class>com.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharsetFilter</filter-name>
<filter-class>com.filter.CharsetFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.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-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<bean id="TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="TransactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="sum*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* com.dao.impl.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod"/>
</aop:config>
<!-- Dao Beans -->
<bean id="UserDao" class="com.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Service Beans -->
<bean id="UserService" class="com.service.UserService">
<property name="userdao" ref="UserDao"/>
</bean>
</beans>
三、dao
package com.dao.impl;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.common.PageUnit;
import com.dao.UserDao;
import com.tool.DBEncoding;
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
public List userList(Map data,int pageNow,int pageSize) throws Exception{
Session session=this.getHibernateTemplate().getSessionFactory().getCurrentSession();
String sql = "select " +
"t.ID," +
"t.SFZH," +
"t.YHXM," +
"t.YHXB," +
"decode(t.YHXB,'0','男','1','女','') as STR_YHXB," +
"t.PHONE," +
"t.PASSWORD," +
"t.CSRQ," +
"t.UPDATENUMBER," +
"to_char(t.ADDDATE,'yyyy-MM-dd hh24:mi:ss') as ADDDATE," +
"t.YXBS " +
" from USERS t " +
" where 1=1 ";
//" and t.YXBS=0";
String sql_where="";
List<String> dataList=new ArrayList<String>();
if(data!=null&&data.size()>0)
{
if(data.get("SFZH")!=null)
{
sql_where+=" and t.SFZH like ? ";
dataList.add("%"+data.get("SFZH")+"%");
}
if(data.get("YHXM")!=null)
{
sql_where+=" and t.YHXM like ? ";
dataList.add("%"+data.get("YHXM")+"%");
}
}
sql+=sql_where+"order by t.ADDDATE desc";
String sql_pageHear="select * from ( select zt.*,rownum m from ( ";
String sql_pageFoot=" ) zt where rownum<=? ) where m>?";
String sql_all=sql_pageHear+sql+sql_pageFoot;
PreparedStatement ps=session.connection().prepareStatement(sql_all);
int index=1;
if(dataList!=null&&dataList.size()>0)
{
for(int i=0;i<dataList.size();i++)
{
ps.setString(index++, dataList.get(i));
}
}
ps.setInt(index++, pageNow*pageSize);
ps.setInt(index++, (pageNow-1)*pageSize);
System.out.println("executeSQL:"+sql_all);
ResultSet rs=ps.executeQuery();
List l=null;
try
{
if(rs!=null)
{
int pageCount=PageUnit.getPageCount(session,sql, dataList, pageSize);
int Total = PageUnit.getRowCount(session, sql, dataList);
l=new ArrayList();
while(rs.next())
{
Map m=new HashMap();
for(int i=0;i<rs.getMetaData().getColumnCount();i++)
{
String key=rs.getMetaData().getColumnName(i+1);
m.put(key, DBEncoding.EncodingOutputDB(rs.getString(key)));
if("null".equals(m.get(key)+""))
{
m.put(key,"");
}
}
m.put("pageCount", pageCount);
m.put("Total", Total);
l.add(m);
}
}
releaseSession(session);
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return l;
}
}
dao中的分页类
package com.common;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import org.hibernate.Session;
import com.tool.DBEncoding;
public class PageUnit{
public static int getPageCount(Session session,String sql, List<String> data, int pageSize)
throws Exception {
int pageCount=0;
int rowCount=0;
sql = "select count(*) from (" +sql+")";
PreparedStatement ps=session.connection().prepareStatement(sql);
int index=1;
if(data!=null&&data.size()>0)
{
for(int i=0;i<data.size();i++)
{
ps.setString(index++, DBEncoding.EncodingInputDB(data.get(i)+""));
}
}
System.out.println("executeSQL:"+sql);
ResultSet rs=ps.executeQuery();
try
{
if(rs!=null)
{
if(rs.next())
{
rowCount=Integer.parseInt(rs.getInt(1)+"");
}
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return pageCount;
}
public static int getRowCount(Session session,String sql,List<String> data) throws Exception{
//int pageCount=0;
int rowCount=0;
sql = "select count(*) from (" +sql+")";
PreparedStatement ps=session.connection().prepareStatement(sql);
int index=1;
if(data!=null&&data.size()>0)
{
for(int i=0;i<data.size();i++)
{
ps.setString(index++, DBEncoding.EncodingInputDB(data.get(i)+""));
}
}
System.out.println("executeSQL:"+sql);
ResultSet rs=ps.executeQuery();
try
{
if(rs!=null)
{
if(rs.next())
{
rowCount=Integer.parseInt(rs.getInt(1)+"");
}
}
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return rowCount;
}
}
service类
package com.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dao.UserDao;
public class UserService {
private UserDao userdao;
public UserDao getUserdao() {
return userdao;
}
public void setUserdao(UserDao userdao) {
this.userdao = userdao;
}
/**
* 带分页的查询用户信息
* @param data
* @param pageNow
* @param pageSize
* @return
*/
public List userList(Map data,int pageNow,int pageSize){
List list = new ArrayList();
try {
list = userdao.userList(data, pageNow, pageSize);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
这时候应该写个测试类来测试一下结果
package com.test;
import java.util.List;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.factory.SpringContextFactory;
import com.service.UserService;
public class UserDaoTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext act=SpringContextFactory.getSpringContext();
UserService us = (UserService)act.getBean("UserService");
List list = us.userList(null, 1, 10);
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
}
}
package com.factory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringContextFactory {
private static ClassPathXmlApplicationContext act=null;
public static ClassPathXmlApplicationContext getSpringContext()
{
if(act==null)
{
act=new ClassPathXmlApplicationContext("applicationContext.xml");
}
return act;
}
}
action 类
package com.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.factory.SpringContextFactory;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserService;
public class UserAction extends ActionSupport{
private int pageNow = 1;
private int pageSize = 10;
private JSONObject Rows;
private String action;
@SuppressWarnings("unchecked")
public String execute(){
//HttpServletRequest request=ServletActionContext.getRequest();
ClassPathXmlApplicationContext act=SpringContextFactory.getSpringContext();
UserService us = (UserService)act.getBean("UserService");
if(action.equals("ulist")){
List userList = us.userList(null, pageNow, pageSize);
/**
* json
*/
HashMap maprow = new HashMap();
if(userList!=null&&userList.size()>0){
String Total=(((Map)userList.get(0)).get("Total"))+"";
maprow.put("Rows", userList);
maprow.put("Total", Total);
}
Rows =JSONObject.parseObject(JSON.toJSONString(maprow));
System.out.println(Rows);
return SUCCESS;
}
return ERROR;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public JSONObject getRows() {
return Rows;
}
public void setRows(JSONObject rows) {
Rows = rows;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
}
struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="json-default">
<action name="UserAction" class="com.action.UserAction">
<result type="json">
<param name="root">Rows</param>
</result>
</action>
</package>
</struts>
下面来使用ligerui的ligerGrid查询显示列表数据,userlist.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户列表</title>
<%@include file="include/head.jsp" %>
<script type="text/javascript">
$(function(){
$("#mainGrid").ligerGrid({
title:"用户列表",
columns:[
{display:"主键",name:"ID",hide:"hidden"},
{display:"身份证号",name:"SFZH",width:200},
{display:"用户姓名",name:"YHXM",width:100},
{display:"用户性别",name:"STR_YHXB"},
{display:"手机号码",name:"PHONE"},
{display:"出生日期",name:"CSRQ"},
{display:"录入时间",name:"ADDDATE"},
{display:"有效标示",name:"YXBS"}
],
//data:docData,
url:'UserAction.action?action=ulist',
sortName: 'au_id',
width:"100%",height:"100%",checkbox:true,
pagesizeParmName:"pageSize",
pageParmName:"pageNow",
pageSize:10,
rowHeight:40,
rownumbers:true,usePager:true
});
})
</script>
</head>
<body>
<div id="mainGrid"></div>
</body>
</html>
显示结果
[img][/img]
只写了个查询的列子,后面的增、删、改都差不多啦!
1、后台程序是参考本公司“杜师傅”的例子!加上自学了ligerui,整合来使用!
2、最近在做一个项目,使用到了上面的技术,不知道现在ssh发展到了上面地步,是不是已经快淘汰了,发现springMVC+mybatis、hibernate+esayui、juqeryui等是企业级应用比较广泛,本人在大学期间,就是学习ssh整合开发,个人感觉现在ssh在java企业应用中还是普遍存在的吧!
3、重在个人总结,技术积累,有什么不好的地方,还请各位牛人指点!相互学习、相互进步。
话不多说,下面是整合信息
一、项目结构:
二、把需要的jar包添加到lib目录,配置web.xml、applicationContext.xml
web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoader</listener-class>
</listener>
<display-name>Struts Blank</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <filter>
<filter-name>loginFilter</filter-name>
<filter-class>com.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharsetFilter</filter-name>
<filter-class>com.filter.CharsetFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.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-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<bean id="TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="TransactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="sum*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* com.dao.impl.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod"/>
</aop:config>
<!-- Dao Beans -->
<bean id="UserDao" class="com.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Service Beans -->
<bean id="UserService" class="com.service.UserService">
<property name="userdao" ref="UserDao"/>
</bean>
</beans>
三、dao
package com.dao.impl;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.common.PageUnit;
import com.dao.UserDao;
import com.tool.DBEncoding;
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
public List userList(Map data,int pageNow,int pageSize) throws Exception{
Session session=this.getHibernateTemplate().getSessionFactory().getCurrentSession();
String sql = "select " +
"t.ID," +
"t.SFZH," +
"t.YHXM," +
"t.YHXB," +
"decode(t.YHXB,'0','男','1','女','') as STR_YHXB," +
"t.PHONE," +
"t.PASSWORD," +
"t.CSRQ," +
"t.UPDATENUMBER," +
"to_char(t.ADDDATE,'yyyy-MM-dd hh24:mi:ss') as ADDDATE," +
"t.YXBS " +
" from USERS t " +
" where 1=1 ";
//" and t.YXBS=0";
String sql_where="";
List<String> dataList=new ArrayList<String>();
if(data!=null&&data.size()>0)
{
if(data.get("SFZH")!=null)
{
sql_where+=" and t.SFZH like ? ";
dataList.add("%"+data.get("SFZH")+"%");
}
if(data.get("YHXM")!=null)
{
sql_where+=" and t.YHXM like ? ";
dataList.add("%"+data.get("YHXM")+"%");
}
}
sql+=sql_where+"order by t.ADDDATE desc";
String sql_pageHear="select * from ( select zt.*,rownum m from ( ";
String sql_pageFoot=" ) zt where rownum<=? ) where m>?";
String sql_all=sql_pageHear+sql+sql_pageFoot;
PreparedStatement ps=session.connection().prepareStatement(sql_all);
int index=1;
if(dataList!=null&&dataList.size()>0)
{
for(int i=0;i<dataList.size();i++)
{
ps.setString(index++, dataList.get(i));
}
}
ps.setInt(index++, pageNow*pageSize);
ps.setInt(index++, (pageNow-1)*pageSize);
System.out.println("executeSQL:"+sql_all);
ResultSet rs=ps.executeQuery();
List l=null;
try
{
if(rs!=null)
{
int pageCount=PageUnit.getPageCount(session,sql, dataList, pageSize);
int Total = PageUnit.getRowCount(session, sql, dataList);
l=new ArrayList();
while(rs.next())
{
Map m=new HashMap();
for(int i=0;i<rs.getMetaData().getColumnCount();i++)
{
String key=rs.getMetaData().getColumnName(i+1);
m.put(key, DBEncoding.EncodingOutputDB(rs.getString(key)));
if("null".equals(m.get(key)+""))
{
m.put(key,"");
}
}
m.put("pageCount", pageCount);
m.put("Total", Total);
l.add(m);
}
}
releaseSession(session);
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return l;
}
}
dao中的分页类
package com.common;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import org.hibernate.Session;
import com.tool.DBEncoding;
public class PageUnit{
public static int getPageCount(Session session,String sql, List<String> data, int pageSize)
throws Exception {
int pageCount=0;
int rowCount=0;
sql = "select count(*) from (" +sql+")";
PreparedStatement ps=session.connection().prepareStatement(sql);
int index=1;
if(data!=null&&data.size()>0)
{
for(int i=0;i<data.size();i++)
{
ps.setString(index++, DBEncoding.EncodingInputDB(data.get(i)+""));
}
}
System.out.println("executeSQL:"+sql);
ResultSet rs=ps.executeQuery();
try
{
if(rs!=null)
{
if(rs.next())
{
rowCount=Integer.parseInt(rs.getInt(1)+"");
}
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return pageCount;
}
public static int getRowCount(Session session,String sql,List<String> data) throws Exception{
//int pageCount=0;
int rowCount=0;
sql = "select count(*) from (" +sql+")";
PreparedStatement ps=session.connection().prepareStatement(sql);
int index=1;
if(data!=null&&data.size()>0)
{
for(int i=0;i<data.size();i++)
{
ps.setString(index++, DBEncoding.EncodingInputDB(data.get(i)+""));
}
}
System.out.println("executeSQL:"+sql);
ResultSet rs=ps.executeQuery();
try
{
if(rs!=null)
{
if(rs.next())
{
rowCount=Integer.parseInt(rs.getInt(1)+"");
}
}
}
finally
{
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
}
return rowCount;
}
}
service类
package com.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dao.UserDao;
public class UserService {
private UserDao userdao;
public UserDao getUserdao() {
return userdao;
}
public void setUserdao(UserDao userdao) {
this.userdao = userdao;
}
/**
* 带分页的查询用户信息
* @param data
* @param pageNow
* @param pageSize
* @return
*/
public List userList(Map data,int pageNow,int pageSize){
List list = new ArrayList();
try {
list = userdao.userList(data, pageNow, pageSize);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
这时候应该写个测试类来测试一下结果
package com.test;
import java.util.List;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.factory.SpringContextFactory;
import com.service.UserService;
public class UserDaoTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext act=SpringContextFactory.getSpringContext();
UserService us = (UserService)act.getBean("UserService");
List list = us.userList(null, 1, 10);
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
}
}
package com.factory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringContextFactory {
private static ClassPathXmlApplicationContext act=null;
public static ClassPathXmlApplicationContext getSpringContext()
{
if(act==null)
{
act=new ClassPathXmlApplicationContext("applicationContext.xml");
}
return act;
}
}
action 类
package com.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.factory.SpringContextFactory;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserService;
public class UserAction extends ActionSupport{
private int pageNow = 1;
private int pageSize = 10;
private JSONObject Rows;
private String action;
@SuppressWarnings("unchecked")
public String execute(){
//HttpServletRequest request=ServletActionContext.getRequest();
ClassPathXmlApplicationContext act=SpringContextFactory.getSpringContext();
UserService us = (UserService)act.getBean("UserService");
if(action.equals("ulist")){
List userList = us.userList(null, pageNow, pageSize);
/**
* json
*/
HashMap maprow = new HashMap();
if(userList!=null&&userList.size()>0){
String Total=(((Map)userList.get(0)).get("Total"))+"";
maprow.put("Rows", userList);
maprow.put("Total", Total);
}
Rows =JSONObject.parseObject(JSON.toJSONString(maprow));
System.out.println(Rows);
return SUCCESS;
}
return ERROR;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public JSONObject getRows() {
return Rows;
}
public void setRows(JSONObject rows) {
Rows = rows;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
}
struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="json-default">
<action name="UserAction" class="com.action.UserAction">
<result type="json">
<param name="root">Rows</param>
</result>
</action>
</package>
</struts>
下面来使用ligerui的ligerGrid查询显示列表数据,userlist.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户列表</title>
<%@include file="include/head.jsp" %>
<script type="text/javascript">
$(function(){
$("#mainGrid").ligerGrid({
title:"用户列表",
columns:[
{display:"主键",name:"ID",hide:"hidden"},
{display:"身份证号",name:"SFZH",width:200},
{display:"用户姓名",name:"YHXM",width:100},
{display:"用户性别",name:"STR_YHXB"},
{display:"手机号码",name:"PHONE"},
{display:"出生日期",name:"CSRQ"},
{display:"录入时间",name:"ADDDATE"},
{display:"有效标示",name:"YXBS"}
],
//data:docData,
url:'UserAction.action?action=ulist',
sortName: 'au_id',
width:"100%",height:"100%",checkbox:true,
pagesizeParmName:"pageSize",
pageParmName:"pageNow",
pageSize:10,
rowHeight:40,
rownumbers:true,usePager:true
});
})
</script>
</head>
<body>
<div id="mainGrid"></div>
</body>
</html>
显示结果
[img][/img]
只写了个查询的列子,后面的增、删、改都差不多啦!
相关推荐
在本教程中,我们将深入探讨如何结合LigerUI的Grid组件和Java的JSON数据来实现数据显示。Grid是LigerUI中的一个核心组件,用于展示表格数据,支持多种交互功能和自定义样式。 首先,我们需要理解LigerUI的Grid组件...
基于spring+struts2+ibatis开发的简单项目,里面有增加,修改,删除,查找功能,前台使用了ligerUI插件,需在jsp页面引用ligerUI的js文件,适合有一定jquery,java的初学者,并对ligerUI有一定的了解,否则将很难理解...
9. 与SpringMVC和LigerUI的整合:在整合Mybatis分页插件时,需要确保它能够与SpringMVC和前端框架LigerUI无缝对接。这涉及到后端处理分页数据的接口设计和前端展示分页数据的页面渲染。 10. 分页操作对用户体验的...
【标题】"spring+mybatis+ligerui案例源码"涉及了三个主要的Java开发框架:Spring、MyBatis和LigerUI。这三个组件在Web应用程序开发中扮演着至关重要的角色,尤其是对于后端逻辑处理和前端用户界面设计。 1. **...
通过这个项目,你不仅可以学习到Spring和Mybatis的整合,还能了解前端UI框架如何与后端数据交互,对Web开发有一个全面的认识。如果你对某个部分有疑问或者想进一步深入,可以从这个基础示例出发,逐步扩展和优化功能...
实际项目,修改数据库文件和对应的配置就能够自动生成数据库,可运行,springMVC的各种使用方式和aop的切面配置均可见到,里面spring4和hibernate4的整合配置弄了两天才解决,绝对物有所值
在这个特定的例子中,我们关注的是如何利用LigerUI进行储存过程分页查询,这在处理大量数据时非常有用,因为可以有效地减少服务器负载并提高用户界面的响应速度。 首先,`web.config`是ASP.NET应用程序的核心配置...
需要解压这个文件并查看其内部结构,包括但不限于Java源码、配置文件(如Spring的`applicationContext.xml`、Hibernate的`hibernate.cfg.xml`和DWR的`dwr.xml`)、HTML/JS前端文件(使用LigerUI的文件)等。...
LigerUI是一款基于JavaScript和CSS3的开源前端框架,它为开发者提供了丰富的UI组件和便捷的API接口,用于快速构建用户界面。此压缩包包含了LigerUI的全套源代码、API文档以及示例,旨在帮助开发者深入理解其内部工作...
LigerUI Table不仅具备基本的表格功能,如排序、筛选、分页,还提供了丰富的扩展特性,如导出Excel功能。这个功能使得用户能够方便地将网页上的数据导出到Excel文件中,以便于进一步的数据分析或存储。 标题"...
这个项目整合了ligerUI前端框架、Spring应用框架、Struts2 MVC框架、MyBatis持久层框架以及Oracle数据库,构建了一个完整的Web应用程序。 【描述】中提到,该项目是从CSDN网站下载并经过个人改良的,目的是简化后端...
LigerUI是一款基于JavaScript开发的前端用户界面框架,专为构建现代Web应用程序而设计。它提供了丰富的组件和灵活的配置选项,旨在简化开发者的工作,提高开发效率。LigerUI这个名字来源于“Liger”,象征着其融合了...
LigerUI是一款强大的JavaScript界面开发框架,主要用于构建高效、易用且美观的Web应用程序。它的V1.2.5版本提供了全面的组件和功能,帮助开发者实现列表、编辑和图标等界面元素的一体化集成。在这款压缩包“ligerui-...
jQuery ligerUI是一款基于jQuery的前端开发框架,它提供了一系列丰富的UI组件,使得开发者能够快速构建具有专业界面的Web应用程序。在"jQuery ligerUI Demos 导航页、菜单栏"这个主题中,我们将深入探讨ligerUI如何...
LigerUI 包含了大量的组件,如表格、表单、对话框、下拉菜单等,大大简化了前端开发工作。本文将深入解析其中文 API,帮助开发者更好地理解和应用这个强大的工具。 1. **基础使用** - **引入文件**:在项目中使用 ...
jquery+ligerUI+文档+demo,里面有文档,中文的,还有许多demo jquery+ligerUI+文档+demo,里面有文档,中文的,还有许多demo jquery+ligerUI+文档+demo,里面有文档,中文的,还有许多demo jquery+ligerUI+文档+...
虽然LigerUI是前端框架,但它可以很好地与Java后端框架如Spring MVC、Struts2等配合使用。前端通过Ajax与后端进行通信,发送请求获取数据,后端处理业务逻辑并返回结果。这种方式可以实现前后端分离,提高系统的可...
LigerUI 是一款功能强大且高效易用的前端框架,专门设计用于构建用户界面(UI)并优化Web应用程序的开发流程。这款框架以其出色的灵活性、丰富的组件库以及对JSON数据的强大支持而备受赞誉。在本文中,我们将深入...
LigerUI 1.2.5 是一个成熟的前端开发框架,专为构建高效、美观的Web应用程序而设计。这个框架提供了丰富的组件和功能,旨在简化开发者的工作,提高开发效率。"LigerUI1.2.5文档和库"的压缩包包含两个主要部分:...
ligerUI 教程API手册,方便查询