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

超简洁SSM框架整合

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

超简洁SSM框架整合

Spring Springmvc mybatis整合思路:Springmvc属于Spring体系的不用特意去整合,但是在业务开发的时候通常将Springmvc.XML与Spring.xml配置分开处理,是为了降低业务的耦合度,Springmvc负责请求分发,Spring.xml配置事务,整合其他框架。spring与mybatis整合参考文档

框架整合的配置文件

启动Web项目的时候,Tomcat首先会读取web.xml文件的信息,启动全局Spring父容器与Springmvc子容器



    
    
    
    
        contextConfigLocation
        classpath:spring.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc.xml
        
    
    
        springmvc
        /
    

Spring.xml配置信息,其中配置了数据库连接池,以及整合Mybatis的配置



    
    
    
        
        
        
        
        
        
    



    
    
    
        
         

service层

package com.cqupt.service;

import com.cqupt.entity.User;

import java.util.List;

public interface UserService {
    public List list();
}

package com.cqupt.service.impl;

import com.cqupt.entity.User;
import com.cqupt.repository.UserMapper;
import com.cqupt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List list() {
        return userMapper.list();
    }
}

Dao层

package com.cqupt.Dao;

import com.cqupt.entity.User;

import java.util.List;

public interface UserMapper {
    public List list();
}





    
        select * from user
    


index.jsp页面

<%--
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>


    Title


    

用户信息

${list}

整合效果:

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

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

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