springboot --- 之SSM架構整合

來源:互聯網
上載者:User

標籤:rac   jar   boot   上下   user   thymeleaf   生效   jdb   templates   

1.pom依賴:即:spring-boot的基本jar ---- 內建springmvc和springThymeleaf jar熱部署 jar ---方便二次載入 ctrl+f9再次編譯Mybatis jarMysql 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=HTML5spring.thymeleaf.encoding=UTF-8spring.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-8spring.datasource.username=rootspring.datasource.password=spring.datasource.driver-class-name=com.mysql.jdbc.Driver3.mapper層 以及非常簡單的entity層:@Mapper@Repository// 加上Repository註解,即可自動beanpublic interface CategoryMapper {    @Select("select * from category_ ")    public List<Category> findAll();}4.service層 --- 以及serviceImpl實現層@Servicepublic class CategoryServiceImpl implements CategoryService {    @Autowired    CategoryMapper;    @Override    public List<Category> selectAll() {        return categoryMapper.findAll();    }}5.controller層:這個裡面加了pagehelper,可以忽略@Controllerpublic 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架構整合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.