ssm
5.1.5.RELEASE
junit
junit
4.12
test
org.springframework
spring-core
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-aspects
${spring.version}
aopalliance
aopalliance
1.0
org.aspectj
aspectjweaver
1.9.2
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
commons-fileupload
commons-fileupload
1.3.3
commons-io
commons-io
2.6
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:springmvc.xml
1
dispatcherServlet
/
HiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
HiddenHttpMethodFilter
dispatcherServlet
注意:此时applicationContext.xml文件为核心配置,springmvc.xml为mvc配置,将来会有更多的类似于mvc这样的附属配置被加入到核心配置中。
所以需要修改web.xml中contextConfigLocation属性为applicationContext.xml
contextConfigLocation
classpath*:applicationContext.xml
org.mybatis
mybatis
3.5.0
com.mchange
c3p0
0.9.5.2
mysql
mysql-connector-java
8.0.13
org.mybatis.generator
mybatis-generator-core
1.3.7
log4j
log4j
1.2.17
org.mybatis
mybatis-spring
1.3.2
# 主要配置
log4j.rootLogger=DEBUG,Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.org.apache=INFO
applicationContext.xml集成jdbc.properties
jdbc.username=test
jdbc.password=123456
# mysql8 加入时区
jdbc.url=jdbc:mysql://localhost:3306/jdbcdb?serverTimezone=UTC
# 采用新版的cj驱动
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.maxActive=50
com.hliedu.ssm.domain
public class Emp {
private Integer eid;
private String ename;
private String job;
//setter getter ...
}
@Repository
public interface EmpMapper {
List queryEmp();
}
public interface EmpService {
List queryEmp();
}
@Service("empService")
public class EmpServiceImpl implements EmpService {
@Autowired
private EmpMapper empMapper;
@Override
public List queryEmp() {
return empMapper.queryEmp();
}
}
在src/test/java下新建com.hliedu.test.SSMTest类
main方法测试
public class SSMTest {
public static void main(String[] args) {
ApplicationContext context = new
ClassPathXmlApplicationContext("applicationContext.xml");
EmpService empService = (EmpService)context.getBean("empService");
System.out.println(empService.queryEmp());
}
}
junit
junit
4.11
test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:applicationContext.xml"})
public class SSMTest {
@Autowired
ApplicationContext ctx;
@Test
public void test() {
EmpService empService = (EmpService)ctx.getBean("empService");
System.out.println(empService.queryEmp());
}
}
org.springframework
spring-tx
${spring.version}
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
@Transactional
@Override
public boolean addEmp() {
Emp emp1 = new Emp(1005 , "zs" , "程序员");
empMapper.addEmp(emp1);
//可能会出现异常的行
System.out.println(10/0);
Emp emp2 = new Emp(1006 , "ls" , "项目经理");
empMapper.addEmp(emp2);
return false;
}
javax.validation
validation-api
2.0.1.Final
org.hibernate
hibernate-validator
6.0.13.Final
给属性加入验证注解
给handler中方法入参加入@Valid注解
@RequestMapping("/emp")
@Controller
public class EmpController {
@Autowired
private EmpService empService;
@RequestMapping("query")
public String query(ModelMap modelMap){
List emps = empService.queryEmp();
modelMap.addAttribute("emps" , emps);
return "empList";
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Emp
${requestScope.emps}
(1)出现查询时无法调用mapper.xml问题Invalid bound statement (not found):
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
om.mchange.v2.c3p0.impl.NewProxyResultSet.isClosed
出现该错误,请对照上面c3p0依赖部分的版本是否为com.mchange下的0.9.5.2
【01】SSM框架整合