SSH_框架,java一个简单的查询,并显示在jsp页面上

//直接上代码

entity包下的实体类

 package entity;


import java.math.BigDecimal;


/**
 * MeUser entity. @author MyEclipse Persistence Tools
 */


public class MeUser implements java.io.Serializable {


// Fields


private Integer userId;
private String accountNum;
private String pwd;
private Integer typeId;
private String photoUrl;
private Integer integral;
private Integer credit;
private Integer lng;
private Integer lat;
private String companyIdentification;
private String invitationcode;
private String userName;
private BigDecimal userSex;
private String userIdcard;
private BigDecimal userAge;
private BigDecimal userState;
private BigDecimal serviceTimes;
private BigDecimal serviceAttitude;
private BigDecimal responseSpeed;


// Constructors


/** default constructor */
public MeUser() {
}


/** minimal constructor */
public MeUser(String accountNum, String pwd, Integer typeId, Integer integral,
Integer credit, BigDecimal serviceAttitude, BigDecimal responseSpeed) {
this.accountNum = accountNum;
this.pwd = pwd;
this.typeId = typeId;
this.integral = integral;
this.credit = credit;
this.serviceAttitude = serviceAttitude;
this.responseSpeed = responseSpeed;
}


/** full constructor */
public MeUser(String accountNum, String pwd, Integer typeId, String photoUrl,
Integer integral, Integer credit, Integer lng, Integer lat,
String companyIdentification, String invitationcode,
String userName, BigDecimal userSex, String userIdcard,
BigDecimal userAge, BigDecimal userState, BigDecimal serviceTimes,
BigDecimal serviceAttitude, BigDecimal responseSpeed) {
this.accountNum = accountNum;
this.pwd = pwd;
this.typeId = typeId;
this.photoUrl = photoUrl;
this.integral = integral;
this.credit = credit;
this.lng = lng;
this.lat = lat;
this.companyIdentification = companyIdentification;
this.invitationcode = invitationcode;
this.userName = userName;
this.userSex = userSex;
this.userIdcard = userIdcard;
this.userAge = userAge;
this.userState = userState;
this.serviceTimes = serviceTimes;
this.serviceAttitude = serviceAttitude;
this.responseSpeed = responseSpeed;
}


// Property accessors


public Integer getUserId() {
return this.userId;
}


public void setUserId(Integer userId) {
this.userId = userId;
}


public String getAccountNum() {
return this.accountNum;
}


public void setAccountNum(String accountNum) {
this.accountNum = accountNum;
}


public String getPwd() {
return this.pwd;
}


public void setPwd(String pwd) {
this.pwd = pwd;
}


public Integer getTypeId() {
return this.typeId;
}


public void setTypeId(Integer typeId) {
this.typeId = typeId;
}


public String getPhotoUrl() {
return this.photoUrl;
}


public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}


public Integer getIntegral() {
return this.integral;
}


public void setIntegral(Integer integral) {
this.integral = integral;
}


public Integer getCredit() {
return this.credit;
}


public void setCredit(Integer credit) {
this.credit = credit;
}


public Integer getLng() {
return this.lng;
}


public void setLng(Integer lng) {
this.lng = lng;
}


public Integer getLat() {
return this.lat;
}


public void setLat(Integer lat) {
this.lat = lat;
}


public String getCompanyIdentification() {
return this.companyIdentification;
}


public void setCompanyIdentification(String companyIdentification) {
this.companyIdentification = companyIdentification;
}


public String getInvitationcode() {
return this.invitationcode;
}


public void setInvitationcode(String invitationcode) {
this.invitationcode = invitationcode;
}


public String getUserName() {
return this.userName;
}


public void setUserName(String userName) {
this.userName = userName;
}


public BigDecimal getUserSex() {
return this.userSex;
}


public void setUserSex(BigDecimal userSex) {
this.userSex = userSex;
}


public String getUserIdcard() {
return this.userIdcard;
}


public void setUserIdcard(String userIdcard) {
this.userIdcard = userIdcard;
}


public BigDecimal getUserAge() {
return this.userAge;
}


public void setUserAge(BigDecimal userAge) {
this.userAge = userAge;
}


public BigDecimal getUserState() {
return this.userState;
}


public void setUserState(BigDecimal userState) {
this.userState = userState;
}


public BigDecimal getServiceTimes() {
return this.serviceTimes;
}


public void setServiceTimes(BigDecimal serviceTimes) {
this.serviceTimes = serviceTimes;
}


public BigDecimal getServiceAttitude() {
return this.serviceAttitude;
}


public void setServiceAttitude(BigDecimal serviceAttitude) {
this.serviceAttitude = serviceAttitude;
}


public BigDecimal getResponseSpeed() {
return this.responseSpeed;
}


public void setResponseSpeed(BigDecimal responseSpeed) {
this.responseSpeed = responseSpeed;
}


}

