action类如下

package com.itheima.movenweb.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.junit.Test; import com.itheima.movenweb.domain.Dep;
import com.itheima.movenweb.service.Service;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; public class Action extends ActionSupport { private Service service; public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String findDepList(){
System.out.println(1);
List<Dep> list = service.dolist();
System.out.println(service);
ServletActionContext.getRequest().setAttribute("list", list);
return "success";
} }

serviceImpl如下:

package com.itheima.movenweb.serviceImpl;

import java.util.List;

import org.junit.Test;

import com.itheima.movenweb.dao.Dao;
import com.itheima.movenweb.domain.Dep;
import com.itheima.movenweb.service.Service; public class ServiceImpl implements Service { private Dao dao; public Dao getDao() {
return dao;
} public void setDao(Dao dao) {
this.dao = dao;
} @Override
public List<Dep> dolist() {
System.out.println(2);
List<Dep> list = dao.dolist();
return list;
} }

daoImpl如下:

package com.itheima.movenweb.daoImpl;

import java.util.List;

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

import com.itheima.movenweb.dao.Dao;
import com.itheima.movenweb.domain.Dep; public class DaoImpl extends HibernateDaoSupport implements Dao{ @Override
public List<Dep> dolist() {
System.out.println(3);
List<Dep> list = (List<Dep>) this.getHibernateTemplate().find("from Dep");
return list;
} }

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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
"> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 在这里方法上开启事务,不要搞错了 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="list" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="serviceMethod" expression="execution(* com.itheima.movenweb.serviceImpl.*.*(..))"/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="advice" />
</aop:config> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!--
<property name="url" value="jdbc:mysql://127.0.0.1:3306/movenwebtest?useUnicode=true&characterEncoding=UTF8"/>
-->
<property name="url" value="jdbc:mysql:///movenwebtest11?useUnicode=true&characterEncoding=UTF8"/>
<property name="username" value="root"/>
<property name="password" value="123"/>
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath:com/itheima/movenweb/domain/*.hbm.xml</value>
</property>
</bean> <!-- 部门数据访问类 -->
<bean id="depDao" class="com.itheima.movenweb.daoImpl.DaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 部门业务逻辑类 -->
<bean id="depService" class="com.itheima.movenweb.serviceImpl.ServiceImpl">
<property name="dao" ref="depDao"></property>
</bean> <!-- 部门action -->
<bean id="depAction" class="com.itheima.movenweb.action.Action">
<property name="service" ref="depService"></property>
</bean> </beans>

  struts.xml 如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="index" class="depAction" method="findDepList">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

还有hibernate的配置文件,我报错的原因和他没有关系,我就不放在这里了;以上的代码是修改后正确的代码;

下面我放入我错误的代码,第一个错误在struts2的配置文件,我将class的配置信息配成了类的全路径,然后报空指针异常,这里class的路径应该写已经配置在applicationContext.xml中的action的id的值

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="index" class="com.itheima.movenweb.domain.Dep" method="findDepList">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

  然后又出了一个问题:如下

我的action中的输出语句输出了,但是我的数据库没有连接上,我去查询我的数据库,发现我的数据库名字是“mavenwebtest11;”  对,你没有看错,我的数据库名字多加了“;”我发现我在创建数据库后本来是想加上英文状态的结束符号,结果加成了中文的结束符号,然后就被一起写进了数据库的名字中,大写的尴尬呀,作为我的第一篇博客,谨以此来激励自己不断学习,不断成长

最新文章

  1. 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005
  2. testng 教程之使用参数的一些tricks配合使用reportng
  3. nodejs授权连接mongodb
  4. 【Linux驱动】内核等待队列
  5. Struts2应用流程注解
  6. StringUtils工具类的常用方法
  7. codeforce Number of Ways(暴力)
  8. 《Nagios系统监控实践》一书出版
  9. 【shell】while read line 与for循环的区别
  10. 让IE支持Css3属性(圆角、阴影、渐变)
  11. 转载 VC 2010下安装OpenCV2.4.4
  12. Meth | phpstorm invalid descendent file name
  13. vector的含义
  14. 设置Cacti图形标题能显示中文
  15. matplotlib绘图总结
  16. 不能将“this”指针从“const SqQueue&lt;ElementType&gt;”转换为“SqQueue&lt;ElementType&gt; &amp;
  17. linux(rhel) rescue修复详解
  18. Javascript 浮点计算问题分析与解决
  19. SpringBoot 使用小技巧合集
  20. 常用LLDB指令

热门文章

  1. Android初级教程初谈自定义view自定义属性
  2. Cocos2D瓦块地图高清屏(retina)显示比例问题的解决
  3. android布局Relative和gridLayout-android学习之旅(十六)
  4. Windows下多线程数据同步互斥的有关知识
  5. Android实现登录小demo
  6. [GitHub]第六讲:开源项目贡献流程
  7. Java进阶(三十一) Web服务调用
  8. ROS(indigo)国外开源示例包括多机器人控制等基于V-Rep和Gazebo的仿真
  9. UNIX环境高级编程——管道读写规则和pipe Capacity、PIPE_BUF
  10. Bootstrap模板代码+页面自适应页面的案例代码