Maven安装可以参看Maven安装
4.0.0
com.xiangty
ssm-template
1.0-SNAPSHOT
war
ssm-template Maven Webapp
http://www.example.com
UTF-8
1.8
1.8
4.3.4.RELEASE
junit
junit
4.12
test
javax.servlet
javax.servlet-api
3.1.0
provided
javax.servlet.jsp
javax.servlet.jsp-api
2.3.1
javax.servlet
jstl
1.1.2
taglibs
standard
1.1.2
org.springframework
spring-core
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-aspects
${spring.version}
org.mybatis
mybatis
3.4.0
org.mybatis
mybatis-spring
1.3.0
mysql
mysql-connector-java
5.1.30
com.alibaba
druid
1.0.16
log4j
log4j
1.2.17
org.slf4j
slf4j-api
1.7.7
org.slf4j
slf4j-log4j12
1.7.7
commons-logging
commons-logging
1.2
commons-fileupload
commons-fileupload
1.2.2
commons-io
commons-io
2.4
commons-fileupload
commons-fileupload
1.2.2
commons-io
commons-io
2.4
ssm-template
注:配置依赖,需要注意一些常见的配置:
第一种如下图
第二种测试依赖中
添加依赖
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/数据库名称
jdbc.username=用户名
jdbc.password=密码
jdbc.minPoolSize=5
jdbc.maxPoolSize=20
#初始化大小
jdbc.initialSize=1
#最小
jdbc.minIdle=1
#最大
jdbc.maxActive=20
#获取连接等待超时的时间
jdbc.maxWait=60000
### 设置###
log4j.rootLogger=debug,stdout,D,E
### 输出信息到控制抬 ###
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=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出DEBUG 级别以上的日志到=E://logs/log.log ###
log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.D.File = E://logs/log.log
log4j.appender.D.Append=true
log4j.appender.D.Threshold=DEBUG
log4j.appender.D.layout=org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append=true
log4j.appender.E.Threshold=ERROR
log4j.appender.E.layout=org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
Archetype Created Web Application
/index.jsp
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:spring/spring-*.xml,
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/spring-mvc.xml
1
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*
项目结构如下,控制器代码如图
User.java
package com.xiangty.ssmtemplate.entity;
/**
* @Classname User
* @Description TODO
* @Date 2019/6/7 23:48
* @Created by xiangty
*/
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
CalculatorController.java
package com.xiangty.ssmtemplate.controller.calculator;
import com.xiangty.ssmtemplate.entity.User;
import com.xiangty.ssmtemplate.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @Classname CalculatorController
* @Description TODO
* @Date 2019/6/7 23:41
* @Created by xiangty
*/
@Controller
public class CalculatorController {
private static final Logger LOGGER = LoggerFactory.getLogger(CalculatorController.class);
@Autowired
private UserService userService;
@RequestMapping(value = "/calcLoginPage")
public void calcLoginPage() {
System.out.println("calcLoginPage时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
LOGGER.info("iiiiiiiiiii");
LOGGER.debug("dddddddd");
LOGGER.warn("wwwwwwwwww");
LOGGER.error("eeeeeeeee");
List userList = userService.queryUserList();
for(User user : userList){
LOGGER.info("id:{}", user.getId());
LOGGER.info("username:{}",user.getUsername());
LOGGER.info("password:{}",user.getPassword());
}
}
}
UserService.java
package com.xiangty.ssmtemplate.service;
import com.xiangty.ssmtemplate.entity.User;
import java.util.List;
/**
* @Classname UserService
* @Description TODO
* @Date 2019/6/8 21:17
* @Created by xiangty
*/
public interface UserService {
List queryUserList();
}
UserServiceImpl.java
package com.xiangty.ssmtemplate.service.impl;
import com.xiangty.ssmtemplate.entity.User;
import com.xiangty.ssmtemplate.dao.UserMapper;
import com.xiangty.ssmtemplate.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @Classname UserServiceImpl
* @Description TODO
* @Date 2019/6/8 21:17
* @Created by xiangty
*/
@Transactional
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List queryUserList() {
return userMapper.queryUserList();
}
}
UserMapper.java
package com.xiangty.ssmtemplate.dao;
import com.xiangty.ssmtemplate.entity.User;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Classname UserMapper
* @Description TODO
* @Date 2019/6/7 23:51
* @Created by xiangty
*/
@Repository
public interface UserMapper {
List queryUserList();
}
UserMapper.xml
ID, USERNAME, PASSWORD
启动项目,访问http://localhost:8080/calcLoginPage,控制台输出下放内容,说明正常。(按照控制器的打印格式打印信息)