java 快速构建ssm项目_SSM快速搭建
基本环境搭建
1、 创建Maven工程
2、 导入项目相关依赖的jar包
spring
springmvc
mybatis
mysql
junit
spring-test
lombok
devtools
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">
4.0.0
org.example
ssm-crud
1.0-SNAPSHOT
org.springframework
spring-webmvc
5.2.8.RELEASE
org.springframework
spring-aspects
5.2.8.RELEASE
org.springframework
spring-jdbc
5.2.8.RELEASE
org.springframework
spring-aop
5.2.8.RELEASE
org.springframework
spring-tx
5.2.8.RELEASE
com.fasterxml.jackson.core
jackson-databind
2.11.2
org.mybatis
mybatis
3.5.0
org.mybatis
mybatis-spring
2.0.5
mysql
mysql-connector-java
8.0.21
com.alibaba
druid
1.1.24
javax.servlet.jsp
javax.servlet.jsp-api
2.3.3
provided
jstl
jstl
1.2
javax.servlet
javax.servlet-api
4.0.1
provided
junit
junit
4.12
test
org.springframework
spring-test
5.2.8.RELEASE
test
org.mybatis.generator
mybatis-generator-core
1.4.0
com.github.pagehelper
pagehelper
5.1.10
com.github.jsqlparser
jsqlparser
3.1
org.projectlombok
lombok
1.18.12
provided
org.springframework.boot
spring-boot-devtools
1.5.6.RELEASE
true
3、 引用bootstrap前端框架
4、 编写ssm相关配置文件
web.xml
spring-mvc.xml
appicationContext.xml
spring-mybatis.xml
jdbc.properties
4.1、web.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
com.example.demo.Listener.MyContextListener
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceRequestEncoding
true
forceResponseEncoding
true
characterEncodingFilter
/*
hiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
hiddenHttpMethodFilter
/*
4.2、spring-mvc.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
4.3、appicationContext.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
4.4、spring-mybatis.xml
/p>
"http://mybatis.org/dtd/mybatis-3-config.dtd">
4.5、jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
jdbc.username=root
jdbc.password=12345678
4.6、log4j.properties
#############
# 输出到控制台
#############
# log4j.rootLogger日志输出类别和级别:只输出不低于该级别的日志信息DEBUG < INFO < WARN < ERROR < FATAL
# WARN:日志级别 CONSOLE:输出位置自己定义的一个名字 logfile:输出位置自己定义的一个名字
log4j.rootLogger=WARN,CONSOLE,logfile
# 配置CONSOLE输出到控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
# 配置CONSOLE设置为自定义布局模式
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
# 配置CONSOLE日志的输出格式 [frame] 2019-08-22 22:52:12,000 %r耗费毫秒数 %p日志的优先级 %t线程名 %C所属类名通常为全类名 %L代码中的行号 %x线程相关联的NDC %m日志 %n换行
log4j.appender.CONSOLE.layout.ConversionPattern=[frame] %d{yyyy-MM-dd HH:mm:ss,SSS} - %-4r %-5p [%t] %C:%L %x - %m%n
################
# 输出到日志文件中
################
# 配置logfile输出到文件中 文件大小到达指定尺寸的时候产生新的日志文件
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
# 保存编码格式
log4j.appender.logfile.Encoding=UTF-8
# 输出文件位置此为项目根目录下的logs文件夹中
log4j.appender.logfile.File=logs/root.log
# 后缀可以是KB,MB,GB达到该大小后创建新的日志文件
log4j.appender.logfile.MaxFileSize=10MB
# 设置滚定文件的最大值3 指可以产生root.log.1、root.log.2、root.log.3和root.log四个日志文件
log4j.appender.logfile.MaxBackupIndex=3
# 配置logfile为自定义布局模式
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %F %p %m%n
##########################
# 对不同的类输出不同的日志文件
##########################
# club.bagedate包下的日志单独输出
log4j.logger.club.bagedate=DEBUG,bagedate
# 设置为false该日志信息就不会加入到rootLogger中了
log4j.additivity.club.bagedate=false
# 下面就和上面配置一样了
log4j.appender.bagedate=org.apache.log4j.RollingFileAppender
log4j.appender.bagedate.Encoding=UTF-8
log4j.appender.bagedate.File=logs/bagedate.log
log4j.appender.bagedate.MaxFileSize=10MB
log4j.appender.bagedate.MaxBackupIndex=3
log4j.appender.bagedate.layout=org.apache.log4j.PatternLayout
log4j.appender.bagedate.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %F %p %m%n
5、工具类
5.1.1 Msg(封装返回信息的对象)
@Data
public class Msg {
//100代表成功,200代表失败
private int code;
private String message;
private Map data;
public Msg() {
data = new HashMap<>();
}
public static Msg success() {
Msg msg = new Msg();
msg.setCode(100);
msg.setMessage("处理成功!");
return msg;
}
public static Msg error() {
Msg msg = new Msg();
msg.setCode(200);
msg.setMessage("处理失败!");
return msg;
}
public Msg addData(String s, Object o) {
data.put(s, o);
return this;
}
}
6、mybatis generator(mybatis逆向工程)
6.1、配置文件
/p>
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
connectionURL="jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC"
userId="root"
password="12345678">
6.2、生成文件的类
public class Generator {
@Test
public void generator() throws Exception {
List warnings = new ArrayList();
// 指定配置文件
File configFile = new File("F:/MyProjects/complete/ssm-crud/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}
遇到的坑
坑一
c3p0-0.9.5.2 jar包缺少其它依赖
解决办法:添加mchange-commons-java-0.2.20 jar包(注意jar包版本)
com.mchange
mchange-commons-java
0.2.20
坑二
pagehelper-5.1.10 jar包缺少其它依赖
解决方法:添加jsqlparser-3.1 jar包(注意jar包版本)
com.github.jsqlparser
jsqlparser
3.1
坑三
关闭tomcat时报错
错误提示:Web应用程序[ROOT]似乎启动了一个名为[C3P0PooledConnectionPoolManager[identityToken->31usy7ac1ocyx2d1tj3xmv|630da823]-AdminTaskTimer]的线程,但未能停止它。这很可能会造成内存泄漏。
解决方法: 换数据源druid
com.alibaba
druid
1.1.24
坑四
关闭tomcat时报错
错误提示:为防止内存泄漏,JDBC驱动程序已被强制取消注册。
解决方法:配置监听器jie
com.example.demo.config.listener.MyContextListener
public class MyContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("webService start");
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("webService stop");
try {
while (DriverManager.getDrivers().hasMoreElements()) {
DriverManager.deregisterDriver(DriverManager.getDrivers().nextElement());
}
System.out.println("jdbc Driver close");
AbandonedConnectionCleanupThread.checkedShutdown();
System.out.println("clean thread success");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
坑五
使用lombok插件,编写实体类时,某成员变量的第二个字母为大写,导致springmvc无法接收前台传来的参数
解决方法:自己编写setter/getter
private Integer dId;
//解决dId无法接收参数的问题,下面的命名方式是JavaBean规范命名
public Integer getdId() {
return dId;
}
public void setdId(Integer dId) {
this.dId = dId;
}
java 快速构建ssm项目_SSM快速搭建相关推荐
- 使用maven快速构建SSM项目
这里我就假设大家都已经配置好Maven,就不在重复说明了.若没有配置可以参考<首次使用maven的配置过程>. 1.新建Maven项目 工作区–右键-new-other–搜索maven 现 ...
- java实现登陆ssm框架_SSM框架搭建web服务器实现登录功能(Spring+SpringMVC+Mybatis)
初学java EE,虽然知道使用框架会使开发更加便捷高效,但是对于初学者来说,感到使用框架比较迷惑,尤其是各种jar包的引用.各种框架的配置.注解的使用等等. 最好的学习方法就是实践,于是下载了一个现 ...
- SpringBoot2.1.5 (5)---快速构建SpringBoot 项目的两种方式
快速构建SpringBoot项目的两种方发 一. 通过 http://start.spring.io/ 在线构建 二. 通过IntelliJ IDEA 快速构建 通过 http://start.spr ...
- vue-cli快速构建vue项目和本地模拟请求数据
Vue-cli快速构建 Vue 项目和本地模拟请求数据 1 前提: 安装了 node.js 首先: 全局安装 vue-cli npm intsall vue-cli -g (-g代表全局安装) 2 使 ...
- 用cookiecutter快速构建机器学习项目结构
文章目录 为什么要采用标准化的项目结构? 用cookiecutter生成更好的项目结构 快速入门 1.安装cookiecutter 2.使用项目工程模板开始一个新项目 3.常用文件说明 数据科学/机器 ...
- eclipse java maven_Eclipse构建maven项目
Eclipse构建maven项目 1 Maven项目转为Eclipse项目 在项目的根目录下打开cmd:执行命令:mvn eclipse:eclipse :将会出现.classpath和.projec ...
- IDEA中使用Maven构建SSM项目
文章目录 第一步 创建Maven webapp项目 第二步 搭建项目目录结构 第三步 添加配置文件内容 第四步 测试 第一步 创建Maven webapp项目 1. 首先,新建工程; 2. 选择Mav ...
- java ssm 项目_ssm开源java博客项目,基于maven搭建
项目描述 1,包含登录注册,用户密码,加密 2,博客图片采用网络地址存储, 运行环境 jdk7+tomcat7+mysql5.6+IntelliJ IDEA+maven 项目技术(必填) spring ...
- 使用dva脚手架(dva-cli)快速构建React项目
安装 dva-cli 你应该会更希望关注逻辑本身,而不是手动敲入一行行代码来构建初始的项目结构,以及配置开发环境. 那么,首先需要安装的是 dva-cli .dva-cli 是 dva 的命令行工具, ...
最新文章
- MapReduce 中 UDF、UDAF、UDTF
- phpmyadmin 忘记密码重设password
- C# WebBrowser document.execCommand()解析
- JAVA流程控制学习总结
- Inline Method(内联函数)
- 程序员需要避免的 10 个坏习惯
- BGP——AS—PATH正则表达式(实列讲解+配置)
- OpenShift 4 之通过ImageTrigger自动构建变化级联镜像
- [POJ3580]SuperMemo
- 图卷积网络的半监督学习脉络
- 微软windows10易升_微软官网下载与安装windows10系统的操作步骤
- 如何在CAD编辑软件中画椭圆
- 2022华为杯E题思路分析
- c语言第五章答案许合利,C语言习题答案贾宗璞许合利较全-.doc
- java画篮球_PS教程!手把手教你绘制炫酷的科比篮球海报
- leetcode 61 旋转链表 c++
- mysql命令行安装教程_MySQL命令行教程
- 2021年岳阳市一中高考成绩查询,湖南岳阳的4所最强高中,2020年高考成绩抢眼,岳阳市一中领先...
- Mandelbrot 并行实现
- 【渝粤教育】电大中专跨境电子商务理论与实务 (2)作业 题库
热门文章
- 多节锂电串联保护板ic_如何有效保护锂电池板,一款优质的MOS管就能解决
- VGA光纤收发器特点及参数
- 光纤交换机的配置 光纤交换机的由来是什么
- 【渝粤题库】陕西师范大学180113 学前儿童艺术教育作业
- 渝粤教育 陕西师范大学 《初级微观经济学》作业
- java发邮件无主题,使用SpringCloud过程中遇到的一些问题
- 蓝桥杯基础模块8_1:串口通信收发
- python实例讲解wxpythonhyh123_Python实例讲解 -- wxpython 基本的控件 (按钮)
- 顺序表输入栈元素c语言,C语言数据结构之栈简单操作
- vue 路由知识点梳理及应用场景整理