MyBatis-SSM整合内附完整Lib资源

  1. 导包
    MyBatis-SSM整合内附完整Lib资源_第1张图片
  • e.资源链接

链接:https://pan.baidu.com/s/1jHXZephrvQ-1WCdOwQY-mQ
提取码:zdqe

  • 配置web.xml配置:


  7.SSM_Integeration
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  
  
	 	
	 	
	 		characterEncodingFilter
	 		org.springframework.web.filter.CharacterEncodingFilter
	 		
	 			encoding
	 			utf-8 
	 		
	 		
	 			forceEncoding
	 			true
	 		
	 	
	 	
	 		characterEncodingFilter
	 		/*
	 	
	 	
	 	
	 	
	 		hiddenHttpMethodFilter
	 		org.springframework.web.filter.HiddenHttpMethodFilter
	 	
	 	
	 	
	 		hiddenHttpMethodFilter
	 		/*
	 	
	 	
	 	
	 
	
		contextConfigLocation
		
		classpath:spring/applicationContext.xml
	
	
	
	
		org.springframework.web.context.ContextLoaderListener
	
	 	
	 	
	 	
	
		springDispatcherServlet
		
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			
			classpath:spring/applicationContext-mvc.xml
		
		1
	
	 	
	 	
	
		springDispatcherServlet
		/
	
  	

SpringMVC的配置applicaitonContext-mvc.xml:

  • 用模板创建:

MyBatis-SSM整合内附完整Lib资源_第2张图片

  • 具体配置:


	
	
	
		
		
	
	
	
	
		
		
		
		
	
	
	
	
	
		
		
	
	
	
	
	
	
	
	
	
	
	


  1. Spring的配置applicaitonContext.xml:


	
	
		
	
	
	
	
	
	
	
		
		
		
		
		
		
	
	
	
	
	
	
	
	
	
		
		
		
		
		
	
	
	
	
		
		
	
	
	
	
		
	
	
	
	
		
		
		
		
	
	
	
	
		
		
			
			
			
			
		
	
	


4.Bean:

package com.EzerbelCN.bean;

import java.sql.Date;

public class Teacher {
	private Integer id;
	private String name;
	private String course;
	private Date brith;
	
	public Teacher() {
		super();
	}
	
	
	public Teacher(Integer id, String name, String course, Date brith) {
		super();
		this.id = id;
		this.name = name;
		this.course = course;
		this.brith = brith;
	}


	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCourse() {
		return course;
	}
	public void setCourse(String course) {
		this.course = course;
	}
	
	public Date getBrith() {
		return brith;
	}

	public void setBrith(Date brith) {
		this.brith = brith;
	}

	@Override
	public String toString() {
		return "Teacher [id=" + id + ", name=" + name + ", course=" + course + ", brith=" + brith + "]";
	}
}

5.Dao

package com.EzerbelCN.dao;

import com.EzerbelCN.bean.Teacher;

public interface TeacherDao {
	public Teacher getTeacherById(Integer id);
}

6.Controller

package com.EzerbelCN.controller;

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.RequestParam;

import com.EzerbelCN.bean.Teacher;
import com.EzerbelCN.service.TeacherService;

@Controller
public class TeacherController{
	
	@Autowired
	TeacherService teacherService;
	
	@RequestMapping("/getTeacherById")
	public String getTeacherHandler(@RequestParam(value ="id",defaultValue="1") Integer id,Model model) {
		Teacher teacher = teacherService.getTeacherById(1);
		model.addAttribute("teacher", teacher);
		return "Success";
	}
}

7.Services

package com.EzerbelCN.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.EzerbelCN.bean.Teacher;
import com.EzerbelCN.dao.TeacherDao;

@Service
public class TeacherService {
	
	@Autowired
	private TeacherDao teacherDao;
	
	public Teacher getTeacherById(Integer id) {
		return (Teacher) teacherDao.getTeacherById(id);
	}
}

8.ehcache.xml



 
 
 
 
   
 

 

9.log4j.xml



 

 
 
   
   
    
   
 
 
   
 
 
   
 
 
   
   
 

10.index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


	查询teacher员工在success界面显示


11.Success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


	

Sucess

${teacher}

12.目录结构:

MyBatis-SSM整合内附完整Lib资源_第3张图片
13.测试

MyBatis-SSM整合内附完整Lib资源_第4张图片

MyBatis-SSM整合内附完整Lib资源_第5张图片

你可能感兴趣的:(MyBatis,SpringMVC)