zoukankan      html  css  js  c++  java
  • SpringBoot与thymeleaf

    SpringBoot是微服务框架,可以快速的开发一个web项目,编译工具使用idea,可以很好的将maven与SpringBoot整合,页面交互使用thymeleaf,Spring官方推荐使用

      在使用idea创建项目时发生问题,maven总是报错,换了一个maven本地仓库就可以了,原来是原来maven仓库中有包有问题,

      项目中使用SpringBoot,连接数据库使用mybatis

    项目目录:其中Demo1Application是SpringBoot的入口文件,其中内置了tomcat(其实应该说maven中依赖了tomcat)

    Spring CLOUD 支持高并发,分布式,Spring boot是基础
    优点:集成所有Spring特性并且不用写配置文件
    @RequestBody,返回的不是一个路径,而是一个真正的字符串或者json,SpringMVC会将返回的数据自动封装成json

    使用thymeleaf模板
    需要引入<html xmlns:th="http://www.thymeleaf.org">这个th标签
    利用th标签,输出th:text,遍历th:each="prod:${prodList}"与el表达式类似


    spring理念默认大于配置(很蛋疼)
    spring-boot很多配置都有默认配置,比如默认页面映射路径为
    classpath:/templates/*.html,也就是说return的html会默认去templates中去找

    css或者js文件默认位置在static中,直接引用

    SpringBoot配置文件application.yml

    在pom中导入相应的包

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>cn.tedu</groupId>
      <artifactId>demo4</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>demo4 Maven Webapp</name>
      <url>http://maven.apache.org</url>
    
      <!--包含了Springboot的全部的依赖-->
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
      </parent>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
      </properties>
    
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-thymeleaf</artifactId>
          </dependency>
    
        <!--web应用所依赖的jar包-->
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
        </dependency>
    
        <!--SpringAOP的配置-->
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
    
          <!--整合mybatis-->
    
          <dependency>
              <groupId>org.mybatis.spring.boot</groupId>
              <artifactId>mybatis-spring-boot-starter</artifactId>
              <version>1.2.0</version>
          </dependency>
    
    
        <!--添加mysql的组件-->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
        </dependency>
    
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <!--内部自己集成了tomcat-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </project>

    这样项目就可以正常启动进行开发了

  • 相关阅读:
    对我比较有用的网站
    ubuntu各种安装
    arabaraba
    镜像源相关
    硬盘相关
    python模块
    递归和循环两种方式实现未知维度集合的笛卡尔积
    单例模式的两种实现方式
    经典String str = new String("abc")内存分配问题
    js方法的命名不能使用表单元素的名称或ID
  • 原文地址:https://www.cnblogs.com/chq011/p/6964211.html
Copyright © 2011-2022 走看看