pom.xml
4.0.0
war
ssmmerger
org.example
ssmmerger
1.0-SNAPSHOT
org.mortbay.jetty
maven-jetty-plugin
6.1.7
8888
30000
${project.build.directory}/${pom.artifactId}-${pom.version}
/
UTF-8
1.8
1.8
5.2.8.RELEASE
2.10.0
junit
junit
4.12
test
ch.qos.logback
logback-classic
1.2.3
org.projectlombok
lombok
1.18.10
provided
mysql
mysql-connector-java
8.0.15
com.alibaba
druid
1.1.12
org.mybatis
mybatis
3.4.6
javax
javaee-api
8.0
provided
javax.servlet
jstl
1.2
com.fasterxml.jackson.core
jackson-core
${jackson.version}
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
com.fasterxml.jackson.core
jackson-annotations
${jackson.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.aspectj
aspectjweaver
1.9.4
org.springframework
spring-test
${spring.version}
test
org.mybatis
mybatis-spring
1.3.2
javax.servlet
javax.servlet-api
3.1.0
jdbc.properties
jdbc.driver = com.mysql.cj.jdbc.Driver
jdbc.username = root
jdbc.password = 123456
jdbc.url = jdbc:mysql://localhost:3306/test?serverTimezone=UTC
mybatis-config.xml
logback.xml
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
spring-dao.xml
spring-service
spring-web
web.xml
index.html
mvc-dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/spring-*.xml
mvc-dispatcher
/
UserDao
package com.mbkj.dao;
import com.mbkj.entity.User;
import java.util.List;
public interface UserDao {
List selectAll();
}
UserDao.xml
UserService
package com.mbkj.service;
import com.mbkj.entity.User;
import java.util.List;
public interface UserService {
List selectAll();
}
UserServiceImpl
package com.mbkj.service.impl;
import com.mbkj.dao.UserDao;
import com.mbkj.entity.User;
import com.mbkj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public List selectAll() {
return userDao.selectAll();
}
}
UserTest
import com.mbkj.entity.User;
import com.mbkj.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml"})
@WebAppConfiguration
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void testCRUD(){
List users = userService.selectAll();
for (User user : users) {
System.out.println(user);
}
}
}
UserController
package com.mbkj.web;
import com.mbkj.entity.User;
import com.mbkj.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.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserService service;
@RequestMapping(value = "/list", method = RequestMethod.GET)
private String list(Model model) {
List list = service.selectAll();
model.addAttribute("list", list);
return "list";// WEB-INF/jsp/"list".jsp
}
}
list.jsp
<%--
Created by IntelliJ IDEA.
User: Richer
Date: 2020/9/15
Time: 15:21
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Title
用户id
用户code
${user.id}
${user.code}