├── .gitignore
├── WebContent
├── META-INF
│ └── MANIFEST.MF
├── index.jsp
└── WEB-INF
│ ├── views
│ └── jsp
│ │ └── student
│ │ └── list-success.jsp
│ └── web.xml
├── src
├── main
│ ├── resources
│ │ ├── mybatis
│ │ │ ├── mybatis-config.xml
│ │ │ └── sqlmap-student.xml
│ │ ├── ehcache.xml
│ │ ├── struts.xml
│ │ ├── log4j.properties
│ │ ├── spring
│ │ │ ├── applicationContext.xml
│ │ │ ├── applicationContext-cache.xml
│ │ │ └── applicationContext-database.xml
│ │ └── struts
│ │ │ └── struts-student.xml
│ └── java
│ │ └── cn
│ │ └── amumu
│ │ └── spring
│ │ ├── dao
│ │ └── StudentDao.java
│ │ ├── service
│ │ ├── StudentService.java
│ │ └── StudentServiceImpl.java
│ │ ├── orm
│ │ └── Student.java
│ │ └── action
│ │ └── StudentAction.java
└── test
│ └── java
│ └── cn
│ └── amumu
│ └── spring
│ └── test
│ └── Main.java
├── sql
└── student.sql
├── README.md
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /target
3 |
--------------------------------------------------------------------------------
/WebContent/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/mybatis/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/cn/amumu/spring/dao/StudentDao.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.dao;
2 |
3 | import java.util.List;
4 |
5 | import cn.amumu.spring.orm.Student;
6 |
7 | public interface StudentDao {
8 |
9 | public Student findById(Long id);
10 |
11 | public void save(Student student);
12 |
13 | public List findAll();
14 |
15 | public void delete(long studentId);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/amumu/spring/service/StudentService.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.service;
2 |
3 | import java.util.List;
4 |
5 | import cn.amumu.spring.orm.Student;
6 |
7 | public interface StudentService {
8 | public Student getStudent(long studentId);
9 |
10 | public void saveStudent(Student student);
11 |
12 | public List findAll();
13 |
14 | public void delete(long studentId);
15 | }
16 |
--------------------------------------------------------------------------------
/WebContent/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | SSH Framework
8 |
9 |
10 | Hello SSH!
11 | list all
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/resources/ehcache.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/struts.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=DEBUG, stdout
2 |
3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 |
6 | # Pattern to output the caller's file name and line number.
7 | log4j.appender.stdout.layout.ConversionPattern=%d %5p (%F:%L) - %m%n
8 |
9 | log4j.appender.R=org.apache.log4j.RollingFileAppender
10 | log4j.appender.R.File=${spring.root}/WEB-INF/example.log
11 |
12 | log4j.appender.R.MaxFileSize=100KB
13 |
14 | # Keep one backup file
15 | log4j.appender.R.MaxBackupIndex=1
16 |
17 | log4j.appender.R.layout=org.apache.log4j.PatternLayout
18 | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
--------------------------------------------------------------------------------
/src/main/resources/spring/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sql/student.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : localhost_3306
5 | Source Server Version : 50613
6 | Source Host : localhost:3306
7 | Source Database : test
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50613
11 | File Encoding : 65001
12 |
13 | Date: 2013-08-22 18:02:15
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 |
18 | -- ----------------------------
19 | -- Table structure for student
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `student`;
22 | CREATE TABLE `student` (
23 | `id` int(11) NOT NULL AUTO_INCREMENT,
24 | `name` varchar(20) NOT NULL,
25 | `age` tinyint(4) NOT NULL,
26 | PRIMARY KEY (`id`)
27 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
28 |
--------------------------------------------------------------------------------
/src/test/java/cn/amumu/spring/test/Main.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.test;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | import cn.amumu.spring.service.StudentService;
8 |
9 | public class Main {
10 |
11 | static Logger logger = LoggerFactory.getLogger(Main.class);
12 |
13 | public static void main(String[] args) {
14 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
15 | "spring/applicationContext.xml");
16 | StudentService studentService = (StudentService) context
17 | .getBean("studentServiceImpl");
18 |
19 | logger.info("findAll : " + studentService.findAll().size());
20 | context.close();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/resources/mybatis/sqlmap-student.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 | insert into student(name,age) values(#{name},#{age})
12 |
13 |
14 |
17 |
18 |
19 | delete from student where id = #{id}
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | spring
2 | ======
3 |
4 | [](https://gitter.im/cr2121/spring?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5 |
6 | spring3 + hibernate4 + struts2
7 | spring3 + mybatis + struts2
8 |
9 | when first run this,
10 | shall change the database setting in applicationContext-database.xml
11 |
12 |
13 |
14 |
15 | as your database setting
16 |
17 | and run the following command in your mysql
18 |
19 | create table student(
20 | id bigint NOT NULL auto_increment,
21 | name VARCHAR(30),
22 | age INT,
23 | primary key (id));
24 |
25 |
--------------------------------------------------------------------------------
/src/main/resources/spring/applicationContext-cache.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/cn/amumu/spring/orm/Student.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.orm;
2 |
3 | public class Student implements java.io.Serializable {
4 |
5 | private static final long serialVersionUID = -8425430450416253627L;
6 |
7 | private Long id;
8 | private String name;
9 | private Integer age;
10 |
11 | public Student(){
12 | }
13 |
14 | public Student(String name, Integer age) {
15 | this.name = name;
16 | this.age = age;
17 | }
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 |
23 | public void setId(Long id) {
24 | this.id = id;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public void setName(String name) {
32 | this.name = name;
33 | }
34 |
35 | public Integer getAge() {
36 | return age;
37 | }
38 |
39 | public void setAge(Integer age) {
40 | this.age = age;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/resources/struts/struts-student.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 | /WEB-INF/views/jsp/student/list-success.jsp
11 |
12 |
13 |
14 | list.action
15 |
16 |
17 |
18 | list.action
19 |
20 |
21 |
22 | list.action
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/WebContent/WEB-INF/views/jsp/student/list-success.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=utf-8"
2 | pageEncoding="utf-8"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
4 | <%@taglib prefix="s" uri="/struts-tags" %>
5 |
6 |
7 |
8 |
9 | students
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | | ID | Name | Age |
21 |
22 | | ${s.id} | ${s.name} | ${s.age} |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/java/cn/amumu/spring/action/StudentAction.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.action;
2 |
3 | import java.util.List;
4 |
5 | import javax.annotation.Resource;
6 |
7 | import cn.amumu.spring.orm.Student;
8 | import cn.amumu.spring.service.StudentService;
9 |
10 | import com.opensymphony.xwork2.ActionSupport;
11 |
12 | public class StudentAction extends ActionSupport {
13 |
14 | private static final long serialVersionUID = 1654432868760393645L;
15 |
16 | @Resource
17 | private StudentService studentService;
18 |
19 | private List students;
20 | private Student student;
21 |
22 | @Override
23 | public String execute() throws Exception {
24 | students = studentService.findAll();
25 | return SUCCESS;
26 | }
27 |
28 | public String addStudent() throws Exception {
29 | studentService.saveStudent(student);
30 | return SUCCESS;
31 | }
32 |
33 | public String deleteStudent() throws Exception {
34 | studentService.delete(12L);
35 | return SUCCESS;
36 | }
37 |
38 | public String findStudent() throws Exception {
39 | studentService.getStudent(12L);
40 | return SUCCESS;
41 | }
42 |
43 | /*-------------get set method---------------------*/
44 | public List getStudents() {
45 | return students;
46 | }
47 |
48 | public void setStudent(Student student) {
49 | this.student = student;
50 | }
51 |
52 | public Student getStudent() {
53 | return student;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/cn/amumu/spring/service/StudentServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.amumu.spring.service;
2 |
3 | import java.util.List;
4 |
5 | import javax.annotation.Resource;
6 |
7 | import org.springframework.cache.annotation.CacheEvict;
8 | import org.springframework.cache.annotation.Cacheable;
9 | import org.springframework.cache.annotation.Caching;
10 | import org.springframework.stereotype.Service;
11 | import org.springframework.transaction.annotation.Transactional;
12 |
13 | import cn.amumu.spring.dao.StudentDao;
14 | import cn.amumu.spring.orm.Student;
15 |
16 | @Service
17 | public class StudentServiceImpl implements StudentService {
18 |
19 | @Resource
20 | private StudentDao studentDao;
21 |
22 | @Override
23 | @Cacheable(value = "student", key = "#studentId")
24 | public Student getStudent(long studentId) {
25 | return studentDao.findById(studentId);
26 | }
27 |
28 | @Override
29 | @Transactional
30 | @CacheEvict(value = "student", key = "'findAllStudent'")
31 | public void saveStudent(Student student) {
32 | studentDao.save(student);
33 | }
34 |
35 | @Override
36 | @Cacheable(value = "student", key = "'findAllStudent'")
37 | public List findAll() {
38 | return studentDao.findAll();
39 | }
40 |
41 | @Override
42 | @Caching(evict={@CacheEvict(value = "student", key = "'findAllStudent'"),@CacheEvict(value = "student", key = "#studentId")})
43 | public void delete(long studentId) {
44 | studentDao.delete(studentId);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/resources/spring/applicationContext-database.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/WebContent/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | spring
7 |
8 |
9 |
10 | webAppRootKey
11 | spring.root
12 |
13 |
14 |
15 |
16 | log4jConfigLocation
17 | classpath:log4j.properties
18 |
19 |
20 |
21 | log4jRefreshInterval
22 | 60000
23 |
24 |
25 |
26 | org.springframework.web.util.Log4jConfigListener
27 |
28 |
29 |
30 |
31 | contextConfigLocation
32 | classpath:spring/applicationContext.xml
33 |
34 |
35 |
36 | org.springframework.web.context.ContextLoaderListener
37 |
38 |
39 |
40 |
41 | struts2
42 | org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
43 |
44 | filterConfig
45 | /WEB-INF/classes/struts/struts.xml
46 |
47 |
48 |
49 |
50 | struts2
51 | *.action
52 |
53 |
54 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | spring
5 | spring
6 | 0.0.1-SNAPSHOT
7 | war
8 | spring
9 | my ssh
10 | https://github.com/cr2121/spring
11 |
12 |
13 | 2.3.15.1
14 | 3.2.2.RELEASE
15 | 1.7
16 |
17 |
18 |
19 | src
20 |
21 |
22 | maven-compiler-plugin
23 | 2.3.2
24 |
25 | ${java-version}
26 | ${java-version}
27 |
28 |
29 |
30 | maven-war-plugin
31 | 2.2
32 |
33 | WebContent
34 | false
35 |
36 |
37 |
38 |
39 |
40 |
41 | junit
42 | junit
43 | 4.11
44 | test
45 |
46 |
47 | org.slf4j
48 | slf4j-log4j12
49 | 1.7.2
50 |
51 |
52 | log4j
53 | log4j
54 | 1.2.17
55 |
56 |
57 | com.mchange
58 | c3p0
59 | 0.9.2.1
60 |
61 |
62 | mysql
63 | mysql-connector-java
64 | 5.1.25
65 |
66 |
67 | net.sf.ehcache
68 | ehcache-core
69 | 2.5.3
70 |
71 |
72 | org.springframework
73 | spring-context-support
74 | ${spring-version}
75 |
76 |
77 | org.springframework
78 | spring-web
79 | ${spring-version}
80 |
81 |
82 | org.springframework
83 | spring-jdbc
84 | ${spring-version}
85 |
86 |
87 | org.apache.struts
88 | struts2-spring-plugin
89 | ${struts-version}
90 |
91 |
92 | org.mybatis
93 | mybatis
94 | 3.1.1
95 |
96 |
97 | org.mybatis
98 | mybatis-spring
99 | 1.2.0
100 |
101 |
102 | jstl
103 | jstl
104 | 1.2
105 |
106 |
107 |
--------------------------------------------------------------------------------