ssm整合 桃扇骨 2021-10-24 02:56 477阅读 0赞 ## ssm整合 ## ### 项目目录 ### ![1560559-20190805161522126-1893405258.png][] ### jar ### ![1560559-20190805161539170-1804104233.png][] ### 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:mybatis-spring="http://mybatis.org/schema/mybatis-spring" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <context:component-scan base-package="com.yjf.service"></context:component-scan> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:db.properties" /> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="root" /> <property name="password" value="root" /> <property name="maxPoolSize" value="3"/> </bean> <!-- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.cj.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssm?autoReconnect=true&failOverReadOnly=false&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true" /> <property name="user" value="root" /> <property name="password" value="root" /> </bean> --> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:com/yjf/mapping/*.xml"></property> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.yjf.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> </beans> ### SpringMvc-config.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <context:component-scan base-package="com.yjf.controller"></context:component-scan> <mvc:annotation-driven></mvc:annotation-driven> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/views/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans> ### db.properties ### jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/ssm?autoReconnect=true&failOverReadOnly=false&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true jdbc.username=root jdbc.password=root ### log4j.properties ### log4j.rootLogger = debug,stdout log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %5p [%t] - %m%n ### StudentController.java ### package com.yjf.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.yjf.entity.Student; import com.yjf.service.StudentService; @Controller @RequestMapping("/student") public class StudentController { @Autowired private StudentService studentservice; @RequestMapping("/all") public ModelAndView index() { List<Student> res = studentservice.queryAll(); ModelAndView mv = new ModelAndView("index"); mv.addObject("res",res); return mv; } } ### StudentMapper.java ### package com.yjf.dao; import java.util.List; import org.springframework.stereotype.Repository; import com.yjf.entity.Student; @Repository public interface StudentMapper { List<Student> queryAll(); } ### Student.java ### package com.yjf.entity; public class Student { private int id; private String name; private int age; private String nickname; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } ### StudentMapper.xml ### <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yjf.dao.StudentMapper"> <select id="queryAll" resultType="com.yjf.entity.Student" > select * from student </select> </mapper> ### index.jsp ### <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <table border="1"> <c:forEach items="${requestScope.res }" var="stu"> <tr> <td>${stu.id }</td> <td>${stu.name }</td> <td>${stu.age }</td> <td>${stu.nickname }</td> <td>${stu.password }</td> </tr> </c:forEach> </table> </body> </html> ### web.xml ### <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>SSMTest</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:SpringMvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <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> </web-app> ### mysql数据库 ### ![1560559-20190805161608589-1352940121.png][] 转载于:https://www.cnblogs.com/sm1128/p/11303687.html [1560559-20190805161522126-1893405258.png]: /images/20211023/d81ab243263744b9a66f8e473e043266.png [1560559-20190805161539170-1804104233.png]: /images/20211023/237cdf613ecf47d695862bc2effca8a6.png [1560559-20190805161608589-1352940121.png]: /images/20211023/aa03f46f4e9a4ad0b6fb29581690a81a.png
相关 整合 SSM 1.1 相关依赖 <dependency> <groupId>org.springframework</groupId> <art 不念不忘少年蓝@/ 2022年12月05日 05:21/ 0 赞/ 8 阅读
相关 ssm整合 整合:spring4.2.5+mybatis3.2.8+springMVC+maven 环境:Myeclipse2014+mysql5.5.20+tomcat8+jdk1. 柔光的暖阳◎/ 2022年07月13日 11:19/ 0 赞/ 134 阅读
相关 ssm整合 手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis -------------------- > 我们看招聘信息的时候,经常 古城微笑少年丶/ 2022年07月12日 06:27/ 0 赞/ 16 阅读
相关 ssm整合 手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis -------------------- > 我们看招聘信息的时候,经常 墨蓝/ 2022年07月12日 06:27/ 0 赞/ 38 阅读
相关 ssm整合 在mybatis和spring整合后 , 在把springmvc整合进来 在maven里创建web工程 然后进行mybatis和spring的整合步骤(写在其他博客里) 超、凢脫俗/ 2022年02月12日 10:10/ 0 赞/ 425 阅读
相关 ssm整合 一、注入依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mav 快来打我*/ 2022年01月23日 12:57/ 0 赞/ 431 阅读
相关 SSM--SSM整合 一、项目层级结构以及所需JAR包: ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9 傷城~/ 2022年01月21日 23:37/ 0 赞/ 463 阅读
相关 ssm整合 ssm整合 项目目录 ![1560559-20190805161522126-1893405258.png][] jar ![1560559-2019080 桃扇骨/ 2021年10月24日 02:56/ 0 赞/ 478 阅读
相关 SSM整合 前提:jdk,maven,tomcat,STS都已经安装配置好了 spring-4.3.7 + mybatis-3.3.0 + maven3.5+jdk8(这个组合会减少很多 悠悠/ 2021年09月28日 07:58/ 0 赞/ 444 阅读
相关 SSM整合 SSM:Spring+SpringMVC+MyBatis 1、导包 1)、Spring 【aop核心】 com.springsource.net.sf. 男娘i/ 2021年09月23日 16:18/ 0 赞/ 496 阅读
还没有评论,来说两句吧...