从学校毕业,参加了第一份工作,由于自己基础的薄弱,导致被公司辞退,在公司呆了半个月收获也是挺丰厚的,springboot整合ssm就是我学到的,分享给大家
说到springboot 网上的介绍有很多,我这就不再赘述,下面开始搭建项目了
上面这一页就是你项目的信息
点上这些就不用你后期的添加了
完成之后的样子是这样的
其中红框框标出来的就是程序启动的入口
由于springboot很少有配置文件,所有的配置都放在这里
下面是我的pom文件,有点多,懒得删,你们自己研究哈
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sxxm</groupId>
<artifactId>sxxm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sxxm</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mybatis.boot.starter.version>1.3.2</mybatis.boot.starter.version>
<mapper.spring.boot.starter.version>2.0.3</mapper.spring.boot.starter.version>
<pagehelper.spring.boot.starter.version>1.2.5</pagehelper.spring.boot.starter.version>
<mysql.connector.java.version>8.0.12</mysql.connector.java.version>
<druid.version>1.1.10</druid.version>
<commons.io.version>2.4</commons.io.version>
<spring.boot.starter.redis.version>1.4.7.RELEASE</spring.boot.starter.redis.version>
<spring.session.data.redis.version>2.0.4.RELEASE</spring.session.data.redis.version>
<jackson.mapper.asl.version>1.9.13</jackson.mapper.asl.version>
<json.lib.version>2.4</json.lib.version>
<json.lib.classifier>jdk15</json.lib.classifier>
<commons.beanutils.version>1.9.3</commons.beanutils.version>
<commons.collections.version>3.2.2</commons.collections.version>
<commons.lang.version>2.6</commons.lang.version>
<commons.logging.version>1.2</commons.logging.version>
<ezmorph.version>1.0.6</ezmorph.version>
<poi.version>4.0.1</poi.version>
<poi.ooxml.schemas.version>4.0.1</poi.ooxml.schemas.version>
<poi.ooxml.version>4.0.1</poi.ooxml.version>
<poi.scratchpad.version>4.0.1</poi.scratchpad.version>
<org.apache.poi.xwpf.converter.xhtml.version>1.0.4</org.apache.poi.xwpf.converter.xhtml.version>
<org.apache.poi.xwpf.converter.core.version>1.0.4</org.apache.poi.xwpf.converter.core.version>
<ooxml.schemas.version>1.1</ooxml.schemas.version>
<xmlbeans.version>3.1.0</xmlbeans.version>
<commons.fileupload.version>1.3</commons.fileupload.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--springboot freemarker-->
<!--
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!--
在pom文件中增加spring-boot-starter-web的maven依赖时,
不做任何web相关的配置便能提供web服务,这还得归于spring boot
自动配置的功能(因为加了EnableAutoConfiguration的注解),
帮我们创建了一堆默认的配置:servlet配置, filter配置,
listener配置,修改filter的映射
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Seesion + redis-->
<!-- <dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>-->
<!-- redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<!-- 1.5的版本默认采用的连接池技术是jedis,2.0以上版本默认连接池是lettuce, 因为此次是采用jedis,所以需要排除lettuce的jar -->
<exclusions>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</exclusion>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- jedis客户端 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<!-- spring2.X集成redis所需common-pool2,使用jedis必须依赖它-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!--
spring boot整合mybatis
使用了该Starter之后,只需要定义一个DataSource即可,
它会自动创建使用该DataSource的SqlSessionFactoryBean
以及SqlSessionTemplate。会自动扫描你的Mappers,连接到
SqlSessionTemplate,并注册到Spring上下文中
-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.boot.starter.version}</version>
</dependency>
<!--mybatis-spring-boot通用Mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${mapper.spring.boot.starter.version}</version>
</dependency>
<!-- pagehelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.spring.boot.starter.version}</version>
</dependency>
<!-- 使用MySql数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.java.version}</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- IO文件流驱动 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<!-- jackson支持包 -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.mapper.asl.version}</version>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json.lib.version}</version>
<classifier>${json.lib.classifier}</classifier>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons.beanutils.version}</version>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons.collections.version}</version>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
</dependency>
<!-- JSON 及其依赖包 https://mvnrepository.com/artifact/net.sf.ezmorph/ezmorph -->
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>${ezmorph.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>${xmlbeans.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.ooxml.schemas.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.scratchpad.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>${ooxml.schemas.version}</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.core</artifactId>
<version>${org.apache.poi.xwpf.converter.core.version}</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>
<version>${org.apache.poi.xwpf.converter.xhtml.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons.fileupload.version}</version>
</dependency>
<!--配置热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.gitee.qdbp.thirdparty</groupId>
<artifactId>ueditor</artifactId>
<version>1.4.3.3</version>
</dependency>
<!--bootstrap-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
</dependencies>
<!-- 声明依赖配置 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 配置远程仓库 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!--
添加mavenc插件
在添加了该插件之后,当运行“mvn package”进行打包时,会打包成一个可以
直接运行的 JAR 文件,使用“java -jar”命令就可以直接运行。这在很大程度
上简化了应用的部署,只需要安装了 JRE 就可以运行
-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--mybatis文件生成插件-->
<!-- <plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>-->
</plugins>
</build>
</project>
application.properties文件
#配置数据库
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mids?serverTimezone=Hongkong&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=123456
#配置数据源类型
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
########################################################
###freemarker
########################################################
#访问后缀名
spring.freemarker.suffix=.html
spring.freemarker.content-type=text/html
spring.freemarker.enabled=true
#缓存配置
spring.freemarker.cache=false
spring.freemarker.encoding=UTF-8
#模板的加载路径
spring.freemarker.template-loader-path=classpath:/templates/
#解决freemarker中long型自动格式化成科学计数法的问题
spring.freemarker.settings.number_format=0.###########
#服务名称--这里不配置项目名称
#spring.application.name=sxxm
#数据库
mapper.identity=MYSQL
#后台打印SQL
#logging.level.com.sinosoft.mapper=DEBUG
#logging.level.com.eth.wallet.mapper=debug
logging.level.com.text.xxm.mapper=debug
#pagehelper 分页插件mybatis
# 方法 startpage(page,rows);
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
#redis
#spring.redis.host=localhost
#spring.redis.port=6379
#spring.redis.password=
#spring.redis.timeout=2000ms
#最大连接数据库连接数,设 0 为没有限制,一般把maxActive设置成可能的并发量就行了
#spring.redis.jedis.pool.max-active=8
#最大等待连接中的数量,设 0 为没有限制
#spring.redis.jedis.pool.min-idle=0
#最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连接将被标记为不可用,然后被释放。设为0表示无限制。
#spring.redis.jedis.pool.max-idle=8
#最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示
#spring.redis.jedis.pool.max-wait=-1ms
#设置最大上传下载文件大小
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
#设置tomcat参数
server.tomcat.uri-encoding=utf-8
server.tomcat.max-connections=1000
#端口号
server.port=80
#mybatis&&通用Mapper
#扫描实体类的所在包
mybatis.type-aliases-package=com.text.xxm.model
#配置扫描xml文件路径
mybatis.mapper-locations=classpath:/mapper/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
#mybatis.config-location=classpath:mybatis-config.xml
#<settings> <setting name="mapUnderscoreToCameICase" value="true" /> </setting>
还有前后端分离*****************
在这里建了一个类,用来给页面返回json格式的数据
里面的内容如下
package com.text.xxm.base.controller;
import java.io.Serializable;
public class Result implements Serializable {
/**
* 返回状态标识:true成功 false失败
*/
public boolean res;
/**
* 成功或者错误消息
*/
public String msg;
/**
* 返回数据
*/
public Object data;
public boolean isRes() {
return res;
}
public void setRes(boolean res) {
this.res = res;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
/**
* 构造方法
* @return
*/
public Result(){
}
/**
* 构造方法
* @return
*/
public static Result success(){
Result result=new Result();
result.setRes(true);
return result;
}
/**
* 构造方法
* @return
*/
public static Result success(Object data){
Result result=new Result();
result.setRes(true);
result.setData(data);
return result;
}
/**
* 构造方法
* @return
*/
public static Result success(String msg,Object data){
Result result=new Result();
result.setRes(true);
result.setMsg(msg);
result.setData(data);
return result;
}
public static Result fail(){
Result result=new Result();
result.setRes(false);
return result;
}
/**
* 构造方法
* @return
*/
public static Result fail(String msg){
Result result=new Result();
result.setRes(false);
result.setMsg(msg);
return result;
}
/**
* 构造方法
* @return
*/
public static Result fail(String msg,Object data){
Result result=new Result();
result.setRes(false);
result.setMsg(msg);
result.setData(data);
return result;
}
}
哎,我这糟糕的解说,贴上项目,有需要的自己下载看吧,嘿嘿嘿
说一下,某宝可以代下,1.5一个哈哈哈哈