博客描述:
本内容是基于idea和maven的一个SSM项目搭建的demo。创建项目时,记得联网(很重要)。
首先需要确定你的idea的maven,java环境是否正常。如下:
在上一步,点击Finish。完成创建。
操作:选中main文件夹,创建Directory。并标记为相应的文件夹类型。
选中main文件夹,使用快捷键(alt + inseert),使用键盘上、下键选中Dieectory。点击创建(名字分别是java、resources、test)。
标记成功时:发现头标,颜色发生了变化。
本人建议,配置上,因为很好用,可以当做Nativcat来用,而且提示很多。(谁用谁知道)
到这里,如果测试成功,那恭喜你,配置好了。Apply -> ok 就可以去使用了。
4.0.0
org.feng
ssm-demo
1.0-SNAPSHOT
war
ssm-demo Maven Webapp
http://www.example.com
UTF-8
1.8
1.8
4.3.14.RELEASE
junit
junit
4.11
test
org.springframework
spring-context
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework
spring-aspects
${spring.version}
org.aspectj
aspectjweaver
1.9.4
org.springframework
spring-orm
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-test
${spring.version}
org.mybatis
mybatis
3.4.6
org.mybatis
mybatis-spring
1.3.2
com.alibaba
druid
1.1.9
mysql
mysql-connector-java
5.1.35
taglibs
standard
1.1.2
jstl
jstl
1.2
javax.servlet
javax.servlet-api
3.1.0
javax.servlet.jsp
jsp-api
2.2
log4j
log4j
1.2.17
org.slf4j
slf4j-api
1.7.26
org.slf4j
slf4j-log4j12
1.7.12
commons-logging
commons-logging
1.2
com.alibaba
fastjson
1.2.9
ssm-demo
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-war-plugin
3.2.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
-- auto-generated definition
create table user
(
id int auto_increment comment 'id'
primary key,
name varchar(50) not null comment '名字',
password varchar(64) not null comment '密码',
birthday bigint(13) null comment '生日(long类型,存储毫秒数)',
info varchar(255) null comment '备注'
);
package org.feng.entity;
/**
* Created by Feng on 2019/10/18 10:07
* CurrentProject's name is ssm-demo
*/
public class User {
private Integer id;
private String name;
private String password;
private Long birthday;
private String info;
public User() {
}
public User(Integer id, String name, String password, Long birthday, String info) {
this.id = id;
this.name = name;
this.password = password;
this.birthday = birthday;
this.info = info;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Long getBirthday() {
return birthday;
}
public void setBirthday(Long birthday) {
this.birthday = birthday;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", password='" + password + '\'' +
", birthday=" + birthday +
", info='" + info + '\'' +
'}';
}
}
package org.feng.mapper;
import org.feng.entity.User;
import java.util.List;
/**
* Created by Feng on 2019/10/18 10:12
* CurrentProject's name is ssm-demo
*/
public interface UserMapper {
List userList();
}
package org.feng.service;
import org.feng.entity.User;
import java.util.List;
/**
* Created by Feng on 2019/10/18 13:18
* CurrentProject's name is ssm-demo
*/
public interface UserService {
List userList();
}
package org.feng.service.impl;
import org.feng.entity.User;
import org.feng.mapper.UserMapper;
import org.feng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by Feng on 2019/10/18 13:18
* CurrentProject's name is ssm-demo
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List userList() {
return userMapper.userList();
}
}
package org.feng.controller;
import org.feng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
/**
* Created by Feng on 2019/10/18 13:19
* CurrentProject's name is ssm-demo
*/
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("index.action")
public String toIndex(HttpServletRequest request){
request.getSession().setAttribute("userList", userService.userList());
return "index";
}
}
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm-demo?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
### set log levels ###
log4j.rootLogger = INFO , console , debug , error
### console ###
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
### log file ###
log4j.appender.debug = org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.File = logs/info.log
log4j.appender.debug.Append = true
log4j.appender.debug.Threshold = INFO
log4j.appender.debug.layout = org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
### exception ###
log4j.appender.error = org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File = logs/error.log
log4j.appender.error.Append = true
log4j.appender.error.Threshold = ERROR
log4j.appender.error.layout = org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
###\u9700\u8981\u58F0\u660E\uFF0C\u7136\u540E\u4E0B\u65B9\u624D\u53EF\u4EE5\u4F7Fdruid sql\u8F93\u51FA\uFF0C\u5426\u5219\u4F1A\u629B\u51FAlog4j.error.key not found
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{
ISO8601} %l %c%n%p\: %m%n
### druid sql ###
log4j.logger.druid.sql=warn,stdout
log4j.logger.druid.sql.DataSource=warn,stdout
log4j.logger.druid.sql.Connection=warn,stdout
log4j.logger.druid.sql.Statement=warn,stdout
log4j.logger.druid.sql.ResultSet=warn,stdout
此文件是对应了mybatis框架中的与Mapper接口对应的文件,在配置扫描包时,也是配置了它的路径。
Archetype Created Web Application
contextConfigLocation
classpath:applicationContext-*.xml
log4jConfigLocation
classpath:log4j.properties
DruidWebStatFilter
com.alibaba.druid.support.http.WebStatFilter
exclusions
*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encoding
*.action
DruidWebStatFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.Log4jConfigListener
DispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
DruidStatView
com.alibaba.druid.support.http.StatViewServlet
DispatcherServlet
*.action
DruidStatView
/druid/*
index.action
本页面进行测试。
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page isELIgnored="false" %>
Hello World!
${sessionScope.userList}