下载地址:https://git.oschina.net/zhuhongliang/Spring_MyBatis_J2EE_Study
我的环境windows7,tomcat8,jre7
先看下            文档目录           和             数据库:


我就吧配置文件贴这,其他文件直接下载,都有
SpringController.java:

package com.zhl.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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 com.zhl.model.Favorite;
import com.zhl.service.FavoriteService;

@Controller
public class SpringController {
	
	@Autowired
	FavoriteService favorite;
	
	@RequestMapping("/")
	public String hitu(Model model) 	{

	    List a= favorite.findAll(); 

	    model.addAttribute("list",a);
	    
	    return "a";
	}
	@RequestMapping("/index")
	public void  index(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException	{
	    response.setHeader("content-type", "text/html;charset=UTF-8");
	    response.setCharacterEncoding("UTF-8");
	
	    response.getWriter().println("<h1>打南边来了个喇嘛,手里提拉着五斤鳎犸。<br>"
	    		+ "打北边来了个哑巴,腰里别着个喇叭。<br>"
	    		+ "南边提拉着鳎犸的喇嘛要拿鳎犸换北边别喇叭哑巴的喇叭。<br>"
	    		+ "哑巴不愿意拿喇叭换喇嘛的鳎犸,喇嘛非要换别喇叭哑巴的喇叭。<br>"
	    		+ "喇嘛抡起鳎犸抽了别喇叭哑巴一鳎犸,哑巴摘下喇叭打了提拉着鳎犸的喇嘛一喇叭。<br>"
	    		+ "也不知是提拉着鳎犸的喇嘛抽了别喇叭哑巴一鳎犸,<br>"
	    		+ "还是别喇叭哑巴打了提拉着鳎犸的喇嘛一喇叭。<br>"
	    		+ "喇嘛炖鳎犸,哑巴嘀嘀哒哒吹喇叭</h1>");
	}	
}

ApplicationContext.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: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-4.0.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
		

	<!-- 配置数据源-->  
    <bean id="jdbcDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
	    <property name="driverClassName">  
	        <value>org.gjt.mm.mysql.Driver</value>  
	    </property>  
	    <property name="url">  
	        <value>jdbc:mysql://localhost:3306/hitu_crm?useUnicode=true&characterEncoding=UTF-8</value>  
	    </property>  
	    <property name="username">  
	        <value>root</value>  
	    </property>  
	    <property name="password">  
	        <value>root</value>  
	    </property>  
	</bean>  
	<bean id="springApplicationContext" class="com.zhl.util.SpringApplicationContext"/>

	<context:component-scan base-package="com.zhl.controller" /> 
	<context:component-scan base-package="com.zhl.service" /> 
	
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.zhl.mapper"></property>
		<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
	</bean>
	
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
	    <property name="dataSource" ref="jdbcDataSource" />  
	    <property name="configLocation" value="classpath:mybatis-config.xml"></property>  
	</bean>  
	


</beans>

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>

    
</configuration>

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_2_5.xsd" id="WebApp_ID" version="2.5">
	<display-name>一个简单的springMVC实例</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:ApplicationContext.xml</param-value>
	</context-param>
	
	<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>
		<load-on-startup>1</load-on-startup>
	</servlet>	
	<servlet-mapping>
		<servlet-name>SpringMVC</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
 
</web-app>

Spring-servlet.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
                         http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd   
                          http://www.springframework.org/schema/mvc
                          http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                         http://www.springframework.org/schema/task 
                        http://www.springframework.org/schema/task/spring-task-4.0.xsd">
    
    
	
	<context:component-scan base-package="com.zhl.controller" />
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	   <property name="prefix" value="/WEB-INF/jsp/" />
	   <property name="suffix" value=".jsp" />
	</bean>


</beans>

我在本地访问:http://localhost:8081/Spring_MyBatis_web_Study/

我在本地访问:http://localhost:8081/Spring_MyBatis_web_Study/index

这个代码有点多:其他文件直接下载了看吧。
 

我的环境windows7,tomcat8,jre7

 

 

下载地址:https://git.oschina.net/zhuhongliang/Spring_MyBatis_J2EE_Study

 

 

发表评论