Springboot---'s SSM framework Integration

Source: Internet
Author: User

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> &LT;ARTIFACTID&GT;MYBATIS-SPRING-BOOT-STARTER&Lt;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.