1.新建web工程
2.添加spring支持
勾上spring persistence
3.配置文件新建源文件夹
applicationContext.xml移动到config下
添加依赖的mybaits和oracle数据包
4.新建jdbc.properties
rkdata.driverClassName=oracle.jdbc.driver.OracleDriver
rkdata.url=jdbc\:oracle\:thin\:@192.168.118.52\:1521\:orcl
rkdata.username=yhrkdata
rkdata.password=rkdata2015
rkgis.driverClassName=oracle.jdbc.driver.OracleDriver
rkgis.url=jdbc\:oracle\:thin\:@192.168.118.52\:1521\:orcl
rkgis.username=yhrkgis
rkgis.password=rkgis2015
jdbc.maxActive=255
jdbc.maxIdle=20
jdbc.maxWait=100
5.新建log4j.properties
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %c{1} - %m%n
log4j.logger.org.springframework.security=ERROR
6.新建包结构
7.新建dispatcher-servlet.xml
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd ">
p:prefix="/resources/jsp/" p:suffix=".jsp" />
8.WEB-INF下web.xml添加拦截器配置和字符编码配置
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
classpath:dispatcher-servlet.xml
9.配置applicationContext.xml
xmlns:p="http://www.springframework.org/schema/p"
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">
10.编辑文件内容
Example_Mapper.xml
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
Example.java
package com.founder.example.model;
/**
*
*
* @author steve
*
*/
public class Example {
}
11.IExampleDao.java
package com.founder.example.dao;
import java.util.List;
import java.util.Map;
/**
*
*
* @author steve
*
*/
public interface IExampleDao {
List
ExampleDaoImpl.java
package com.founder.example.dao.impl;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.founder.example.dao.IExampleDao;
import com.founder.example.model.Example;
@Transactional
@Repository
public class ExampleDaoImpl implements IExampleDao {
private SqlSessionTemplate rkdataSession;
private SqlSessionTemplate rkgisSession;
public SqlSessionTemplate getRkdataSession() {
return rkdataSession;
}
@Autowired
public void setRkdataSession(SqlSessionTemplate rkdataSession) {
this.rkdataSession = rkdataSession;
}
public SqlSessionTemplate getRkgisSession() {
return rkgisSession;
}
@Autowired
public void setRkgisSession(SqlSessionTemplate rkgisSession) {
this.rkgisSession = rkgisSession;
}
@Override
public List
List list = rkdataSession.selectList(Example.class.getName()
+ "_Mapper.findDataExample");
return list;
}
@Override
public List
List list = rkgisSession.selectList(Example.class.getName()
+ "_Mapper.findGisExample");
return list;
}
}
12.IExampleService.java
package com.founder.example.service;
import java.util.List;
import java.util.Map;
public interface IExampleService {
List
List
}
ExampleServiceImpl.java
package com.founder.example.service.impl;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.founder.example.dao.IExampleDao;
import com.founder.example.service.IExampleService;
/**
* @author steve
*
*/
@Service
public class ExampleServiceImpl implements IExampleService {
@Resource
private IExampleDao exampleDao;
@Override
public List
return exampleDao.findDataExample();
}
@Override
public List
return exampleDao.findGisExample();
}
}
13.ExampleController.java
package com.founder.example.controller;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.founder.example.service.IExampleService;
@Controller
public class ExampleController {
@Resource
private IExampleService exampleService;
@RequestMapping("/findDataExample")
public ModelAndView findDataExample() {
List
return new ModelAndView("dataExample", "list", list);
}
@RequestMapping("/findGisExample")
public ModelAndView findGisExample() {
List
System.out.println(list.size());
return new ModelAndView("gisExample", "list", list);
}
}
14.新建jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib
prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
15.启动服务
访问http://localhost:8080/frank/findDataExample.action
访问http://localhost:8080/frank/findGisExample.action