//Dao包下,自定义接口

package Dao;


import java.util.List;


import entity.MeUser;


public interface UserDao {
public List<MeUser> douser();


}

//Dao包下,自定义接口实现类

package Dao.Impl;


import java.util.List;


import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


import entity.MeUser;
import Dao.UserDao;


public class IUserDaoImpl extends HibernateDaoSupport implements UserDao {


public List<MeUser> douser() {
String hql="from MeUser";
return super.getHibernateTemplate().find(hql);   //查询方法
}


}

//Biz包下,自定义的接口

package Biz;


import java.util.List;


import entity.MeUser;


public interface UserBiz {
public List<MeUser> douser();
}

//Biz包下,自定义的接口实现类

package Biz.Impl;


import java.util.List;


import entity.MeUser;
import Biz.UserBiz;
import Dao.UserDao;


public class UserBizImpl implements UserBiz {
private UserDao userDao;




public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}






public List<MeUser> douser() {
// TODO Auto-generated method stub
return userDao.douser();
}


}

// web包下的 action

package web;


import java.util.List;


import net.sf.json.JSONArray;


import Biz.UserBiz;


import com.opensymphony.xwork2.ActionSupport;


import entity.MeUser;


public class userAction extends ActionSupport {
private UserBiz userBIZ;

private List<MeUser>list;
private MeUser user;




public List<MeUser> getList() {
return list;
}


public void setList(List<MeUser> list) {
this.list = list;
}


public MeUser getUser() {
return user;
}


public void setUser(MeUser user) {
this.user = user;
}


public void setUserBIZ(UserBiz userBIZ) {
this.userBIZ = userBIZ;
}
@Override
public String execute() throws Exception {
System.out.println("以进入action");
return super.execute();
}
public String doSelect() throws Exception {
System.out.println("进入doSelect()方法");
list=userBIZ.douser();
user=list.get(0);
String json = JSONArray.fromObject(list).toString();
System.out.println(json);
return SUCCESS;
}
//applicationContext.xml配置信息

<?xml version="1.0" encoding="UTF-8"?>
<!-- 头部信息,添加了tx,aop声明配置 -->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/tx
     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="jsmen"></property>
<property name="password" value="jsmen"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>entity/MeUser.hbm.xml</value></list>
</property></bean>

<!-- Spring事物控制(开始) -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED"
read-only="true" />
<tx:method name="find*" propagation="REQUIRED"
read-only="true" />
<tx:method name="search*" propagation="REQUIRED"
read-only="true" />
<tx:method name="query*" propagation="REQUIRED"
read-only="true" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="submit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="check*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- Spring事物控制(结束) -->


        <!-- 日志增强性处理(开始) -->
<bean id="aroundLogger" class="util.AroundLogger"></bean>
<!-- 日志增强性处理(结束) -->



<!-- SpringAOP配置(开始)注意:org.accp.biz是具体业务层的包名,要随着业务层的变化而修改! -->
<aop:config proxy-target-class="true"> 
<aop:pointcut id="bizMethod"
expression="execution(* org.accp.biz.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethod" />
                <aop:advisor advice-ref="aroundLogger" pointcut-ref="bizMethod"/>
</aop:config>
<!-- SpringAOP配置(结束) -->

<!-- BEAN 配置(开始) -->
        <bean id="userDAO" class="Dao.Impl.IUserDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userBIZ" class="Biz.Impl.UserBizImpl">
<property name="userDao" ref="userDAO" />
</bean>
<bean id="UserAction" class="web.userAction"
>
<property name="userBIZ" ref="userBIZ" />
</bean>

<!-- BEAN 配置(结束) -->
</beans>


}


//log4j.properties日志文件配置信息

log4j.rootCategory=INFO, stdout , R


log4j.appender.stdout=org.apache.log4j.ConsoleAppender


log4j.appender.stdout.layout=org.apache.log4j.PatternLayout


log4j.appender.stdout.layout.ConversionPattern=[SSH] %p [%t] %C.%M(%L) | %m%n


log4j.appender.R=org.apache.log4j.DailyRollingFileAppender  


log4j.appender.R.File=${webName.root}/WEB-INF/logs/log.log


log4j.appender.R.layout=org.apache.log4j.PatternLayout
 
log4j.appender.R.DatePattern  ='.'yyyy-MM-dd  


log4j.appender.R.layout.ConversionPattern=[SSH] %p [%t] %C.%M(%L) | %m%n


log4j.logger.org.springframework=error


log4j.logger.com.ibatis.db=error


log4j.logger.org.hibernate=error


log4j.logger.org.hibernate.ps.PreparedStatementCache=error

