为了账号安全,请及时绑定邮箱和手机立即绑定

使用Struts2+Hibernate开发学生信息管理功能

  • 不知道哪年出的视频 不过方法已经弃用了,下面是2016-11月可以使用的方法 Configuration configuration = new Configuration().configure(); ServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); SessionFactory sessionfactory = configuration.buildSessionFactory(registry); Session session = sessionfactory.getCurrentSession(); MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(registry).buildMetadata(); SchemaExport export = new SchemaExport(registry,metadata); export.create(true,true);
    查看全部
    7 采集 收起 来源:生成表结构

    2016-11-15

  • 在validate中验证有错误的话且没有指定return 字符串的话, struts2默认就返回的是 return INPUT 也就是return "input",所以要在struts.xml中配置<result name="input">/users/Users_login.jsp</result>
    查看全部
  • 配置web.xml文件 <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>
    查看全部
  • Struts2与hibernate整合 (1)创建struts2和hibernate用户类库 (2)导入struts2与hibernate的jar包 (3)配置web.xml (4)创建struts.xml (5)配置hibernate.cfg.xml 1、配置hibernate.cfg.xml文件 <property name="connection.username">root</property> <property name="connection.password"></property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///test?useUnicode=true&amp;characterEncoding=UTF-8</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <property name="hibernate.current_session_context_class">thread</property> 2、配置web.xml文件 <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>
    查看全部
  • 添加用户库的时候,一定不能有相同的jar包,否则会出错,尤其是用myeclipse自带的库时,struts和hibernate会有个相同的jar包,antlr.jar,将较低版本的去掉即可,建议自己添加User Library
    查看全部
  • Query query = session.createQuery(hql);处抛出 UndeclaredThrowableException 异常,是因为有相同的jar包,myeclipse自带的struts和hibernate有相同antlr.jar,把低版本的那个去掉就行了,建议自己添加User Library,把需要的jar包放进去
    查看全部
  • Struts2与Hibernate整合:
        1. 创建struts2和hibernate用户类库
        2. 导入struts2与hibernate的jar包
        3. 配置web.xml文件(加入struts2的过滤器)
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> // struts2过滤器
        </filter>
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>  // 过滤所有请求
        </filter-mapping>
        4. 创建struts.xml
         WEB-INF/classes/struts.xml --> src/struts.xml
         <package name="default" namespace="/" extends="struts-default">
        
         </package>
        5. 配置hibernate.cfg.xml(hibernate的主配置文档)
        src/hibernate.cfg.xml
      <hibernate-configuration>
       <session-factory>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="connection.driver_class">com.mysql.jbdc.Driver</property>
        <property
            name="connection.url">jdbc:mysql:///test?useUnicode=true&amp;characterEncoding=UTF-8</property>
        <property name="dialect">org.hibernate.dialet.MySQLDialect</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hbm2dd1.auto">update</property>
        <property name="hibernate.current_session_context_class">thread</property>// 使用getCurrentSession方式打开会话
       </session-factory>
      </hibernate-configuration>


    查看全部
  • 5.1以上版本,方法发生变化了。 public void createTable() { // 注册 StandardServiceRegistry StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); // 通过 StandardServiceRegistry 和 Metadata 方法 得到 SessionFactory Metadata metadata = new MetadataSources(registry).buildMetadata(); SchemaExport export = new SchemaExport(); System.out.println(export.toString()); export.create(EnumSet.of(TargetType.DATABASE), metadata); }
    查看全部
    3 采集 收起 来源:生成表结构

    2017-01-25

  • 添加Action: 第一步:在StudentsAction中添加 public String add() throws ParseException { StudentsDao sdao = new StudentsDaoImpl(); String Sname = request.getParameter("sname"); String Sgender = request.getParameter("gender"); String Sbirthday = request.getParameter("birthday"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = simpleDateFormat.parse(Sbirthday); String Saddress = request.getParameter("address"); Students s = new Students(); s.setAddress(Saddress); s.setBirthday(date); s.setGender(Sgender); s.setSname(Sname); sdao.addStudents(s); return "add_success"; } 第二步:在stucts.xml中添加 <result name="add_success">/students/Students_add_success.jsp</result> PS:如果网页中日期一栏无法选择,是因为你没有把素材中的js文件夹拷贝到WebContent目录下。注意路径。
    查看全部
  • public String add() throws ParseException {<br> StudentsDao sdao=new StudentsDaoImpl();<br> String Sname=request.getParameter("sname");<br> String Sgender=request.getParameter("gender");<br> String Sbirthday=request.getParameter("birthday");<br> SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");<br> Date date=simpleDateFormat.parse(Sbirthday);<br> String Saddress=request.getParameter("address");<br> Students s=new Students();<br> s.setAddress(Saddress);<br> s.setBirthday(date);<br> s.setGender(Sgender);<br> s.setSname(Sname);<br> sdao.addStudents(s);<br> return "add_success";<br> }<br> 然后再添加xml文件
    查看全部
  • 配置hibernate.cfg.xml文件 <property name="connection.username">root</property> <property name="connection.password"></property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///test?useUnicode=true&amp;characterEncoding=UTF-8</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <property name="hibernate.current_session_context_class">thread</property> <!-- 使用getCurrentSession方式打开会话 -->
    查看全部
  • 添加学生资料: 1.界面原型演示 2.编写添加学生业务逻辑代码 3.编写添加action 4.页面调用
    查看全部
  • Struts2与hibernate整合 (1)创建struts2和hibernate用户类库 (2)导入struts2与hibernate的jar包 (3)配置web.xml (4)创建struts.xml (5)配置hibernate.cfg.xml
    查看全部
  • 生成表结构:
    // 创建配置对象
    Configuration config = new Configuration().configue();
    // 创建服务注册对象
    ServiceReqistry serviceReqistry = new ServiceRegistryBuilder().applySetting(config);
    // 创建sessionFactory
    SessionFactory sessionFactory = config.buildeSessionFactory(serviceReqistry);
    // 创建session对象
    Session session = sessionFactory.getCurrentSession();
    // 创建schemaExport对象
    SchemaExport export = new SchemaExport(config);
    
    export.create(true, true); // 第一个true表示生成表结构,第二个表示输出SQL语句


    查看全部
    2 采集 收起 来源:生成表结构

    2018-09-11

  • 在hibernate4.2中我们使用如下方式创建ServiceRegistry对象: ServiceRegistry serviceRegistry= new ServiceRegistrybuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); 在hibernate5.0.2中buildServiceRegistry方法被替换掉了我们使用如下方式去创建ServiceRegistry对象: ServiceRegistry serviceRegistry= new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    查看全部
    2 采集 收起 来源:生成表结构

    2017-12-28

首页上一页1234567下一页尾页

举报

0/150
提交
取消
课程须知
各位小伙伴,学习本课程前需要对 Struts2和Hibernate的基础知识有所了解。
老师告诉你能学到什么?
1、掌握Struts2和Hibernate的整合开发 2、能够使用Struts2+Hibernate独立开发信息管理类的项目,进行数据的增删改查。

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!