本文章提供了详细的搭建过程,供大家参考学习。
案例Demo已托管至Github,详情查看SSM Demo
名称 | 描述 | 版本号 | 网址 |
---|---|---|---|
Spring MVC | MVC框架 | 4.3.10.RELEASE | https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc |
Spring Framework | 容器 | 4.3.10.RELEASE | http://projects.spring.io/spring-framework/ |
MyBatis | ORM/持久层框架 | 3.4.5 | http://www.mybatis.org/mybatis-3/zh/index.html |
AspectJ | 面向切面的框架 | 1.8.10 | http://www.eclipse.org/aspectj/ |
Druid | 数据库连接池 | 1.1.3 | https://github.com/alibaba/druid |
Jackson | json解析器 | 2.9.1 | https://github.com/FasterXML/jackson |
Logback | 日志组件 | 1.2.3 | https://logback.qos.ch |
Maven | 项目构建管理 | 3.3.9 | http://maven.apache.org/ |
1.png
2.png
3.png
4.png
5.png
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">
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
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/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
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/spring-context-4.3.xsd">
package com.frame.service;
public interface DemoService {
void test();
}
package com.frame.service.impl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.frame.service.DemoService;
@Service("demoService")
public class DemoServiceImpl implements DemoService {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
// mybatis sql模板的命名空间
private static final String NAMESPACE = "com.frame.mapper.DemoMapper";
@Override
public void test() {
System.out.println("返回查询结果集 -> " + sqlSessionTemplate.selectList(NAMESPACE + ".getTest")); // 查询结果集
}
}
package com.frame.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.frame.service.DemoService;
@Controller
public class DemoController {
@Autowired
private DemoService demoService;
@RequestMapping("/hello")
public String hello() {
System.out.println("执行hello控制器方法");
// 调用业务层执行查询操作
demoService.test();
return "hello";
}
}
<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
This is index page.
<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Hello World!
6.png
执行hello控制器方法
返回查询结果集 -> [{ID=1ba6d11d2639401ebf63c00c5ae7c2a0, NAME=SSM, TYPE=FRAME}]
到此整个框架就搭建完成了,接下来即可进入开发阶段,如果感觉不错请分享出去。