亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

springmvc+spring+hibernate配置過程

發布時間:2020-08-14 14:32:04 來源:網絡 閱讀:828 作者:o鳳舞九天o 欄目:開發技術

開發工具:eclipse

項目目錄:springmvc+spring+hibernate配置過程


jar包:

springmvc+spring+hibernate配置過程


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" metadata-complete="true">
  <display-name>SMSH</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:hanxuanyuan/config/spring-*.xml</param-value>
  </context-param>
  
  
   <!-- 配置Spring的用于初始化容器對象的監聽器 -->
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- 中央控制器  -->
  <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*:hanxuanyuan/config/springmvc-servlet.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
  
  <!-- 配置Session -->  
  <filter>  
    <filter-name>openSession</filter-name>  
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>  
  </filter>  
  <filter-mapping>  
    <filter-name>openSession</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
  
</web-app>

springmvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  
 xmlns:context="http://www.springframework.org/schema/context"  
 xmlns:p="http://www.springframework.org/schema/p"  
 xmlns:mvc="http://www.springframework.org/schema/mvc"  
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 xsi:schemaLocation="http://www.springframework.org/schema/beans  
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
      http://www.springframework.org/schema/context  
      http://www.springframework.org/schema/context/spring-context.xsd  
      http://www.springframework.org/schema/mvc  
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
       
    <!-- 啟用注解 -->
    <mvc:annotation-driven/>
    
   <!--  靜態資源訪問 --> 
   <!--  <mvc:resources location="/js/" mapping="/js/**" /> -->
    
    <!-- 掃描包 -->
    <context:component-scan base-package="hanxuanyuan.controller" />
    
  <!-- 視圖配置 -->
  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/"></property>
  <property name="suffix" value=".jsp"></property>
  </bean>
  
</beans>


spring-hibernate.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!--  自動掃描與裝配bean -->
<context:component-scan base-package="hanxuanyuan"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:demo">
</property>
<property name="username" value="test"></property>
<property name="password" value="test"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
 org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="configLocations">
<list>
<value>
classpath*:hanxuanyuan/config/hibernate.cfg.xml
</value>
</list>
</property>  
</bean>
  <!--   配置聲明式事務管理(采用注解的方式)-->
 <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
 <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <bean id="txBase" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true">
 <property name="transactionManager" ref="transactionManager"></property>
 <property name="transactionAttributes">
 <props>
 <prop key="add*">PROPAGATION_REQUIRED,-Exception </prop>
 <prop key="update*">PROPAGATION_REQUIRED,-Exception </prop>
 <prop key="insert*">PROPAGATION_REQUIRED,-Exception </prop>
 <prop key="modify*">PROPAGATION_REQUIRED,-Exception </prop>
 <prop key="get*">PROPAGATION_NEVER</prop>
 </props>
 </property>
 </bean>
 
</beans>


spring-bean.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
  <bean id="userDao" class="hanxuanyuan.Dao.UserDaoImpl">
   <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
 
    <bean id="userServiceBase" class="hanxuanyuan.service.UserServiceImpl">
   <property name="userDao" ref="userDao"></property>
  </bean>
  
  <bean id="userService" parent="txBase">
  <property name="target" ref="userServiceBase"></property>
  </bean>
 
</beans>


hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <mapping class="hanxuanyuan.entity.GYh"/>
    </session-factory>
</hibernate-configuration>


UserController.java

package hanxuanyuan.controller;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import hanxuanyuan.entity.GYh;
import hanxuanyuan.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Resource(name="userService")
private UserService userService ;
@RequestMapping("/list")
public String list(){
return "userlist" ;
}
@RequestMapping("/add")
public String add(GYh gyh,Model model ,HttpServletRequest request){
userService.addUser(gyh);
List<GYh> list = userService.queryList() ;
model.addAttribute("list", list);
return "userlist" ;
}
}


后臺向前臺傳值方式:放入model.addAtribute()中


entity: GYh.java

package hanxuanyuan.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
 * GYh entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name="G_YH")
