springboot --- 之SSM框架整合
1.pom依赖:
即:spring-boot的基本jar ---- 内置springmvc和spring
Thymeleaf jar
热部署 jar ---方便二次加载 ctrl+f9再次编译
Mybatis jar
Mysql jar <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency> <!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency> 2.application的配置:
#thymeleaf 配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#缓存设置为false, 这样修改之后马上生效,便于调试
spring.thymeleaf.cache=false
#上下文
server.context-path=/thymeleaf
#视图层控制
#spring.mvc.view.prefix=classpath:/templates/
#spring.mvc.view.suffix=.html
#spring.mvc.static-path-pattern=/static/**
#数据库
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/how2java?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3.mapper层 以及非常简单的entity层:
@Mapper
@Repository
// 加上Repository注解,即可自动bean
public interface CategoryMapper { @Select("select * from category_ ")
public List<Category> findAll(); } 4.service层 --- 以及serviceImpl实现层
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
CategoryMapper; @Override
public List<Category> selectAll() {
return categoryMapper.findAll();
}
}
5.controller层:
这个里面加了pagehelper,可以忽略
@Controller
public class CategoryController {
@Autowired
CategoryService categoryService; @RequestMapping("/listCategory")
public String showList(Model model,
@RequestParam(value = "start", defaultValue = "0") int start,
@RequestParam(value = "size", defaultValue = "5") int size)
throws Exception{
PageHelper.startPage(start,size);
List<Category> list = categoryService.selectAll();
PageInfo<Category> page = new PageInfo<>(list);
model.addAttribute("page",page);
return "listCategory";
}
} 6.Thymeleaf --- 渲染模板: 有点类似于EL表达式的写法
<table border="1px">
<tr>
<th>id</th>
<th>name</th>
</tr>
<tr th:each="l:${page.list}">
<td th:text="${l.id}"></td>
<td th:text="${l.name}"></td>
</tr>
</table>
<a th:href="@{/listCategory(start=0)}">[首 页]</a>
<a th:href="@{/listCategory(start=${page.pageNum-1})}">[上一页]</a>
<a th:href="@{/listCategory(start=${page.pageNum+1})}">[下一页]</a>
<a th:href="@{/listCategory(start=${page.pages})}">[末 页]</a>
springboot --- 之SSM框架整合的更多相关文章
- SpringMVC详解及SSM框架整合项目
SpringMVC ssm : mybatis + Spring + SpringMVC MVC三层架构 JavaSE:认真学习,老师带,入门快 JavaWeb:认真学习,老师带,入门快 SSM框架: ...
- SSM框架整合项目 :租房管理系统
使用ssm框架整合,oracle数据库 框架: Spring SpringMVC MyBatis 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastj ...
- 基于maven的ssm框架整合
基于maven的ssm框架整合 第一步:通过maven建立一个web项目. 第二步:pom文件导入jar包 (1 ...
- JavaWeb之ssm框架整合,用户角色权限管理
SSM框架整合 Spring SpringMVC MyBatis 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastjson 5, aspectwea ...
- SSM框架整合环境构建——基于Spring4和Mybatis3
目录 环境 配置说明 所需jar包 配置db.properties 配置log4j.properties 配置spring.xml 配置mybatis-spring.xml 配置springmvc.x ...
- Springboot,SSM框架比较,区别
百度搜 Springboot,SSM框架区别,大多说的都是 1.springboot一个应用是一个可执行jar 2.将原有的xml配置,简化为java配置 他们说的确实没错,可是根本没有说到本质,百度 ...
- 基于springboot的SSM框架实现返回easyui-tree所需要数据
1.easyui-tree easui-tree目所需要的数据结构类型如下: [ { "children": [ { "children": [], " ...
- springmvc(二) ssm框架整合的各种配置
ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...
- SSM框架整合的其它方式
---------------------siwuxie095 SSM 框架整合的其它方式 1.主要是整合 Spring ...
随机推荐
- ZWave对COMAND CLASS的处理流程
文章主题 在开发一个 ZWave Device 的过程中,对 COMAND CLASS(单词太长了,后面就简写为 CC 啦) 的处理是最基本.最重要的工作.这篇文章以最最简单的 CC:COMMNAD ...
- VUE+ELEMENT-UI的后台项目封装组件--查询form的封装
最近项目打算重构,项目的模块几乎都是以后台查询展示的传统的增删改差模式,所以卑微的我想要自己封装一下查询form,先上效果图 子组件页面: <template> <div class ...
- python-判断、循环、列表、字典
一.如何将两个列表合并成一个字典 运用dict(zip()) 例如: usernames = ['xiaohei', 'xiaobai', 'xiaoming'] passwords = ['1234 ...
- django OperationalError: unable to open database file 创建数据库
- Perl入门(四)Perl的正则表达式
正则表达式是Perl语言的特色,基本的语法不是很难,但是编写一个符合需求.高效的正则表达式,还是有一些挑战的. Perl的三种匹配模式 1.查找 语法:m/正则表达式内容/; 作用:查找匹配内容中是否 ...
- JavaWeb网上图书商城完整项目--26.注册页面之验证码换一张实现
我们现在要实现点击换一张的时候实现验证码的修改 我们首先在html添加函数点击事件: <%@ page language="java" contentType="t ...
- java web20套项目
http://shenghuo.lshou.com/c4154/t5bdbcc98b9a9.html
- 【Spring注解驱动开发】关于BeanPostProcessor后置处理器,你了解多少?
写在前面 有些小伙伴问我,学习Spring是不是不用学习到这么细节的程度啊?感觉这些细节的部分在实际工作中使用不到啊,我到底需不需要学习到这么细节的程度呢?我的答案是:有必要学习到这么细节的程度,而且 ...
- java命令行输入参数
Java命令行输入参数 代码用例:命令行输入参数,并进行加法运算. public class Demo01 { public static void main(String[] args) { for ...
- Ubuntu16.04CPU下安装caffe的艰苦历程
我选用的是anaconda安装,符上我参照的三个有用的教程. 1 http://www.linuxdiyf.com/linux/22442.html 主要讲anaconda的安装和python路径配置 ...