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>

  

最新文章

  1. 使用 python 实现 memcached 的启动服务脚本 rc
  2. webstrom live templates
  3. iframe跨域cookie问题
  4. centos7.2 默认启动内核修改
  5. 《C与指针》第二章练习
  6. 【C#】线程之Parallel
  7. eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作。 如下图所示,保存文件也无法保存。 这个怎么办?一年好几天,什么都干不了!!!!!
  8. 3.7 嵌入式SQL
  9. [转]关于position 的 static、relative、absolute、fixed、inherit
  10. 校省选赛第一场A题Cinema题解
  11. Android AlarmManager实现不间断轮询服务
  12. (译文)React----React应用程序流式服务端渲染
  13. JPA 连表查询
  14. 使用css设置三角形
  15. 百度统计微信网站绑定(vue项目)
  16. Python爬虫——用BeautifulSoup、python-docx爬取廖雪峰大大的教程为word文档
  17. 禁用 Gnome Shell 默认的 Ubuntu Dock 和 Ubuntu AppIndicators 扩展
  18. python测试开发django-35.xadmin注册表信息
  19. linux查看某个目录下有哪些文件的命令
  20. fiddler 修改request请求

热门文章

  1. java小项目——抽奖系统
  2. Beta冲刺总结随笔
  3. 动力节点 mysql 郭鑫 34道经典的面试题二
  4. 四层发现-TCP发现
  5. jfinal运行时报错分析java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
  6. el-table表头与内容右边框错位问题
  7. 学习Java的Day02
  8. MyEclipse中项目利用不同版本JDK编译注意点
  9. 吐血推荐,想进BAT必看
  10. 《UNIX环境高级编程》(APUE) 笔记第一章 - UNIX基础知识