public class GYh implements java.io.Serializable {
// Fields
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="payablemoney_seq")  
@SequenceGenerator(name="payablemoney_seq", sequenceName="SEQ_ID")  
private Long id;
private String yhlx01;
private String yhlx02;
private String xm;
private String dm;
private String dw;
private String sfz;
private String jgz;
private String yjgz;
private String grdh;
private String mm;
private String sm;
private String cjsj;
private String zt;
private Long ryid;
private String dwid;
private String zzmc;
// Constructors
/** default constructor */
public GYh() {
}
/** full constructor */
public GYh(String yhlx01, String yhlx02, String xm, String dm, String dw,
String sfz, String jgz, String yjgz, String grdh, String mm,
String sm, String cjsj, String zt,Long ryid, String dwid, String zzmc) {
this.yhlx01 = yhlx01;
this.yhlx02 = yhlx02;
this.xm = xm;
this.dm = dm;
this.dw = dw;
this.sfz = sfz;
this.jgz = jgz;
this.yjgz = yjgz;
this.grdh = grdh;
this.mm = mm;
this.sm = sm;
this.cjsj = cjsj;
this.zt = zt;
this.ryid = ryid;
this.dwid = dwid;
this.zzmc = zzmc;
}
// Property accessors
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getYhlx01() {
return this.yhlx01;
}
public void setYhlx01(String yhlx01) {
this.yhlx01 = yhlx01;
}
public String getYhlx02() {
return this.yhlx02;
}
public void setYhlx02(String yhlx02) {
this.yhlx02 = yhlx02;
}
public String getXm() {
return this.xm;
}
public void setXm(String xm) {
this.xm = xm;
}
public String getDm() {
return this.dm;
}
public void setDm(String dm) {
this.dm = dm;
}
public String getDw() {
return this.dw;
}
public void setDw(String dw) {
this.dw = dw;
}
public String getSfz() {
return this.sfz;
}
public void setSfz(String sfz) {
this.sfz = sfz;
}
public String getJgz() {
return this.jgz;
}
public void setJgz(String jgz) {
this.jgz = jgz;
}
public String getYjgz() {
return this.yjgz;
}
public void setYjgz(String yjgz) {
this.yjgz = yjgz;
}
public String getGrdh() {
return this.grdh;
}
public void setGrdh(String grdh) {
this.grdh = grdh;
}
public String getMm() {
return this.mm;
}
public void setMm(String mm) {
this.mm = mm;
}
public String getSm() {
return this.sm;
}
public void setSm(String sm) {
this.sm = sm;
}
public String getCjsj() {
return this.cjsj;
}
public void setCjsj(String cjsj) {
this.cjsj = cjsj;
}
public String getZt() {
return this.zt;
}
public void setZt(String zt) {
this.zt = zt;
}
public Long getRyid() {
return ryid;
}
public void setRyid(Long ryid) {
this.ryid = ryid;
}
@Override
public String toString() {
return "GYh [id=" + id + ", yhlx01=" + yhlx01 + ", yhlx02=" + yhlx02 + ", xm=" + xm + ", dm=" + dm + ", dw="
+ dw + ", sfz=" + sfz + ", jgz=" + jgz + ", yjgz=" + yjgz + ", grdh=" + grdh + ", mm=" + mm + ", sm="
+ sm + ", cjsj=" + cjsj + ", zt=" + zt + ", ryid=" + ryid + "]";
}
public String getDwid() {
return dwid;
}
public void setDwid(String dwid) {
this.dwid = dwid;
}
public String getZzmc() {
return zzmc;
}
public void setZzmc(String zzmc) {
this.zzmc = zzmc;
}
}


項目源碼鏈接:http://down.51cto.com/data/2302295

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

崇礼县| 武城县| 轮台县| 宝山区| 辛集市| 兰西县| 突泉县| 敦化市| 通榆县| 乡城县| 商河县| 额济纳旗| 邵东县| 大竹县| 正蓝旗| 岳池县| 且末县| 新沂市| 麻江县| 潞城市| 绥化市| 龙南县| 韶山市| 黄石市| 怀化市| 绿春县| 东兰县| 衡阳县| 永城市| 龙陵县| 南江县| 益阳市| 新巴尔虎左旗| 桃园市| 小金县| 六安市| 南开区| 莱州市| 彭水| 邵阳市| 喀什市|