spring boot 开发相关

来源:互联网 发布:听东方软件 编辑:程序博客网 时间:2024/04/28 12:16

转载请注明出处。

用了spring boot有一段时间了,中途也遇到过一些坑.下面记录一下:
刚开始使用eclipse做开发,但是对于做android的我来说,eclipse很久不用了,最主要的是eclipse需要自己安装gradle,然后将web项目转成gradle项目.太麻烦了.鉴于spring boot内置tomcat,本身就是一个java程序,所以果断使用android studio进行开发.

以下有几个点需要注意:

  1. 目录结构:src/main下面一个java目录存放代码,另一个resources目录存放资源.(当然最主要的build.gradle要正确配置)
    项目结构图

  2. 使用的hibernate.cfg.xml文件内容,此处使用mysql:

<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <!-- Database connection settings -->        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="connection.url">jdbc:mysql://localhost:3306/m_c</property>        <property name="connection.username">thy</property>        <property name="connection.password">******</property>        <!-- SQL dialect -->        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>        <!-- Echo all executed SQL to stdout -->        <property name="show_sql">true</property>        <property name="format_sql">true</property>        <!-- Drop and re-create the database schema on startup -->        <property name="hbm2ddl.auto">update</property>        <mapping class="com.thy.model.User" />    </session-factory></hibernate-configuration>

3 . 关于jsp模板代码,代码置于resources/templates目录下,其他的css,js,图片等放到静态资源目录下,默认的资源目录

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {          "classpath:/META-INF/resources/", "classpath:/resources/",          "classpath:/static/", "classpath:/public/" };  

优先级顺序为:META/resources > resources > static > public

4 . 要使用html模板,需要引入以下模块

compile("org.springframework.boot:spring-boot-starter-thymeleaf")

暂时先写到这,以后在慢慢整理

0 0
原创粉丝点击