一. SpringMVC

阅读我的上一篇文章《使用MyEclipse2015构建SpringMVC项目》,知道基本的构建方法,先构建一个纯springmvc项目,再对web.xml按照本文中做法简单改动。

二. Hibernate

之后用类似方法添加hibernate框架,并生成hibernate.cfg.xml和HibernateSessionFactory.java这个工厂文件。

进入MyEclipse Database Explorer,首先添加自己的服务器,之后,连接服务器,在所需的表(可多选)上右键Hibernate Reverse Engineering,根据所需功能生成实体类,不要忘记选择好主键策略。

三. Spring

这里给出只用springmvc-servlet.xml而不使用application.xml的方法

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <display-name>Spring4</display-name>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:springmvc-servlet.xml</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
View Code

相关文章: