直接把项目建立在仓库的根目录即可,当然我们也可以创建两个仓库,一个前端项目仓库,一个后端项目仓库:
删除父工程下的src
创建子工程 system-adimin,删除掉父工程的src,将父工程的pom文件中的packaging改为pom,声明为一个父工程:
在父工程中加入以下依赖,进行依赖管理,每一个依赖的作用不在赘述,这是基本的ssm项目搭建
4.0.0
com.class
ydl_wssm_2
pom
1.0-SNAPSHOT
system-adimin
ruoyi
http://www.ydlclass.com
元动力管理系统
11
11
utf-8
4.0.1
5.2.18.RELEASE
2.6.0
1.9.6
1.18.22
2.13.1
2.0.1.Final
6.0.9.Final
1.2.6
1.3.3
1.2.8
8.0.26
3.5.5
2.0.6
javax.servlet
javax.servlet-api
${javax.servlet.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework.data
spring-data-commons
${spring-data-commons.version}
org.aspectj
aspectjweaver
${aspectjweaver.version}
org.projectlombok
lombok
${lombok.version}
com.fasterxml.jackson.core
jackson-core
${jackson.version}
com.fasterxml.jackson.core
jackson-annotations
${jackson.version}
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
javax.validation
validation-api
${validation-api.version}
org.hibernate
hibernate-validator
${hibernate-validator}
ch.qos.logback
logback-classic
${logback-classic.version}
commons-fileupload
commons-fileupload
${commons-fileupload.version}
com.alibaba
druid
${druid.version}
mysql
mysql-connector-java
${mysql-connector-java.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
${mybatis-spring.version}
org.apache.maven.plugins
maven-compiler-plugin
3.1
${java.version}
${project.build.sourceEncoding}
public
aliyun nexus
https://maven.aliyun.com/repository/public
true
在子工程中加入以下依赖:
ydl-back
com.ydl
1.0-SNAPSHOT
4.0.0
ydl-backend
11
11
javax.servlet
javax.servlet-api
org.springframework
spring-webmvc
org.springframework
spring-jdbc
org.springframework.data
spring-data-commons
org.aspectj
aspectjweaver
org.projectlombok
lombok
com.fasterxml.jackson.core
jackson-core
com.fasterxml.jackson.core
jackson-annotations
com.fasterxml.jackson.core
jackson-databind
javax.validation
validation-api
org.hibernate
hibernate-validator
ch.qos.logback
logback-classic
commons-fileupload
commons-fileupload
com.alibaba
druid
mysql
mysql-connector-java
org.mybatis
mybatis
org.mybatis
mybatis-spring
web.xml的内容
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:application.xml
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:application.xml
1
springmvc
/
jdbc.properties
//注意根据自己数据库密码账号改
user=root
password=root
url=jdbc:mysql://127.0.0.1:3306/ydlclass?characterEncoding=utf8&serverTimezone=Asia/Shanghai
driverName=com.mysql.cj.jdbc.Driver
application.xml,我们将spring和springmvc的配置统一在一个文件中,你也可以分开。
text/plain;charset=UTF-8
application/json;charset=UTF-8
logback日志的配置文件 logback.xml:
${log.pattern}
${log.path}/sys-info.log
${log.path}/sys-info.%d{yyyy-MM-dd}.log
60
${log.pattern}
INFO
ACCEPT
DENY
${log.path}/sys-error.log
${log.path}/sys-error.%d{yyyy-MM-dd}.log
60
${log.pattern}
ERROR
ACCEPT
DENY
创建CustomObjectMapper来配置jackson的序列化和反序列化:
public class CustomObjectMapper extends ObjectMapper {
public CustomObjectMapper() {
super();
//去掉默认的时间戳格式
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//设置为东八区
setTimeZone(TimeZone.getTimeZone("GMT+8"));
//设置日期转换yyyy-MM-dd HH:mm:ss
setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
// 设置输入:禁止把POJO中值为null的字段映射到json字符串中
configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
// 空值不序列化
setSerializationInclusion(JsonInclude.Include.NON_NULL);
// 反序列化时,属性不存在的兼容处理
getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// 序列化枚举是以toString()来输出,默认false,即默认以name()来输出
configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
}
}
启动测试
http://localhost:8080/admin/
http://localhost:8080/admin/test
如遇无法启动更换端口尝试
测试controller
@Controller
public class TestController {
@GetMapping("user")
@ResponseBody
public User test(){
return new User("tom",12);
}
@ResponseBody
public User test(){
return new User("tom",12);
}
static class User{
String username;
Integer age;
public User(String username, Integer age) {
this.username = username;
this.age = age;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
}
启动成功
访问
http://localhost:8080/admin/user