栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SSM整合(以sqlserver 为例)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SSM整合(以sqlserver 为例)

1、applicationContext.xml配置文件


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-4.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd" >
    
    

    
       
       
       
       
   

    
   
        
        
            
    

    
    
        
        
    

    
    
    
   
   
   
       
       
       
       
   

   
   
    
        
    

    
    

    
    
   

 或数据库采用外部文件,配置文件中配置数据源改为下面内容:

    
   
    
    
       
       
       
       
   

2、jdbc.properties文件

jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://127.0.0.1:1433;databaseName=数据库名
jdbc.username=sa
jdbc.password=密码

3、controller文件内容

@Controller
public class HelloController {
	
	@Autowired
	private HelloService piaoService;
	
	@RequestMapping("/findAll")
	public String findAll(Model model) {
		List lists = piaoService.selectAll();
		model.addAttribute("Piaos", lists);
		
		return "success";
		
	}

4、server代码内容

@Service
@Transactional
public class HelloService {
	
	@Autowired
	private PiaoDao piaoDao;

	public List selectAll(){
		
		return piaoDao.findAll();
	}

5、MyAnnotation文件内容

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
	
}

6、dao层代码内容

import java.util.List;

import com.cc.annotation.MyAnnotation;
import com.cc.entity.Piao;

@MyAnnotation
public interface PiaoDao {

	List findAll();
}

7、mapper映射文件

  
 
	
	
	

8、jsp文件内容

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>




Insert title here



	
${piao.name } ${piao.leibie }

最后web.xml配置内容为



  ssm_01
 

        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:applicationContext.xml
        

        
        1
    

    
        dispatcherServlet
        /
    

    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
        
            encoding
            UTF-8
        

    

    
        encodingFilter
        /*
    

lib的包

 最后,以上ssm的整合只是自己写的一个记录,如有bug请多多包涵!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1007557.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号