ssm+orcle怎么搭

本文详细介绍了如何搭建SSM(Spring、Struts、MyBatis)与Oracle数据库的整合项目,包括各层结构、代码实现、XML配置、数据库连接、依赖库引入以及Web配置等,提供了一步步的操作指南和必要的资源链接。
摘要由CSDN通过智能技术生成
                                                **#ssm+orcle怎么搭**

这是我的结构
在这里插入图片描述
上层结构
在这里插入图片描述
action代码:

//---------------------------------------------------代码-------------------------------
package com.sun.action;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.alibaba.fastjson.JSON;
import com.sun.UserServcies.I.DemoServciesM;
import com.sun.pojo.Demo;


@Controller
public class Demoaction {
	@Autowired
    private DemoServciesM demoServciesM;



	
	public DemoServciesM getDemoServciesM() {
		return demoServciesM;
	}


	public void setDemoServciesM(DemoServciesM demoServciesM) {
		this.demoServciesM = demoServciesM;
	}




	@RequestMapping(value="/show")
	@ResponseBody	
	public String addpao(Model model,String name){
      	
		List<Demo> providerList = new ArrayList<Demo>();
		System.out.println(name);
		providerList = demoServciesM.show(name);
		//鎶妏roviderList杞崲鎴恓son瀵硅薄杈撳嚭
		
		String json=JSON.toJSONStringWithDateFormat(providerList, "yyyy-MM-dd");

		System.out.println(".."+json);
		return json;
	}
	
	
	@RequestMapping(value="/updatepao")
public String updatepao(Model model,String id){
      	
	Demo providerList =null;
		
		providerList = demoServciesM.show1(id);
		//鎶妏roviderList杞崲鎴恓son瀵硅薄杈撳嚭
		model.addAttribute("Demo",providerList);
		return "/update.jsp";
	}
	
	@RequestMapping(value="/update")
public String update(Model model,String id,String gai){
      	
	    System.out.println(gai);		
		 demoServciesM.update(id,gai);
		//鎶妏roviderList杞崲鎴恓son瀵硅薄杈撳嚭
		
		return "/index.jsp";
	}
	
	
}

实体类com.sun.pojo的代码:

package com.sun.pojo;

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

public class Demo {
    private int good_Id;
    private String good_name;
    private String good_Price;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date good_Product_Date;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date good_In_Date;
    private String good_Company;

public int getGood_Id() {
	return good_Id;
}
public void setGood_Id(int good_Id) {
	this.good_Id = good_Id;
}
public String getGood_name() {
	return good_name;
}
public void setGood_name(String good_name) {
	this.good_name = good_name;
}
public String getGood_Price() {
	return good_Price;
}
public void setGood_Price(String good_Price) {
	this.good_Price = good_Price;
}
public Date getGood_Product_Date() {
	return good_Product_Date;
}
public void setGood_Product_Date(Date good_Product_Date) {
	this.good_Product_Date = good_Product_Date;
}
public Date getGood_In_Date() {
	return good_In_Date;
}
public void setGood_In_Date(Date good_In_Date) {
	this.good_In_Date = good_In_Date;
}
public String getGood_Company() {
	return good_Company;
}
public void setGood_Company(String good_Company) {
	this.good_Company = good_Company;
}

com.sun.tools类为工具类不需要但是我这里也做展示:

Constants类:

package com.sun.tools;

public class Constants {
	public final static String USER_SESSION = "userSession";
	public final static String SYS_MESSAGE = "message";
	public final static int pageSize = 5;
}

PageSupport类:

package com.sun.tools;

public class PageSupport {
	//褰撳墠椤电爜-鏉ヨ嚜浜庣敤鎴疯緭鍏?
	private int currentPageNo = 1;
	
	//鎬绘暟閲忥紙琛級
	private int totalCount = 0;
	
	//椤甸潰瀹归噺
	private int pageSize = 0;
	
	//鎬婚〉鏁?totalCount/pageSize锛?1锛?
	private int totalPageCount = 1;

	public int getCurrentPageNo() {
		return currentPageNo;
	}

	public void setCurrentPageNo(int currentPageNo) {
		if(currentPageNo > 0){
			this.currentPageNo = currentPageNo;
		}
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		if(totalCount > 0){
			this.totalCount = totalCount;
			//璁剧疆鎬婚〉鏁?
			this.setTotalPageCountByRs();
		}
	}
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if(pageSize > 0){
			this.pageSize = pageSize;
		}
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}
	
