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 Listlist(); } 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 Listlist() { return userMapper.list(); } } Dao层
package com.cqupt.Dao; import com.cqupt.entity.User; import java.util.List; public interface UserMapper { public Listlist(); } 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}整合效果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)