1.pom dependency: Spring-boot basic jar----Built-in SPRINGMVC and springthymeleaf jar hot deploy jar---Easy two load ctrl+f9 compile MyBatis jarmysql again 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><!--Hot Deployment--><dependency> <groupId>org.springframework.boot< /groupid> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> < !--this needs to be true hot deployment is effective--></dependency><!--MyBatis--><dependency> <groupId> Org.mybatis.spring.boot</groupid> <ARTIFACTID>MYBATIS-SPRING-BOOT-STARTER≪/artifactid> <version>1.1.1</version></dependency><!--MySQL--><dependency> & Lt;groupid>mysql</groupid> <artifactId>mysql-connector-java</artifactId> <version> 5.1.21</version></dependency>2.application configuration: #thymeleaf configuration spring.thymeleaf.mode= The html5spring.thymeleaf.encoding=utf-8spring.thymeleaf.content-type=text/html# cache is set to false so that the modification takes effect immediately, Facilitates debugging spring.thymeleaf.cache=false# context server.context-path=/thymeleaf# View Layer control #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-8spring.datasource.username= Rootspring.datasource.password=spring.datasource.driver-class-name=com.mysql.jdbc.driver3.mapper Layer And very simple entity layer: @Mapper @repository//plus Repository annotations, you can automatically beanpublic interface Categorymapper {@Select ("select * from CA Tegory_ ") Public list<category> findAll ();} 4. Service Layer---and SERVICEIMPL implementation layer @servicepublic class Categoryserviceimpl implements Categoryservice {@Autowired Categ Orymapper; @Override public list<category> SelectAll () {return categorymapper.findall (); }}5.controller layer: This inside add pagehelper, can ignore @controllerpublic class Categorycontroller {@Autowired categoryservice Categor Yservice; @RequestMapping ("/listcategory") public String Showlist (model model, @RequestParam (value = "s Tart ", 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---Render template: A bit similar to the notation of El expressions <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)}" >[home]</a><a th:href= "@{/listcategory (Start=${page.pagenum-1})}" >[previous Page] </a><a th:href= "@{/listcategory (Start=${page.pagenum+1})}" >[next]</a><a th:href= "@{/ Listcategory (Start=${page.pages})} ">[last]</a>
Springboot---'s SSM framework Integration