	public void setTotalPageCountByRs(){
		if(this.totalCount % this.pageSize == 0){
			this.totalPageCount = this.totalCount / this.pageSize;
		}else if(this.totalCount % this.pageSize > 0){
			this.totalPageCount = this.totalCount / this.pageSize + 1;
		}else{
			this.totalPageCount = 0;
		}
	}
	
}

com.sun.userdao.I类代码
IDemo接口类:

package com.sun.userdao.I;





import java.util.List;

import org.apache.ibatis.annotations.Param;



import com.sun.pojo.Demo;

public interface IDemo {
	
	 
    public List<Demo> show(@Param("name")String name)throws Exception;
    
	public Demo show1(@Param("id")String id);
	

	
	public void update(@Param("id")String id,@Param("gai")String gai);
}

DemoDao.xml,xml文件:

<!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sun.userdao.I.IDemo">	
    
	 
	 <select id="show" resultType="Demo" >
	 select * from Demo 
	    <if test=" name !=null and name !='' ">
	       where good_name like  '%'||upper(#{name,jdbcType=VARCHAR})||'%' 
	   	</if>	   	
	 </select>	
	 
	 <select id="show1" resultType="Demo" >
	   	select * from Demo  where good_Id=#{id}
	 </select>	
	 
	<update id="update" parameterType="String">
	  update Demo set good_Price=#{gai} where good_Id=#{id}
	</update>
</mapper> 

com.sun.UserServcies.I包代码:
DemoServiceI.java接口类:

package com.sun.UserServcies.I;

import java.util.List;

import com.sun.pojo.Demo;


public interface DemoServciesI {
	
	
	public List<Demo> show(String name);
	
	public Demo show1(String id);
	
	public void update(String id,String gai);
		
	
}

DemoServciesM.java类代码:

package com.sun.UserServcies.I;

import java.util.List;

import com.sun.pojo.Demo;
import com.sun.userdao.I.IDemo;




public class DemoServciesM implements DemoServciesI{
     private IDemo dao;
     

   

	public IDemo getDao() {
		return dao;
	}


	public void setDao(IDemo dao) {
		this.dao = dao;
	}


	//--------------------------------------锟斤拷锟斤拷锟侥分革拷锟斤拷----------------------------------------------------------
	

	public List<Demo> show(String name) {
		// TODO Auto-generated method stub
		System.out.println(name);
		
		List<Demo> u=null;
		try {
			 u=dao.show(name);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return u;
	}


	public Demo show1(String id) {
		Demo u=null;
		try {
			 u=dao.show1(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return u;
	}


	public void update(String id, String gai) {
		dao.update(id,gai);
	}


	


}

applicationContext.xml,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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	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/context
	 http://www.springframework.org/schema/context/spring-context-3.2.xsd	
	 http://www.springframework.org/schema/mvc
	 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
	 http://www.springframework.org/schema/tx
	 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
	
	 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	        <property name="location" value="classpath:database.properties"></property>
	   </bean>
	  
	   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
	     <property name="driverClassName" value="${jdbc.driverClassName}"></property>
	     <property name="url" value="${jdbc.url}"/>
		 <property name="username" value="${jdbc.username}"></property>
		 <property name="password" value="${jdbc.password}"></property>
	   </bean>
	   
	    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
	      <property name="dataSource" ref="dataSource"></property>
	       <property name="configLocation" value="classpath:myBatis-config.xml"></property>
	   </bean>
	   
	   
           <bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
     	         <property name="basePackage" value="com.sun.*.I"/>
            </bean>
            
            <bean id="demoServciesM" class="com.sun.UserServcies.I.DemoServciesM">
		            <property name="dao" ref="IDemo"/>
	        </bean> 
	          
       <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
	<property name = "messageConverters">
		<list>
			<bean class = "org.springframework.http.converter.StringHttpMessageConverter">
				<property name = "supportedMediaTypes">
					<list>
						<value>text/plain;charset=UTF-8</value>
					</list>
				</property>
			</bean>
		</list>
	</property>
	</bean>
	 <context:component-scan base-package="com.sun.action"></context:component-scan>
    
	
    
     <mvc:default-servlet-handler/>
 
  		
     
    <mvc:annotation-driven>   
         <mvc:message-converters>   
                  <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                                  <property name="objectMapper">   
                                 <bean class="com.fasterxml.jackson.databind.ObjectMapper"> 
                   <property name="dateFormat">      
                         <bean class="java.text.SimpleDateFormat"> 
                             <constructor-arg type="java.lang.String" value="yyyy-MM-dd" /> 
                               </bean>
                        </property>       
                     </bean>        
                   </property>     
                 </bean>    
                      </mvc:message-converters> 
                          </mvc:annotation-driven>


	 </beans>

database.properties,jdbc数据源配置文件:

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc\:oracle\:thin\:@localhost\:1521\:orcll
jdbc.username=ticketmo
jdbc.password=123

myBatis-config.xml配置:

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<typeAliases>
             <package name="com.sun.pojo"/>
</typeAliases>
             <mappers>
                 <mapper resource="com/sun/userdao/I/DemoDao.xml"/>                
             </mappers>
</configuration>

导入包教程:
第一步点击项目右键:
在这里插入图片描述
选择Build Path》AddLibraries》MyEclipse Libraries
在这里插入图片描述
选中:
在这里插入图片描述
这几个包哈哈最后WebRoot
在这里插入图片描述
jquery我用的是1.8.3其他也行

lib包展示:

在这里插入图片描述
在这里插入图片描述
jar包王盘链接:链接: link.请点击link
提取码:1xpx

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">
  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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:applicationContext.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>
  
  <filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
  
</web-app>

index.jsp配置代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	
   <script type="text/javascript" src="<%=basePath%>/js/jquery-1.8.3.min.js"></script>




	<script type="text/javascript">
     /*选项查询部分**/
     myfunction(); 
    
     function myfunction(){
      var a="";
      var na="";
       na=document.getElementById("nacc"); //获得文本框的值            
       if(na!="" && na!=null){
         alert(na);
         a=na.value;
       } 
      /*ajax查询部分**/ 
      $.ajax({
		type:"POST",
		url:"show",
		data:"name="+a,
		dataType:"json",
		success:function(date){ 
	
		    $("#bordershrees").find("tr:not(:first)").remove();                       
                       for(var i=0;i<date.length;i++){
                           
                                 $("#bordershrees").append("<tr>"+
                                                     "<td align='center' height='70px' width='570px'>"+date[i].good_Id+"</td>"+
                                                     "<td align='center' height='70px'width='370px'>"+date[i].good_name+"</td>"+
	                                                 "<td align='center' height='70px'width='350px'>"+date[i].good_Product_Date+"</td>"+
	                                                 "<td align='center' height='70px'width='350px'>"+date[i].good_Price+"</td>"+	                                                
	                                                 "<td align='center' height='70px' width='350px'><a href='updatepao?id="+date[i].good_Id+"'>调整价格</a></td>"+
	                                                 "</tr>");	                                               
                         } 
                    }                 
            
                });
        }  
             function cvb(){
                       myfunction(); 
                   }
    
    </script>
	
  </head>
  
  <body>
        <form action="">
        <table style="margin:auto; margin-top:30px;  " cellpadding="0" cellspacing="0">
        <tr>
        <td> 关键字(商品名称):<input id="nacc" name="name"  type="text" /></td>
        <td>  <input onclick="cvb()" type="button" value="查询"/></td>       
        </tr>
        </table>
     </form>
  
  
 
   
     <table   border="1" style="margin:auto; margin-top:30px;  " cellpadding="0" cellspacing="0" >
           <tr id="shreesbox">
	                <td align="center" height="80px" width="570px">商品条码</td>
	                <td align="center" height="80px" width="370px">商品名称</td>
	                <td align="center" height="80px" width="350px">生产日期</td>
	                <td align="center" height="80px" width="350px">价格</td>	               
	                <td align="center" height="80px" width="350px">操作</td>
	             </tr>
	             </table>
     <div style="height: 400px; overflow-y:scroll">
            <div style="border: 1px  #000000; width: 100%; margin: 0 auto;">
            <table id="bordershrees"   style="margin:auto; margin-top:30px; border:1px solid #FFF;" border="1" cellpadding="0" cellspacing="0" >
                  
	            <tr>
	              
	           
	             </tr>
	           </table>
	             
	                
                        </div>
                       </div> 
  </body>
</html>

update.jsp配置代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'update.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <form action="update" method="post">
  <input name="id"  type="hidden" value="${Demo.good_Id }"/>
   商品编号<span>${Demo.good_Id }</span><br/>
   商品名称<span>${Demo.good_name }</span><br/>
   商品原价<span>${Demo.good_Price }</span><br/>
   商品现价<span><input name="gai" type="text" value=""/></span><br/>
   <input type="submit" value="保存"/>
   </form>
  </body>
</html>

运行展示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值