//struts.xml配置信息

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 常量设置开始 -->
<!-- 主题的显示模式 -->
<constant name="struts.ui.theme" value="simple" />
<!-- 禁止动态调用方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 修改类型转换错误的消息通知 -->
<constant name="struts.custom.i18n.resources" value="message"/>
<!-- struts 乱码处理 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 常量设置结束 -->
<package name="default" namespace="/" extends="struts-default">
<!-- 拦截器配置(开始) -->
<!-- 拦截器配置(结束) -->
<!-- 默认Action配置(开始) -->
<default-action-ref name="defaultAction" />
<!-- 默认Action配置(结束) -->
<!-- 全局结果集配置(开始) -->
<global-results>
<result name="error">error.jsp</result>
<result name="input">${inputPage}</result>
</global-results>
<!-- 全局结果集配置(结束) -->
<action name="defaultAction">
<result>error.jsp</result>
</action>
<action name="android" class="UserAction" method="doSelect">
<result name="success">index.jsp</result>
</action>

</package>
</struts>    


// web.xml 配置信息

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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>
   
  <!-- Spring配置(开始) -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
  <!-- Spring配置(结束) -->
  <!-- LOG4J日志配置(开始) -->
<context-param>
<param-name>webName</param-name>
<param-value>webName.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>3000</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
  <!-- LOG4J日志配置(结束)-->
  
  <!-- openSessionInViewFilter(开始) -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
  <!-- openSessionInViewFilter(结束) -->
  
  </web-app>

// 环绕日志增强

package util;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;


import com.sun.org.apache.bcel.internal.generic.NEW;


/**
 * 
 ***************************************************************
 * @类名 : AroundLogger
 * @描述 : 配置具体环绕日志增强
 * @作者 : jsmen
 * @版本 : v1.0
 * @日期 : 2015-01-07          
 * 
 * @最后修改日志 :
 * @修改人 :
 * @修订后版本 : v2.0
 * @修改时间 :  
 ****************************************************************
 */
public class AroundLogger implements MethodInterceptor {

// LOG4J日志对象
private static final Logger LOG = Logger.getLogger(AroundLogger.class);

public Object invoke(MethodInvocation invocation) throws Throwable {
// 获取类名
String className = invocation.getThis().getClass().getName();
// 获取具体执行方法名称
String methodName = invocation.getMethod().getName();
// 接收具体参数名称
String parms = Arrays.toString(invocation.getArguments());

// 1.前置的日志增强处理
StringBuilder beforeLogBuilder = new StringBuilder();
beforeLogBuilder.append("\r++++++++++++++++++++++前置方法增强日志(开始)+++++++++++++++++++++++++++++++\r");
beforeLogBuilder.append("执行时间:"+UtilConstants.SIMPLE_FORMAT_TWO.format(new Date())+"\r");
beforeLogBuilder.append("当前运行类:" + className+"\r");
beforeLogBuilder.append("当前执行方法:" + methodName+"\r");
beforeLogBuilder.append("当前方法参数列表:" + parms+"\r");
beforeLogBuilder.append("++++++++++++++++++++++前置方法增强日志(结束)+++++++++++++++++++++++++++++++"+"\r");

// 记录日志
LOG.info(beforeLogBuilder.toString());
try {
Object result = invocation.proceed();
// 2. 后置的日志增强处理
StringBuilder afterLogBuilder = new StringBuilder();
afterLogBuilder.append("\r++++++++++++++++++++++后置方法增强日志(开始)+++++++++++++++++++++++++++++++\r");
afterLogBuilder.append("执行时间:"+UtilConstants.SIMPLE_FORMAT_TWO.format(new Date())+"\r");
afterLogBuilder.append("当前运行类:" + className+"\r");
afterLogBuilder.append("当前执行方法:" + methodName+"\r");
afterLogBuilder.append("当前方法返回值:" + result+"\r");
afterLogBuilder.append("++++++++++++++++++++++后置方法增强日志(结束)+++++++++++++++++++++++++++++++\r");

// 记录日志
LOG.info(afterLogBuilder.toString());
return result;
} catch (Exception e) {
//3. 异常日志增强处理
StringBuilder errorLogBuilder = new StringBuilder();
errorLogBuilder.append("\r++++++++++++++++++++++异常方法增强日志(开始)+++++++++++++++++++++++++++++++\r");
errorLogBuilder.append("执行时间:"+UtilConstants.SIMPLE_FORMAT_TWO.format(new Date())+"\r");
errorLogBuilder.append("当前运行类:" + className+"\r");
errorLogBuilder.append("当前执行方法:" + methodName+"\r");
errorLogBuilder.append("当前方法执行出错,返回的错误信息:" + e.getMessage()+"\r");
errorLogBuilder.append("++++++++++++++++++++++异常方法增强日志(结束)+++++++++++++++++++++++++++++++\r");

//日志记录
LOG.error(errorLogBuilder.toString());
throw e;
}


}


}



  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值