标签:host basic aaa get 前端控制器 哪些 xmlns sele doctype
ssm框架各个技术的职责
SqlSession session = SqlSessionFactoryUtil.getSession();
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>aaa</groupId> <artifactId>test_maven_qy97_03</artifactId> <version>1.0-SNAPSHOT</version>
<properties> <spring.version>4.3.18.RELEASE</spring.version> </properties> <dependencies> <!--spring的核心的jar包--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!--spring mvc的jar包--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!--spring jdbc的jar包--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!--mybatis的jar包--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <!--spring 和mybatis整合的中间件jar包--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.2</version> </dependency> <!--orace的驱动包--> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>6</version> </dependency> <!--spring 实现文件上传的jar包--> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency> <!--解析json数据的jar包--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.8</version> </dependency> <!--数据库连接池的jar包--> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <!--jstl的jar包--> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> </dependencies> <build> <resources> <!--指定src main java下所有的目录下的xml文件都编译--> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build> </project>
<!-- 配置spring的核心监听器--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置spring 的主配置文件的位置和名称--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param> <!-- 配置spring mvc的前端控制器--> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置spring mvc的主配置文件的位置和名称--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
/** * 部门管理实体类 */ public class Dept { private Long deptno; private String dname; private String loc; public Long getDeptno() { return deptno; } public void setDeptno(Long deptno) { this.deptno = deptno; } public String getDname() { return dname; } public void setDname(String dname) { this.dname = dname; } public String getLoc() { return loc; } public void setLoc(String loc) { this.loc = loc; } }
/** * 部门管理dao接口 */ public interface DeptDao { /** * 查询所有的部门信息 * @return */ public List<Dept> listAll(); }
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.aaa.ssm.dao.DeptDao"> <select id="listAll" resultType="com.aaa.ssm.entity.Dept"> select * from dept </select> </mapper>
/** * 部门管理service接口 */ public interface DeptService { /** * 查询所有的部门信息 * @return */ public List<Dept> listAll(); }
/** * 部门管理service接口实现 */ @Service @Transactional public class DeptServiceImpl implements DeptService { @Autowired private DeptDao deptDao; public List<Dept> listAll() { return deptDao.listAll(); } }
/** * 部门管理控制器实现 */ @Controller @RequestMapping("/dept") public class DeptController { @Autowired private DeptService deptService; /** * 跳转到部门管理界面 * @return */ @RequestMapping("/list") public String list(Model model){ List<Dept> depts = deptService.listAll(); model.addAttribute("list",depts); return "list"; } }
driver=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:orcl user=scott password=tiger
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="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/springcontext.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/springtx.xsd"> <!--第一步,扫描service --> <context:component-scan base-package="com.aaa.ssm.service.impl"></context:component-scan> <!--第二步,加载jdbc.properties--> <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder> <!--第三步,创建dbcp数据源连接池--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${driver}"></property> <property name="url" value="${url}"></property> <property name="username" value="${user}"></property> <property name="password" value="${password}"></property> </bean> <!--第四步,创建mybatis的工厂类对象--> <bean class="org.mybatis.spring.SqlSessionFactoryBean"> <!--指定数据源--> <property name="dataSource" ref="dataSource"></property> <!--加载mybatis的映射文件 在value中可以使用*号通配符--> <property name="mapperLocations" value="classpath:com/aaa/ssm/dao/*.xml"></property> </bean> <!--第五步,在spring 的工厂中生成dao接口的实现类对象 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--指定要扫描哪个包下面所有的dao接口--> <property name="basePackage" value="com.aaa.ssm.dao"></property> </bean> <!--第六步,创建spring的事物管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--第七步,声明以注解的方式配置声明式事物--> <tx:annotation-driven transaction-manager="transactionManager" ></tx:annotation-driven> </beans>
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="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/springcontext.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/springmvc.xsd"> <!--第一步,扫描控制器包--> <context:component-scan base-package="com.aaa.ssm.controller"></context:component-scan> <!--第二步,声明以注解的方式使用spring mvc--> <mvc:annotation-driven></mvc:annotation-driven> <!--第三步,配置spring mvc 内置的视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2019/6/3 Time: 10:59 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>部门管理</title> </head> <body> <table> <tr> <th>部门编号</th> <th>部门名称</th> <th>部门位置</th> </tr> <c:forEach items="${list}" var="item"> <tr> <td> ${item.deptno} </td> <td> ${item.dname} </td> <td> ${item.loc} </td> </tr> </c:forEach> </table> </body> </html>
ssm(spring,spring mvc,mybatis)框架
标签:host basic aaa get 前端控制器 哪些 xmlns sele doctype
原文地址:https://www.cnblogs.com/duguangming/p/10969961.html