├── .gitignore ├── .idea ├── artifacts │ ├── springmvc_mybatis_book_war.xml │ └── springmvc_mybatis_book_war_exploded.xml ├── checkstyle-idea.xml ├── compiler.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── libraries │ ├── Maven__com_alibaba_druid_1_1_9.xml │ ├── Maven__javax_servlet_javax_servlet_api_4_0_0.xml │ ├── Maven__jstl_jstl_1_2.xml │ ├── Maven__junit_junit_4_12.xml │ ├── Maven__org_aspectj_aspectjweaver_1_8_13.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__org_mybatis_mybatis_3_4_6.xml │ ├── Maven__org_mybatis_mybatis_spring_1_3_2.xml │ ├── Maven__org_springframework_spring_aop_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_aspects_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_context_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_context_support_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_core_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_jcl_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_test_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_5_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_web_5_0_4_RELEASE.xml │ └── Maven__org_springframework_spring_webmvc_5_0_4_RELEASE.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── doc ├── ay_role.sql ├── ay_school.sql ├── ay_student.sql ├── ay_user.sql ├── ay_user_address.sql ├── ay_user_role_rel.sql └── 彻底掌握SSM框架(实战篇).docx ├── pom.xml ├── springmvc-mybatis-book.iml └── src └── main ├── java └── com │ └── ay │ ├── controller │ ├── AyRoleController.java │ ├── AySchoolController.java │ ├── AyStudentController.java │ ├── AyTestController.java │ ├── AyUserAddressController.java │ ├── AyUserController.java │ ├── MoodController.java │ ├── SysUserController.java │ └── UserController.java │ ├── dao │ ├── AyRoleDao.java │ ├── AySchoolDao.java │ ├── AyStudentDao.java │ ├── AyUserAddressDao.java │ ├── AyUserDao.java │ ├── MoodDao.java │ ├── SysUserDao.java │ ├── UserDao.java │ └── UserMoodPraiseRelDao.java │ ├── dto │ ├── MoodDTO.java │ ├── SysUserDTO.java │ └── UserDTO.java │ ├── job │ └── PraiseDataSaveDBJob.java │ ├── model │ ├── AyRole.java │ ├── AySchool.java │ ├── AyStudent.java │ ├── AyUser.java │ ├── AyUserAddress.java │ ├── AyUserRoleRel.java │ ├── Mood.java │ ├── SysUser.java │ ├── User.java │ └── UserMoodPraiseRel.java │ ├── mq │ ├── MoodConsumer.java │ └── MoodProducer.java │ ├── proxy │ └── LogInterceptor.java │ ├── service │ ├── AyRoleService.java │ ├── AySchoolService.java │ ├── AyStudentService.java │ ├── AyUserAddressService.java │ ├── AyUserService.java │ ├── MoodService.java │ ├── SysUserService.java │ ├── UserMoodPraiseRelService.java │ ├── UserService.java │ └── impl │ │ ├── AyRoleServiceImpl.java │ │ ├── AySchoolServiceImpl.java │ │ ├── AyStudentServiceImpl.java │ │ ├── AyUserAddressServiceImpl.java │ │ ├── AyUserServiceImpl.java │ │ ├── MoodServiveImpl.java │ │ ├── SysUserServiceImpl.java │ │ ├── UserMoodPraiseRelServiceImpl.java │ │ └── UserServiceImpl.java │ └── validator │ └── AyUserValidator.java ├── resources ├── activemq.properties ├── applicationContext.xml ├── jdbc.properties ├── log4j.properties ├── mapper │ ├── AyRoleMapper.xml │ ├── AySchoolMapper.xml │ ├── AyStudentMapper.xml │ ├── AyUserAddressMapper.xml │ ├── AyUserMapper.xml │ ├── MoodMapper.xml │ ├── SysUserMapper.xml │ ├── UserMapper.xml │ └── UserMoodPraiseRelMapper.xml ├── mybatis-config.xml ├── redis.properties ├── spring-jms.xml ├── spring-mvc.xml └── spring-redis.xml ├── test └── com │ └── ay │ └── test │ ├── AyUserDaoTest.java │ ├── BaseJunit4Test.java │ ├── BusinessClassService.java │ ├── BusinessClassServiceImpl.java │ ├── MQTest.java │ ├── MoodDaoTest.java │ ├── MyLogger.java │ ├── MyLoggerHandler.java │ ├── MyLoggerImpl.java │ ├── MyLoggerTest.java │ ├── ProxyPattern.java │ ├── RedisTest.java │ ├── SpringTest.java │ └── UserDaoTest.java └── webapp ├── WEB-INF ├── views │ ├── error.jsp │ ├── hello.jsp │ ├── mood.jsp │ ├── saveUser.jsp │ ├── success.jsp │ ├── updateUser.jsp │ ├── user.jsp │ ├── userIn.jsp │ ├── userManage.jsp │ └── userOut.jsp └── web.xml └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* -------------------------------------------------------------------------------- /.idea/artifacts/springmvc_mybatis_book_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target 4 | 5 | 6 | springmvc-mybatis-book 7 | war 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/artifacts/springmvc_mybatis_book_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target/springmvc-mybatis-book 4 | 5 | 6 | true 7 | springmvc-mybatis-book 8 | war 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_druid_1_1_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_servlet_javax_servlet_api_4_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__jstl_jstl_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mybatis_mybatis_3_4_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aspects_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_support_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jcl_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 32 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /doc/ay_role.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 18:11:32 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_role 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_role`; 22 | CREATE TABLE `ay_role` ( 23 | `id` bigint(32) NOT NULL, 24 | `name` varchar(255) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 27 | -------------------------------------------------------------------------------- /doc/ay_school.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 15:17:02 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_school 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_school`; 22 | CREATE TABLE `ay_school` ( 23 | `id` bigint(32) NOT NULL, 24 | `name` varchar(255) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 27 | -------------------------------------------------------------------------------- /doc/ay_student.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 15:16:53 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_student 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_student`; 22 | CREATE TABLE `ay_student` ( 23 | `id` bigint(32) NOT NULL, 24 | `name` varchar(255) DEFAULT NULL, 25 | `age` int(2) DEFAULT NULL, 26 | `school_id` bigint(32) DEFAULT NULL, 27 | PRIMARY KEY (`id`) 28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 29 | -------------------------------------------------------------------------------- /doc/ay_user.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 18:11:23 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_user 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_user`; 22 | CREATE TABLE `ay_user` ( 23 | `id` bigint(32) NOT NULL AUTO_INCREMENT, 24 | `name` varchar(10) DEFAULT NULL, 25 | `password` varchar(64) DEFAULT NULL, 26 | `age` int(10) DEFAULT NULL, 27 | `address_id` bigint(32) DEFAULT NULL, 28 | PRIMARY KEY (`id`), 29 | KEY `FK_address_id` (`address_id`), 30 | CONSTRAINT `FK_address_id` FOREIGN KEY (`address_id`) REFERENCES `ay_user_address` (`id`) 31 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 32 | -------------------------------------------------------------------------------- /doc/ay_user_address.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 13:25:25 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_user_address 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_user_address`; 22 | CREATE TABLE `ay_user_address` ( 23 | `id` bigint(32) NOT NULL, 24 | `name` varchar(255) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 27 | -------------------------------------------------------------------------------- /doc/ay_user_role_rel.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50717 6 | Source Host : localhost:3306 7 | Source Database : springmvc-mybatis-book 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50717 11 | File Encoding : 65001 12 | 13 | Date: 2018-05-01 18:11:51 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ay_user_role_rel 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ay_user_role_rel`; 22 | CREATE TABLE `ay_user_role_rel` ( 23 | `id` bigint(32) NOT NULL, 24 | `user_id` bigint(32) DEFAULT NULL, 25 | `role_id` bigint(32) DEFAULT NULL, 26 | PRIMARY KEY (`id`) 27 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 28 | -------------------------------------------------------------------------------- /doc/彻底掌握SSM框架(实战篇).docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenyi10/springmvc-mybatis-book/e672f2605a32dfce0b8e83d66c7bb2def2b46a47/doc/彻底掌握SSM框架(实战篇).docx -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.ay 5 | springmvc-mybatis-book 6 | war 7 | 1.0-SNAPSHOT 8 | springmvc-mybatis-book Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | 5.0.4.RELEASE 13 | 4.0.0 14 | 1.2 15 | 3.4.6 16 | 8.0.9-rc 17 | 1.1.9 18 | 1.3.2 19 | 20 | 1.7.25 21 | 1.2.17 22 | 23 | 1.6.0.RELEASE 24 | 2.7.2 25 | 2.4.2 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.springframework 33 | spring-core 34 | ${spring.version} 35 | 36 | 37 | 38 | org.springframework 39 | spring-beans 40 | ${spring.version} 41 | 42 | 43 | 44 | org.springframework 45 | spring-context 46 | ${spring.version} 47 | 48 | 49 | 50 | org.springframework 51 | spring-context-support 52 | ${spring.version} 53 | 54 | 55 | 56 | org.springframework 57 | spring-aop 58 | ${spring.version} 59 | 60 | 61 | 62 | org.springframework 63 | spring-aspects 64 | ${spring.version} 65 | 66 | 67 | 68 | org.springframework 69 | spring-expression 70 | ${spring.version} 71 | 72 | 73 | 74 | org.springframework 75 | spring-tx 76 | ${spring.version} 77 | 78 | 79 | 80 | org.springframework 81 | spring-test 82 | ${spring.version} 83 | 84 | 85 | 86 | org.springframework 87 | spring-web 88 | ${spring.version} 89 | 90 | 91 | 92 | 93 | 94 | jstl 95 | jstl 96 | ${jstl.version} 97 | 98 | 99 | javax.servlet 100 | javax.servlet-api 101 | ${javax.servlet.version} 102 | 103 | 104 | org.springframework 105 | spring-webmvc 106 | ${spring.version} 107 | 108 | 109 | 110 | 111 | 112 | mysql 113 | mysql-connector-java 114 | ${mysql.connector.java.version} 115 | runtime 116 | 117 | 118 | 119 | com.alibaba 120 | druid 121 | ${druid.version} 122 | 123 | 124 | 125 | org.springframework 126 | spring-jdbc 127 | ${spring.version} 128 | 129 | 130 | 131 | org.mybatis 132 | mybatis 133 | ${mybatis.version} 134 | 135 | 136 | 137 | org.mybatis 138 | mybatis-spring 139 | ${mybatis.spring.version} 140 | 141 | 142 | 143 | 144 | 145 | junit 146 | junit 147 | 4.12 148 | 149 | 150 | 151 | 152 | log4j 153 | log4j 154 | ${log4j.version} 155 | 156 | 157 | org.slf4j 158 | slf4j-api 159 | ${slf4j.version} 160 | 161 | 162 | org.slf4j 163 | slf4j-log4j12 164 | ${slf4j.version} 165 | 166 | 167 | 168 | com.github.pagehelper 169 | pagehelper 170 | 5.1.4 171 | 172 | 173 | 174 | com.fasterxml.jackson.core 175 | jackson-core 176 | 2.9.5 177 | 178 | 179 | com.fasterxml.jackson.core 180 | jackson-annotations 181 | 2.9.5 182 | 183 | 184 | com.fasterxml.jackson.core 185 | jackson-databind 186 | 2.9.5 187 | 188 | 189 | 190 | org.hibernate.validator 191 | hibernate-validator 192 | 6.0.10.Final 193 | 194 | 195 | 196 | 197 | org.springframework.data 198 | spring-data-redis 199 | ${spring.redis.version} 200 | 201 | 202 | 203 | org.apache.commons 204 | commons-pool2 205 | ${commons.version} 206 | 207 | 208 | 209 | redis.clients 210 | jedis 211 | ${jedis.version} 212 | 213 | 214 | 215 | 216 | org.springframework 217 | spring-jms 218 | ${spring.version} 219 | 220 | 221 | 222 | org.apache.activemq 223 | activemq-all 224 | 5.11.2 225 | 226 | 227 | spring-context 228 | org.springframework 229 | 230 | 231 | org.apache.geronimo.specs 232 | geronimo-jms_1.1_spec 233 | 234 | 235 | 236 | 237 | 238 | javax.jms 239 | javax.jms-api 240 | 2.0.1 241 | 242 | 243 | 244 | 245 | 246 | 247 | springmvc-mybatis-book 248 | 249 | 250 | -------------------------------------------------------------------------------- /springmvc-mybatis-book.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AyRoleController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.model.AyRole; 4 | import com.ay.model.AyUser; 5 | import com.ay.service.AyRoleService; 6 | import com.ay.service.AyUserService; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * @author Ay 16 | * @date 2018/04/02 17 | */ 18 | @Controller 19 | @RequestMapping(value = "/role") 20 | public class AyRoleController { 21 | 22 | @Resource 23 | private AyRoleService ayRoleService; 24 | 25 | @GetMapping("/findById") 26 | public String findById(Model model) { 27 | AyRole ayRole = ayRoleService.findById("1"); 28 | return "success"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AySchoolController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.model.AySchool; 4 | import com.ay.model.AyUserAddress; 5 | import com.ay.service.AySchoolService; 6 | import com.ay.service.AyUserAddressService; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * 描述:地址控制层 16 | * 17 | * @author Ay 18 | * @create 2018/05/01 19 | **/ 20 | @Controller 21 | @RequestMapping(value = "/school") 22 | public class AySchoolController { 23 | 24 | @Resource 25 | private AySchoolService aySchoolService; 26 | 27 | @GetMapping("/findById") 28 | public String findById(Model model) { 29 | AySchool aySchool = aySchoolService.findById(1); 30 | return "success"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AyStudentController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.model.AyStudent; 4 | import com.ay.model.AyUserAddress; 5 | import com.ay.service.AyStudentService; 6 | import com.ay.service.AyUserAddressService; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * 描述:地址控制层 16 | * 17 | * @author Ay 18 | * @create 2018/05/01 19 | **/ 20 | @Controller 21 | @RequestMapping(value = "/student") 22 | public class AyStudentController { 23 | 24 | @Resource 25 | private AyStudentService ayStudentService; 26 | 27 | @GetMapping("/findById") 28 | public String findById(Model model) { 29 | AyStudent ayStudent = ayStudentService.findById(1); 30 | return "success"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AyTestController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author Ay 11 | * @date 2018/04/02 12 | */ 13 | @Controller 14 | @RequestMapping(value = "/test") 15 | public class AyTestController { 16 | 17 | @GetMapping("/sayHello") 18 | public String sayHello(Model model) { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AyUserAddressController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.model.AyUser; 4 | import com.ay.model.AyUserAddress; 5 | import com.ay.service.AyUserAddressService; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * 描述:地址控制层 15 | * 16 | * @author Ay 17 | * @create 2018/05/01 18 | **/ 19 | @Controller 20 | @RequestMapping(value = "/address") 21 | public class AyUserAddressController { 22 | 23 | @Resource 24 | private AyUserAddressService ayUserAddressService; 25 | 26 | @GetMapping("/findById") 27 | public String findById(Model model) { 28 | AyUserAddress ayUserAddress = ayUserAddressService.findById(1); 29 | return "success"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/AyUserController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.model.AyUser; 4 | import com.ay.service.AyUserService; 5 | import com.ay.validator.AyUserValidator; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.validation.Errors; 10 | import org.springframework.validation.ObjectError; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.annotation.Resource; 14 | import javax.validation.Valid; 15 | import java.util.List; 16 | 17 | /** 18 | * 用户控制层 19 | * 20 | * @author Ay 21 | * @date 2018/04/02 22 | */ 23 | @Controller 24 | @RequestMapping("/user") 25 | public class AyUserController { 26 | 27 | @RequestMapping("/save") 28 | public String save() { 29 | return "saveUser"; 30 | } 31 | 32 | @PostMapping("/insert") 33 | public String insert(@Valid @ModelAttribute AyUser ayUser, BindingResult result) { 34 | if (result.hasErrors()) { 35 | return "error"; 36 | } 37 | int count = ayUserService.insert(ayUser); 38 | return "success"; 39 | } 40 | 41 | 42 | // @Resource 43 | // private AyUserValidator ayUserValidator; 44 | 45 | // @RequestMapping("/save") 46 | // public String save(){ 47 | // return "saveUser"; 48 | // } 49 | 50 | // @PostMapping("/insert") 51 | // public String insert(@ModelAttribute AyUser ayUser,Model model, Errors errors){ 52 | // ayUserValidator.validate(ayUser, errors); 53 | // if(errors.hasErrors()){ 54 | // model.addAttribute("errors", errors); 55 | // return "error"; 56 | // } 57 | // int count = ayUserService.insert(ayUser); 58 | // return "hello"; 59 | // } 60 | 61 | // @RequestMapping("/hello") 62 | // @ResponseBody 63 | // public void hello(@RequestBody AyUser ayUser){ 64 | // System.out.println("name" + ayUser.getName()); 65 | // System.out.println("password" + ayUser.getPassword()); 66 | // } 67 | 68 | 69 | // @RequestMapping("/hello") 70 | // @ResponseBody 71 | // public Map hello(){ 72 | // Map map = new HashMap(); 73 | // map.put("name", "ay"); 74 | // map.put("age", "3"); 75 | // return map; 76 | // } 77 | 78 | // @RequestMapping("/hello") 79 | // @ResponseBody 80 | // public List hello(){ 81 | // List list = new ArrayList(); 82 | // list.add("ay"); 83 | // list.add("al"); 84 | // return list; 85 | // } 86 | 87 | // @RequestMapping("/hello") 88 | // @ResponseBody 89 | // public String hello(){ 90 | // return "I am not view"; 91 | // } 92 | 93 | // @RequestMapping("hello") 94 | // public ModelAndView hello(HttpMethod method){ 95 | // ModelAndView mv = new ModelAndView(); 96 | // mv.addObject("name","ay"); 97 | // mv.setViewName("hello"); 98 | // return mv; 99 | // } 100 | 101 | 102 | // @RequestMapping("hello") 103 | // public ModelAndView hello(HttpServletRequest request){ 104 | // ModelAndView mv = new ModelAndView(); 105 | // mv.addObject("name","ay"); 106 | // mv.setViewName("hello"); 107 | // return mv; 108 | // } 109 | 110 | // @RequestMapping("hello") 111 | // public String hello(Model model){ 112 | // model.addAttribute("name", "ay"); 113 | // return "hello"; 114 | // } 115 | 116 | // @ModelAttribute 117 | // public void redirectTest(Model model){ 118 | // model.addAttribute("name","ay"); 119 | // } 120 | // 121 | // @RequestMapping("hello") 122 | // public String hello(Model model, ModelMap modelMap, Map map){ 123 | // return "hello"; 124 | // } 125 | 126 | // @RequestMapping("redirect") 127 | // public String redirectTest(Model model,SessionStatus sessionStatus){ 128 | // AyUser ayUser = new AyUser(); 129 | // ayUser.setName("ay"); 130 | // model.addAttribute("ayUser",ayUser); 131 | // sessionStatus.setComplete(); 132 | // return "redirect:hello"; 133 | // } 134 | // 135 | // @RequestMapping("hello") 136 | // public String hello(@SessionAttribute AyUser ayUser){ 137 | // System.out.println(ayUser.getName()); 138 | // return "hello"; 139 | // } 140 | 141 | // @RequestMapping("hello") 142 | // public String hello(ModelMap modelMap){ 143 | // AyUser ayUser = (AyUser) modelMap.get("ayUser"); 144 | // System.out.println(ayUser.getName()); 145 | // return "hello"; 146 | // } 147 | 148 | // @ModelAttribute("ayUser") 149 | // public AyUser init(@RequestParam("id") Integer id, 150 | // @RequestParam("name") String name){ 151 | // AyUser ayUser = new AyUser(); 152 | // ayUser.setId(id); 153 | // ayUser.setName(name); 154 | // return ayUser; 155 | // } 156 | // 157 | // @RequestMapping(value="hello") 158 | // public String hello(@ModelAttribute("ayUser") AyUser ayUser){ 159 | // 160 | // return "hello"; 161 | // } 162 | 163 | // @ModelAttribute("name") 164 | // @RequestMapping(value = "/hello") 165 | // public String hello(){ 166 | // return "ay"; 167 | // } 168 | 169 | // @ModelAttribute("name") 170 | // public String init(@RequestParam(value = "name", required = false) String name){ 171 | // return name; 172 | // } 173 | // 174 | // @GetMapping("/hello") 175 | // public String hello(){ 176 | // return "hello"; 177 | // } 178 | 179 | // @ModelAttribute() 180 | // public void init(Model model){ 181 | // AyUser ayUser = new AyUser(); 182 | // ayUser.setId(1); 183 | // ayUser.setName("ay"); 184 | // model.addAttribute("user", ayUser); 185 | // } 186 | // 187 | // @GetMapping("/hello") 188 | // public String hello(){ 189 | // return "hello"; 190 | // } 191 | 192 | // @ModelAttribute 193 | // public void init(){ 194 | // System.out.println("init ..."); 195 | // } 196 | // 197 | // @ModelAttribute 198 | // public void init02(){ 199 | // System.out.println("init 02 ..."); 200 | // } 201 | // 202 | // @GetMapping("/findById/{id}") 203 | // public String findById(@PathVariable String id) { 204 | // // ... 205 | // return ""; 206 | // } 207 | // 208 | // @ModelAttribute 209 | // public void init03(){ 210 | // System.out.println("init 03 ..."); 211 | // } 212 | 213 | // @GetMapping("/findById/{id}") 214 | // public String findById(@PathVariable String id) { 215 | // // ... 216 | // return ""; 217 | // } 218 | 219 | // @PostMapping(path = "/add") 220 | // public String add(@RequestBody AyUser ayUser) { 221 | // // ... 222 | // return ""; 223 | // } 224 | 225 | 226 | // @RequestMapping("/cookieValue") 227 | // public String handle(@CookieValue("JSESSIONID") String cookie) { 228 | // //... 229 | // return ""; 230 | // } 231 | 232 | // @RequestMapping("/requestHeader") 233 | // public String handle( 234 | // @RequestHeader("Accept-Encoding") String[] encoding, 235 | // @RequestHeader("Accept") String[] accept) { 236 | // //... 237 | // return ""; 238 | // } 239 | 240 | // @RequestMapping("/pets/{petId}") 241 | // public String findPet(@PathVariable Long ownerId, @PathVariable Long petId) { 242 | // // ... 243 | // return ""; 244 | // } 245 | 246 | 247 | // @RequestMapping("/findByNameAndPassword") 248 | // public String findByNameAndPassword( 249 | // @RequestParam(value="name") String name, 250 | // @RequestParam(value="password",required = false,defaultValue = "123") String password){ 251 | // System.out.println("name=" + name); 252 | // System.out.println("password" + password); 253 | // return "success"; 254 | // } 255 | 256 | @Resource 257 | private AyUserService ayUserService; 258 | 259 | // @RequestMapping("findById") 260 | // public String findById(@RequestParam(value="id") String id){ 261 | // AyUser ayUser = ayUserService.findById(id); 262 | // return "success"; 263 | // } 264 | 265 | // @RequestMapping(value = "/fetch", params = { 266 | // "personId=10" 267 | // }) 268 | // public String getParams(@RequestParam("personId") String id) { 269 | // return "Fetched parameter using params attribute = " + id; 270 | // } 271 | // @RequestMapping(value = "/fetch", params = { 272 | // "personId=20" 273 | // }) 274 | // public String getParamsDifferent(@RequestParam("personId") String id) { 275 | // return "Fetched parameter using params attribute = " + id; 276 | // } 277 | 278 | // @RequestMapping(value = "/head", headers = { 279 | // "content-type=text/plain", 280 | // "content-type=text/html" 281 | // }) String post() { 282 | // return "Mapping applied along with headers"; 283 | // } 284 | 285 | // @RequestMapping(value = "/head", headers = { 286 | // "content-type=text/plain" 287 | // }) 288 | // String post() { 289 | // return "Mapping applied along with headers"; 290 | // } 291 | 292 | 293 | // @RequestMapping(value = "/produces", produces = { 294 | // "application/JSON" 295 | // }) 296 | // @ResponseBody 297 | // String getProduces() { 298 | // return "Produces attribute"; 299 | // } 300 | // 301 | // @RequestMapping(value = "/consumes", consumes = { 302 | // "application/JSON", 303 | // "application/XML" 304 | // }) 305 | // String getConsumes() { 306 | // return "Consumes attribute"; 307 | // } 308 | 309 | // @RequestMapping(method = RequestMethod.GET) 310 | // String get() { 311 | // return "Hello from get"; 312 | // } 313 | // @RequestMapping(method = RequestMethod.DELETE) 314 | // String delete() { 315 | // return "Hello from delete"; 316 | // } 317 | // @RequestMapping(method = RequestMethod.POST) 318 | // String post() { 319 | // return "Hello from post"; 320 | // } 321 | // @RequestMapping(method = RequestMethod.PUT) 322 | // String put() { 323 | // return "Hello from put"; 324 | // } 325 | // @RequestMapping(method = RequestMethod.PATCH) 326 | // String patch() { 327 | // return "Hello from patch"; 328 | // } 329 | // 330 | // @RequestMapping(value = { 331 | // "", 332 | // "/page", 333 | // "page*", 334 | // "view/*,**/msg" 335 | // }) 336 | // public String hello(Model model){ 337 | // model.addAttribute("message", "hello ay"); 338 | // return "hello"; 339 | // } 340 | // @RequestMapping("/hello") 341 | // public String hello(Model model){ 342 | // model.addAttribute("message", "hello ay"); 343 | // return "hello"; 344 | // } 345 | 346 | 347 | // @GetMapping("/findById") 348 | // public String findById(Model model){ 349 | // AyUser ayUser = ayUserService.findById("1"); 350 | // return "success"; 351 | // } 352 | // 353 | // @GetMapping("/findAll") 354 | // public String findAll(Model model){ 355 | // List ayUserList = ayUserService.findAll(); 356 | // for(AyUser ayUser : ayUserList){ 357 | // System.out.println("id: " + ayUser.getId()); 358 | // System.out.println("name: " + ayUser.getName()); 359 | // } 360 | // return "hello"; 361 | // } 362 | // 363 | // @GetMapping("/findById") 364 | // public String findById(Model model){ 365 | // AyUser ayUser = ayUserService.findById("1"); 366 | // return "success"; 367 | // } 368 | // 369 | // @GetMapping("/findByName") 370 | // public String findByName(Model model){ 371 | // List ayUsers = ayUserService.findByName("阿毅"); 372 | // return "success"; 373 | // } 374 | // 375 | // @GetMapping("/countByName") 376 | // public String countByName(Model model){ 377 | // int count = ayUserService.countByName("阿毅"); 378 | // return "success"; 379 | // } 380 | 381 | // @GetMapping("/insert") 382 | // public String insert(Model model){ 383 | // AyUser ayUser = new AyUser(); 384 | // ayUser.setId(3); 385 | // ayUser.setName("ay"); 386 | // ayUser.setPassword("123"); 387 | // int count = ayUserService.insert(ayUser); 388 | // return "success"; 389 | // } 390 | 391 | // @GetMapping("/insert") 392 | //// public String insert(Model model){ 393 | //// AyUser ayUser = new AyUser(); 394 | //// //ayUser.setId(3); 395 | //// ayUser.setName("ay"); 396 | //// ayUser.setPassword("123"); 397 | //// int count = ayUserService.insert(ayUser); 398 | //// return "success"; 399 | //// } 400 | //// 401 | @GetMapping("/update") 402 | public String update(Model model) { 403 | AyUser ayUser = new AyUser(); 404 | ayUser.setId(1); 405 | ayUser.setName("aaaa"); 406 | ayUser.setPassword("123"); 407 | int count = ayUserService.update(ayUser); 408 | return "success"; 409 | } 410 | //// 411 | //// @GetMapping("/delete") 412 | //// public String delete(Model model){ 413 | //// int count = ayUserService.delete(4); 414 | //// return "success"; 415 | //// } 416 | //// 417 | //// @GetMapping("/deleteByName") 418 | //// public String deleteByName(Model model){ 419 | //// int count = ayUserService.deleteByName("al"); 420 | //// return "success"; 421 | //// } 422 | //// 423 | //// @GetMapping("/findByNameAndPassword") 424 | //// public String findByNameAndPassword(Model model){ 425 | //// //List ayUsers = ayUserService.findByNameAndPassword("ay","123"); 426 | //// List ayUsers = ayUserService.findByNameAndPassword("al","123"); 427 | //// return "success"; 428 | //// } 429 | 430 | // @GetMapping("/findByNameAndPassword") 431 | // public String findByNameAndPassword(Model model){ 432 | // //List ayUsers = ayUserService.findByNameAndPassword("ay","123"); 433 | // Map map = new HashMap(); 434 | // map.put("name","al"); 435 | // map.put("password","123"); 436 | // List ayUsers = ayUserService.findByNameAndPassword(map); 437 | // return "success"; 438 | // } 439 | 440 | // @GetMapping("/findByIds") 441 | // public String findByIds(Model model){ 442 | // List ids = new ArrayList(); 443 | // ids.add(1); 444 | // ids.add(2); 445 | // List ayUsers = ayUserService.findByIds(ids); 446 | // return "success"; 447 | // } 448 | } 449 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/MoodController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.dto.MoodDTO; 4 | import com.ay.service.MoodService; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | import java.util.Random; 12 | 13 | /** 14 | * 描述:说说控制层 15 | * 16 | * @author Ay 17 | * @date 2018/1/6. 18 | */ 19 | @Controller 20 | @RequestMapping("/mood") 21 | public class MoodController { 22 | 23 | @Resource 24 | private MoodService moodService; 25 | 26 | @GetMapping(value = "/findAll") 27 | public String findAll(Model model) { 28 | List moodDTOList = moodService.findAll(); 29 | model.addAttribute("moods", moodDTOList); 30 | return "mood"; 31 | } 32 | 33 | @GetMapping(value = "/{moodId}/praise") 34 | public String praise(Model model, @PathVariable(value = "moodId") String moodId, 35 | @RequestParam(value = "userId") String userId) { 36 | boolean isPraise = moodService.praiseMood(userId, moodId); 37 | 38 | List moodDTOList = moodService.findAll(); 39 | model.addAttribute("moods", moodDTOList); 40 | model.addAttribute("isPraise", isPraise); 41 | return "mood"; 42 | } 43 | 44 | @GetMapping(value = "/{moodId}/praiseForRedis") 45 | public String praiseForRedis(Model model, @PathVariable(value = "moodId") String moodId, 46 | @RequestParam(value = "userId") String userId) { 47 | //方便使用,随机生成用户id 48 | Random random = new Random(); 49 | userId = random.nextInt(100) + ""; 50 | 51 | boolean isPraise = moodService.praiseMoodForRedis(userId, moodId); 52 | //查询所有的说说数据 53 | List moodDTOList = moodService.findAllForRedis(); 54 | model.addAttribute("moods", moodDTOList); 55 | model.addAttribute("isPraise", isPraise); 56 | return "mood"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/SysUserController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | import com.ay.dto.SysUserDTO; 3 | import com.ay.model.SysUser; 4 | import com.ay.service.SysUserService; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.util.CollectionUtils; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | /** 16 | * 用户控制层 17 | * Created by Ay on 2020/3/22. 18 | */ 19 | @Controller 20 | @RequestMapping("/sysUser") 21 | public class SysUserController { 22 | 23 | @Resource 24 | private SysUserService sysUserService; 25 | 26 | @GetMapping("/findAll") 27 | public String findAll(Model model){ 28 | List users = sysUserService.findAll(); 29 | model.addAttribute("users", convertToList(users)); 30 | return "userManage"; 31 | } 32 | 33 | @GetMapping("/in") 34 | public String userIn(Model model){ 35 | return "userIn"; 36 | } 37 | @GetMapping("/out") 38 | public String userOut(@RequestParam("id") String id, Model model){ 39 | SysUser user = sysUserService.findById(Integer.valueOf(id)); 40 | model.addAttribute("user", convertToDTO(user)); 41 | return "userOut"; 42 | } 43 | 44 | @GetMapping("/updateInfo") 45 | public String updateInfo(@RequestParam("id") String id, Model model){ 46 | SysUser user = sysUserService.findById(Integer.valueOf(id)); 47 | model.addAttribute("user", convertToDTO(user)); 48 | return "updateUser"; 49 | } 50 | 51 | @PostMapping(value = "/save") 52 | public String save(@RequestBody SysUserDTO user){ 53 | sysUserService.save(user); 54 | return "userManage"; 55 | } 56 | 57 | @PostMapping(value = "/update") 58 | public String update(@RequestBody SysUserDTO user){ 59 | sysUserService.update(user); 60 | return "userManage"; 61 | } 62 | 63 | @PostMapping(value = "/updateStatus") 64 | public String updateStatus(@RequestBody SysUserDTO user){ 65 | sysUserService.updateStatus(user); 66 | return "userManage"; 67 | } 68 | 69 | private List convertToList(List users){ 70 | if(CollectionUtils.isEmpty(users)){ 71 | return Collections.EMPTY_LIST; 72 | } 73 | List userList = new ArrayList(); 74 | for(SysUser user: users){ 75 | userList.add(convertToDTO(user)); 76 | } 77 | return userList; 78 | } 79 | 80 | private SysUserDTO convertToDTO(SysUser user){ 81 | SysUserDTO userDTO = new SysUserDTO(); 82 | userDTO.setId(String.valueOf(user.getId())); 83 | userDTO.setName(user.getName()); 84 | userDTO.setNo(user.getNo()); 85 | userDTO.setPosition(user.getPosition()); 86 | if("1".equals(user.getStatus())){ 87 | userDTO.setStatus("在职"); 88 | } 89 | if("2".equals(user.getStatus())){ 90 | userDTO.setStatus("已离职"); 91 | } 92 | userDTO.setReason(user.getReason()); 93 | return userDTO; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/ay/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.ay.controller; 2 | 3 | import com.ay.service.UserService; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * 描述:用户控制层 11 | * 12 | * @author Ay 13 | * @date 2018/6/6. 14 | */ 15 | @RestController 16 | @RequestMapping("/user") 17 | public class UserController { 18 | @Resource 19 | private UserService userService; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/AyRoleDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.AyRole; 4 | import com.ay.model.AyUser; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface AyRoleDao { 9 | 10 | AyRole findById(String id); 11 | // @Select("SELECT * FROM ay_user") 12 | // List findAll(); 13 | // @Select("SELECT * FROM ay_user") 14 | // @Results({ 15 | // @Result(id = true,column = "id",property = "id"), 16 | // @Result(column = "name",property = "name"), 17 | // @Result(column = "password",property = "password") 18 | // }) 19 | // List findAll(); 20 | 21 | // @Select("SELECT * FROM ay_user WHERE id = #{id}") 22 | //AyRole findById(String id); 23 | // 24 | // @Select("SELECT * FROM ay_user WHERE name = #{name}") 25 | // List findByName(String name); 26 | // 27 | // int countByName(String name); 28 | // 29 | // @Insert("INSERT INTO ay_user(name,password) VALUES(#{name}, #{password})") 30 | // @Options(useGeneratedKeys = true, keyProperty = "id") 31 | // int insert(AyUser ayUser); 32 | // 33 | // @Update("UPDATE ay_user SET name = #{name}, password = #{password} WHERE id = #{id}") 34 | // int update(AyUser ayUser); 35 | // 36 | // @Delete("DELETE FROM ay_user WHERE id = #{id}") 37 | // int delete(int id); 38 | // 39 | // @Delete("DELETE FROM ay_user WHERE name = #{name}") 40 | // int deleteByName(String name); 41 | 42 | // @Select("SELECT * FROM ay_user WHERE name = #{name} and password = #{password}") 43 | // List findByNameAndPassword(@Param("name") String name,@Param("password")String password); 44 | 45 | // List findByNameAndPassword(String name,String password); 46 | 47 | // List findByNameAndPassword(Map map); 48 | 49 | // List findByIds(@Param("list") List list); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/AySchoolDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.AySchool; 4 | 5 | /** 6 | * 描述:学校DAO接口 7 | * 8 | * @author Ay 9 | * @create 2018/05/01 10 | **/ 11 | public interface AySchoolDao { 12 | 13 | AySchool findById(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/AyStudentDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | 4 | import com.ay.model.AyStudent; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 描述:学生DAO接口 10 | * 11 | * @author Ay 12 | * @create 2018/05/01 13 | **/ 14 | public interface AyStudentDao { 15 | 16 | AyStudent findById(Integer id); 17 | 18 | List findBySchoolId(Integer id); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/AyUserAddressDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.AyUser; 4 | import com.ay.model.AyUserAddress; 5 | import org.apache.ibatis.annotations.*; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Repository 11 | public interface AyUserAddressDao { 12 | 13 | AyUserAddress findById(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/AyUserDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.AyUser; 4 | import org.apache.ibatis.annotations.*; 5 | import org.apache.ibatis.session.RowBounds; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | @Repository 12 | public interface AyUserDao { 13 | 14 | @Insert("INSERT INTO ay_user(name,password,age) VALUES(#{name}, #{password}, #{age})") 15 | @Options(useGeneratedKeys = true, keyProperty = "id") 16 | int insert(AyUser ayUser); 17 | 18 | AyUser findById(String id); 19 | 20 | // @Select("SELECT * FROM ay_user") 21 | // List findAll(); 22 | // @Select("SELECT * FROM ay_user") 23 | // @Results({ 24 | // @Result(id = true,column = "id",property = "id"), 25 | // @Result(column = "name",property = "name"), 26 | // @Result(column = "password",property = "password") 27 | // }) 28 | List findAll(); 29 | 30 | // @Select("SELECT * FROM ay_user WHERE id = #{id}") 31 | // 32 | 33 | // @Select("SELECT * FROM ay_user WHERE name = #{name}") 34 | // List findByName(String name); 35 | // 36 | // int countByName(String name); 37 | // 38 | // @Insert("INSERT INTO ay_user(name,password) VALUES(#{name}, #{password})") 39 | // @Options(useGeneratedKeys = true, keyProperty = "id") 40 | // int insert(AyUser ayUser); 41 | // 42 | @Update("UPDATE ay_user SET name = #{name}, password = #{password} WHERE id = #{id}") 43 | int update(AyUser ayUser); 44 | // 45 | // @Delete("DELETE FROM ay_user WHERE id = #{id}") 46 | // int delete(int id); 47 | // 48 | // @Delete("DELETE FROM ay_user WHERE name = #{name}") 49 | // int deleteByName(String name); 50 | 51 | // @Select("SELECT * FROM ay_user WHERE name = #{name} and password = #{password}") 52 | // List findByNameAndPassword(@Param("name") String name,@Param("password")String password); 53 | 54 | // List findByNameAndPassword(String name,String password); 55 | 56 | // List findByNameAndPassword(Map map); 57 | 58 | // List findByIds(@Param("list") List list); 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/MoodDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.Mood; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Ay 11 | * @create 2018/06/30 12 | **/ 13 | @Repository 14 | public interface MoodDao { 15 | 16 | List findAll(); 17 | 18 | boolean update(@Param("mood") Mood mood); 19 | 20 | Mood findById(String id); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/SysUserDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.SysUser; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Dao层 11 | * Created by Ay on 2020/3/22. 12 | */ 13 | @Repository 14 | public interface SysUserDao { 15 | /** 16 | * 查询所有用户 17 | * 18 | * @return 19 | */ 20 | List findAll(); 21 | 22 | void save(SysUser user); 23 | 24 | SysUser findById(Integer id); 25 | 26 | void update(@Param("user") SysUser user); 27 | 28 | void updateStatus(@Param("user") SysUser user); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.User; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 描述:用户Dao 10 | * 11 | * @author Ay 12 | * @create 2018/06/30 13 | **/ 14 | @Repository 15 | public interface UserDao { 16 | 17 | User find(String id); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dao/UserMoodPraiseRelDao.java: -------------------------------------------------------------------------------- 1 | package com.ay.dao; 2 | 3 | import com.ay.model.UserMoodPraiseRel; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * 描述:用户说说点赞关联DAO 9 | * 10 | * @author Ay 11 | * @create 2018/07/01 12 | **/ 13 | @Repository 14 | public interface UserMoodPraiseRelDao { 15 | 16 | boolean save(@Param("userMoodPraiseRel") UserMoodPraiseRel userMoodPraiseRel); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dto/MoodDTO.java: -------------------------------------------------------------------------------- 1 | package com.ay.dto; 2 | 3 | import com.ay.model.Mood; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 描述:说说DTO 9 | * 10 | * @author Ay 11 | * @date 2018/1/6. 12 | */ 13 | public class MoodDTO extends Mood implements Serializable { 14 | /** 15 | * 用户名称 16 | */ 17 | private String userName; 18 | 19 | /** 20 | * 用户的账号 21 | */ 22 | private String userAccount; 23 | 24 | public String getUserName() { 25 | return userName; 26 | } 27 | 28 | public void setUserName(String userName) { 29 | this.userName = userName; 30 | } 31 | 32 | public String getUserAccount() { 33 | return userAccount; 34 | } 35 | 36 | public void setUserAccount(String userAccount) { 37 | this.userAccount = userAccount; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dto/SysUserDTO.java: -------------------------------------------------------------------------------- 1 | package com.ay.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 用户DTO 7 | * Created by Ay on 2020/3/22. 8 | */ 9 | public class SysUserDTO implements Serializable { 10 | 11 | //主键 12 | private String id; 13 | //用户名 14 | private String name; 15 | //工号 16 | private String no; 17 | //职位 18 | private String position; 19 | //离职原因 20 | private String reason; 21 | 22 | //状态,0:删除 1:在职 2:离职 23 | private String status; 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getNo() { 42 | return no; 43 | } 44 | 45 | public void setNo(String no) { 46 | this.no = no; 47 | } 48 | 49 | public String getPosition() { 50 | return position; 51 | } 52 | 53 | public void setPosition(String position) { 54 | this.position = position; 55 | } 56 | 57 | public String getStatus() { 58 | return status; 59 | } 60 | 61 | public void setStatus(String status) { 62 | this.status = status; 63 | } 64 | 65 | public String getReason() { 66 | return reason; 67 | } 68 | 69 | public void setReason(String reason) { 70 | this.reason = reason; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/ay/dto/UserDTO.java: -------------------------------------------------------------------------------- 1 | package com.ay.dto; 2 | 3 | import com.ay.model.User; 4 | 5 | /** 6 | * 描述:用户DTO 7 | * 8 | * @author Ay 9 | * @create 2018/07/01 10 | **/ 11 | public class UserDTO extends User { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ay/job/PraiseDataSaveDBJob.java: -------------------------------------------------------------------------------- 1 | package com.ay.job; 2 | 3 | import com.ay.model.Mood; 4 | import com.ay.model.UserMoodPraiseRel; 5 | import com.ay.service.MoodService; 6 | import com.ay.service.UserMoodPraiseRelService; 7 | import org.springframework.beans.factory.annotation.Configurable; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.scheduling.annotation.EnableScheduling; 10 | import org.springframework.scheduling.annotation.Scheduled; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.util.CollectionUtils; 13 | 14 | import javax.annotation.Resource; 15 | import java.util.Set; 16 | 17 | /** 18 | * 描述:定时器 19 | * 20 | * @author Ay 21 | * @date 2018/1/6. 22 | */ 23 | @Component 24 | @Configurable 25 | @EnableScheduling 26 | public class PraiseDataSaveDBJob { 27 | 28 | //每5秒执行一次 29 | @Scheduled(cron = "*/60 * * * * * ") 30 | public void savePraiseDataToDB() { 31 | System.out.println("run ....."); 32 | } 33 | 34 | @Resource 35 | private RedisTemplate redisTemplate; 36 | private static final String PRAISE_HASH_KEY = "springmv.mybatis.boot.mood.id.list.key"; 37 | @Resource 38 | private UserMoodPraiseRelService userMoodPraiseRelService; 39 | @Resource 40 | private MoodService moodService; 41 | 42 | //每10秒执行一次,真实项目当中,我们可以把定时器的执行计划时间设置长一点 43 | //比如说每天晚上凌晨2点跑一次。 44 | @Scheduled(cron = "*/10 * * * * * ") 45 | public void savePraiseDataToDB2() { 46 | 47 | //获取所有被点赞的说说id 48 | Set moods = redisTemplate.opsForSet().members(PRAISE_HASH_KEY); 49 | if (CollectionUtils.isEmpty(moods)) { 50 | return; 51 | } 52 | for (String moodId : moods) { 53 | if (redisTemplate.opsForSet().members(moodId) == null) { 54 | continue; 55 | } else { 56 | //通过说说id获取所有点赞的用户id列表 57 | Set userIds = redisTemplate.opsForSet().members(moodId); 58 | if (CollectionUtils.isEmpty(userIds)) { 59 | continue; 60 | } else { 61 | for (String userId : userIds) { 62 | UserMoodPraiseRel userMoodPraiseRel = new UserMoodPraiseRel(); 63 | userMoodPraiseRel.setMoodId(moodId); 64 | userMoodPraiseRel.setUserId(userId); 65 | //保存说说与用户关联关系 66 | userMoodPraiseRelService.save(userMoodPraiseRel); 67 | } 68 | Mood mood = moodService.findById(moodId); 69 | //更新说说点赞数量 70 | //说说的总点赞数量 = redis 点赞数量 + 数据库的点赞数量 71 | mood.setPraiseNum(mood.getPraiseNum() + redisTemplate.opsForSet().size(moodId).intValue()); 72 | moodService.update(mood); 73 | //清除缓存数据 74 | redisTemplate.delete(moodId); 75 | } 76 | } 77 | } 78 | //清除缓存数据 79 | redisTemplate.delete(PRAISE_HASH_KEY); 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AyRole.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * 描述:角色实体 8 | * 9 | * @author Ay 10 | * @create 2018/05/01 11 | **/ 12 | public class AyRole implements Serializable { 13 | 14 | private Integer id; 15 | 16 | private String name; 17 | 18 | private List ayUserList; 19 | 20 | public Integer getId() { 21 | return id; 22 | } 23 | 24 | public void setId(Integer id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public List getAyUserList() { 37 | return ayUserList; 38 | } 39 | 40 | public void setAyUserList(List ayUserList) { 41 | this.ayUserList = ayUserList; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AySchool.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * 描述:学校实体 8 | * 9 | * @author Ay 10 | * @create 2018/05/01 11 | **/ 12 | public class AySchool implements Serializable { 13 | 14 | private Integer id; 15 | private String name; 16 | //一个学校有多个学生 17 | private List students; 18 | 19 | public Integer getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Integer 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 List getStudents() { 36 | return students; 37 | } 38 | 39 | public void setStudents(List students) { 40 | this.students = students; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AyStudent.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述:学生实体 7 | * 8 | * @author Ay 9 | * @create 2018/05/01 10 | **/ 11 | public class AyStudent implements Serializable { 12 | 13 | private Integer id; 14 | private String name; 15 | private Integer age; 16 | //一个学生只能在一个学校 17 | private AySchool aySchool; 18 | 19 | public Integer getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Integer 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 | public AySchool getAySchool() { 44 | return aySchool; 45 | } 46 | 47 | public void setAySchool(AySchool aySchool) { 48 | this.aySchool = aySchool; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AyUser.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import org.hibernate.validator.constraints.Length; 4 | import org.hibernate.validator.constraints.Range; 5 | 6 | import javax.validation.constraints.NotBlank; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | /** 11 | * 用户实体 12 | * 13 | * @author Ay 14 | * @date 2018/04/02 15 | */ 16 | public class AyUser implements Serializable { 17 | 18 | private Integer id; 19 | @NotBlank(message = "name不能为空") 20 | private String name; 21 | @Length(min = 3, max = 16, message = "密码长度必须在3~16位之间") 22 | private String password; 23 | @Range(min = 0, max = 150, message = "年龄必须在0~150岁之间") 24 | private Integer age; 25 | 26 | //用户和地址一一对应,即一个用户只有一个老家地址 27 | private AyUserAddress ayUserAddress; 28 | 29 | private List ayRoleList; 30 | 31 | public Integer getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Integer id) { 36 | this.id = id; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public String getPassword() { 48 | return password; 49 | } 50 | 51 | public void setPassword(String password) { 52 | this.password = password; 53 | } 54 | 55 | public Integer getAge() { 56 | return age; 57 | } 58 | 59 | public void setAge(Integer age) { 60 | this.age = age; 61 | } 62 | 63 | public AyUserAddress getAyUserAddress() { 64 | return ayUserAddress; 65 | } 66 | 67 | public void setAyUserAddress(AyUserAddress ayUserAddress) { 68 | this.ayUserAddress = ayUserAddress; 69 | } 70 | 71 | public List getAyRoleList() { 72 | return ayRoleList; 73 | } 74 | 75 | public void setAyRoleList(List ayRoleList) { 76 | this.ayRoleList = ayRoleList; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AyUserAddress.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述:用户地址实体 7 | * 8 | * @author Ay 9 | * @create 2018/05/01 10 | **/ 11 | public class AyUserAddress implements Serializable { 12 | 13 | private Integer id; 14 | private String name; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/AyUserRoleRel.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述:角色实体 7 | * 8 | * @author Ay 9 | * @create 2018/05/01 10 | **/ 11 | public class AyUserRoleRel implements Serializable { 12 | 13 | private Integer id; 14 | 15 | private Integer userId; 16 | 17 | private Integer roleId; 18 | 19 | public Integer getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Integer id) { 24 | this.id = id; 25 | } 26 | 27 | public Integer getUserId() { 28 | return userId; 29 | } 30 | 31 | public void setUserId(Integer userId) { 32 | this.userId = userId; 33 | } 34 | 35 | public Integer getRoleId() { 36 | return roleId; 37 | } 38 | 39 | public void setRoleId(Integer roleId) { 40 | this.roleId = roleId; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/Mood.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * 描述:说说 8 | * Created by Ay on 2017/9/16. 9 | */ 10 | public class Mood implements Serializable { 11 | /** 12 | * 主键 13 | */ 14 | private String id; 15 | /** 16 | * 说说内容 17 | */ 18 | private String content; 19 | /** 20 | * 点赞数量 21 | */ 22 | private Integer praiseNum; 23 | /** 24 | * 用户id 25 | */ 26 | private String userId; 27 | /** 28 | * 发表时间 29 | */ 30 | private Date publishTime; 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | public void setId(String id) { 37 | this.id = id; 38 | } 39 | 40 | public String getContent() { 41 | return content; 42 | } 43 | 44 | public void setContent(String content) { 45 | this.content = content; 46 | } 47 | 48 | public Integer getPraiseNum() { 49 | return praiseNum; 50 | } 51 | 52 | public void setPraiseNum(Integer praiseNum) { 53 | this.praiseNum = praiseNum; 54 | } 55 | 56 | public String getUserId() { 57 | return userId; 58 | } 59 | 60 | public void setUserId(String userId) { 61 | this.userId = userId; 62 | } 63 | 64 | public Date getPublishTime() { 65 | return publishTime; 66 | } 67 | 68 | public void setPublishTime(Date publishTime) { 69 | this.publishTime = publishTime; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/SysUser.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 员工表 7 | * Created by Ay on 2020/3/22. 8 | */ 9 | public class SysUser implements Serializable { 10 | //主键 11 | private Integer id; 12 | //用户名 13 | private String name; 14 | //工号 15 | private String no; 16 | //职位 17 | private String position; 18 | //离职原因 19 | private String reason; 20 | //状态,0:删除 1:在职 2:离职 21 | private String status; 22 | 23 | public Integer getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Integer id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getNo() { 40 | return no; 41 | } 42 | 43 | public void setNo(String no) { 44 | this.no = no; 45 | } 46 | 47 | public String getPosition() { 48 | return position; 49 | } 50 | 51 | public void setPosition(String position) { 52 | this.position = position; 53 | } 54 | 55 | public String getStatus() { 56 | return status; 57 | } 58 | 59 | public void setStatus(String status) { 60 | this.status = status; 61 | } 62 | 63 | public String getReason() { 64 | return reason; 65 | } 66 | 67 | public void setReason(String reason) { 68 | this.reason = reason; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/User.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述:用户表 7 | * 8 | * @author Ay 9 | * @date 2017/9/16. 10 | */ 11 | public class User implements Serializable { 12 | /** 13 | * 主键 14 | */ 15 | private String id; 16 | /** 17 | * 用户名称 18 | */ 19 | private String name; 20 | /** 21 | * 账户 22 | */ 23 | private String account; 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getAccount() { 42 | return account; 43 | } 44 | 45 | public void setAccount(String account) { 46 | this.account = account; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/main/java/com/ay/model/UserMoodPraiseRel.java: -------------------------------------------------------------------------------- 1 | package com.ay.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述:说说点赞关联表 7 | * 8 | * @author ay 9 | * @date 2017/9/16 10 | */ 11 | public class UserMoodPraiseRel implements Serializable { 12 | /** 13 | * 主键 14 | */ 15 | private Integer id; 16 | /** 17 | * 用户id 18 | */ 19 | private String userId; 20 | /** 21 | * 说说id 22 | */ 23 | private String moodId; 24 | 25 | public String getUserId() { 26 | return userId; 27 | } 28 | 29 | public void setUserId(String userId) { 30 | this.userId = userId; 31 | } 32 | 33 | public String getMoodId() { 34 | return moodId; 35 | } 36 | 37 | public void setMoodId(String moodId) { 38 | this.moodId = moodId; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ay/mq/MoodConsumer.java: -------------------------------------------------------------------------------- 1 | package com.ay.mq; 2 | 3 | import com.ay.dto.MoodDTO; 4 | import com.ay.model.Mood; 5 | import org.apache.activemq.command.ActiveMQObjectMessage; 6 | import org.apache.log4j.Logger; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.annotation.Resource; 11 | import javax.jms.Message; 12 | import javax.jms.MessageListener; 13 | 14 | /** 15 | * 消费者 16 | * 17 | * @author Ay 18 | * @date 2017/11/30 19 | */ 20 | @Component 21 | public class MoodConsumer implements MessageListener { 22 | 23 | private static final String PRAISE_HASH_KEY = "springmv.mybatis.boot.mood.id.list.key"; 24 | 25 | @Resource 26 | private RedisTemplate redisTemplate; 27 | 28 | private Logger log = Logger.getLogger(this.getClass()); 29 | 30 | public void onMessage(Message message) { 31 | try { 32 | MoodDTO mood = (MoodDTO) ((ActiveMQObjectMessage) message).getObject(); 33 | //1.存放到set中 34 | redisTemplate.opsForSet().add(PRAISE_HASH_KEY, mood.getId()); 35 | //2.存放到set中 36 | redisTemplate.opsForSet().add(mood.getId(), mood.getUserId()); 37 | log.info("消费者--->>>用户id:" + mood.getUserId() + " 给说说id:" + mood.getId() + " 点赞"); 38 | } catch (Exception e) { 39 | System.out.println(e); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ay/mq/MoodProducer.java: -------------------------------------------------------------------------------- 1 | package com.ay.mq; 2 | 3 | import com.ay.dto.MoodDTO; 4 | import com.ay.model.Mood; 5 | import org.apache.log4j.Logger; 6 | import org.apache.log4j.spi.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.jms.core.JmsTemplate; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.Resource; 12 | import javax.jms.Destination; 13 | 14 | /** 15 | * 生产者jmsTemplate 16 | * 17 | * @author Ay 18 | * @date 2017/11/30 19 | */ 20 | @Component 21 | public class MoodProducer { 22 | 23 | @Resource 24 | private JmsTemplate jmsTemplate; 25 | 26 | private Logger log = Logger.getLogger(this.getClass()); 27 | 28 | public void sendMessage(Destination destination, final MoodDTO mood) { 29 | log.info("生产者--->>>用户id:" + mood.getUserId() + " 给说说id:" + mood.getId() + " 点赞"); 30 | //mood实体需要实现Serializable序列化接口 31 | jmsTemplate.convertAndSend(destination, mood); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/ay/proxy/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.ay.proxy; 2 | 3 | import org.aspectj.lang.annotation.After; 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.aspectj.lang.annotation.Before; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * 描述:日志拦截类 10 | * 11 | * @author Ay 12 | * @create 2018/04/22 13 | **/ 14 | @Aspect 15 | @Component 16 | public class LogInterceptor { 17 | 18 | @Before(value = "execution(* com.ay.controller.*.*(..))") 19 | public void before() { 20 | System.out.println("进入方法时间为:" + System.currentTimeMillis()); 21 | } 22 | 23 | @After(value = "execution(* com.ay.controller.*.*(..))") 24 | public void after() { 25 | System.out.println("退出方法时间为:" + System.currentTimeMillis()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/AyRoleService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.AyRole; 4 | 5 | public interface AyRoleService { 6 | AyRole findById(String id); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/AySchoolService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.AySchool; 4 | import com.ay.model.AyUserAddress; 5 | 6 | /** 7 | * 描述:地址服务接口 8 | * 9 | * @author Ay 10 | * @create 2018/05/01 11 | **/ 12 | public interface AySchoolService { 13 | 14 | AySchool findById(Integer id); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/AyStudentService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.AyStudent; 4 | import com.ay.model.AyUserAddress; 5 | 6 | /** 7 | * 描述:地址服务接口 8 | * 9 | * @author Ay 10 | * @create 2018/05/01 11 | **/ 12 | public interface AyStudentService { 13 | 14 | AyStudent findById(Integer id); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/AyUserAddressService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.AyUserAddress; 4 | 5 | /** 6 | * 描述:地址服务接口 7 | * 8 | * @author Ay 9 | * @create 2018/05/01 10 | **/ 11 | public interface AyUserAddressService { 12 | 13 | AyUserAddress findById(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/AyUserService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.AyUser; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.apache.ibatis.session.RowBounds; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public interface AyUserService { 11 | 12 | List findAll(); 13 | 14 | // List findAll(RowBounds rowBounds); 15 | // 16 | AyUser findById(String id); 17 | 18 | // 19 | // List findByName(String name); 20 | // 21 | // int countByName(String name); 22 | // 23 | int insert(AyUser ayUser); 24 | 25 | // 26 | int update(AyUser ayUser); 27 | // 28 | // int delete(int id); 29 | // 30 | // int deleteByName(String name); 31 | 32 | // List findByNameAndPassword(Map map); 33 | 34 | // List findByNameAndPassword(String name, String password); 35 | // 36 | // List findByIds(List ids); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/MoodService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.dto.MoodDTO; 4 | import com.ay.model.Mood; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 描述:说说接口 11 | * 12 | * @author Ay 13 | * @date 2018/1/6. 14 | */ 15 | public interface MoodService { 16 | //传统查询 17 | List findAll(); 18 | 19 | //传统点赞 20 | boolean praiseMood(String userId, String moodId); 21 | 22 | boolean update(@Param("mood") Mood mood); 23 | 24 | Mood findById(String id); 25 | 26 | boolean praiseMoodForRedis(String userId, String moodId); 27 | 28 | List findAllForRedis(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.dto.SysUserDTO; 4 | import com.ay.model.SysUser; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 用户服务接口 10 | * Created by Ay on 2020/3/22. 11 | */ 12 | public interface SysUserService { 13 | 14 | List findAll(); 15 | 16 | boolean save(SysUserDTO user); 17 | 18 | SysUser findById(Integer id); 19 | 20 | boolean update(SysUserDTO user); 21 | 22 | boolean updateStatus(SysUserDTO user); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/UserMoodPraiseRelService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.model.UserMoodPraiseRel; 4 | 5 | /** 6 | * 描述:用户说说点赞关联接口 7 | * 8 | * @author Ay 9 | * @date 2018/1/6. 10 | */ 11 | public interface UserMoodPraiseRelService { 12 | 13 | boolean save(UserMoodPraiseRel userMoodPraiseRel); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.ay.service; 2 | 3 | import com.ay.dto.UserDTO; 4 | 5 | /** 6 | * 描述:用户服务接口 7 | * 8 | * @author Ay 9 | * @date 2018/1/6. 10 | */ 11 | public interface UserService { 12 | 13 | UserDTO find(String id); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/AyRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.AyRoleDao; 4 | import com.ay.dao.AyUserDao; 5 | import com.ay.model.AyRole; 6 | import com.ay.model.AyUser; 7 | import com.ay.service.AyRoleService; 8 | import com.ay.service.AyUserService; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.Resource; 12 | 13 | @Service 14 | public class AyRoleServiceImpl implements AyRoleService { 15 | 16 | @Resource 17 | private AyRoleDao ayRoleDao; 18 | 19 | public AyRole findById(String id) { 20 | return ayRoleDao.findById(id); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/AySchoolServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.AySchoolDao; 4 | import com.ay.dao.AyUserAddressDao; 5 | import com.ay.model.AySchool; 6 | import com.ay.model.AyUserAddress; 7 | import com.ay.service.AySchoolService; 8 | import com.ay.service.AyUserAddressService; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * @author Ay 15 | * @create 2018/05/01 16 | **/ 17 | @Service 18 | public class AySchoolServiceImpl implements AySchoolService { 19 | 20 | @Resource 21 | private AySchoolDao aySchoolDao; 22 | 23 | public AySchool findById(Integer id) { 24 | return aySchoolDao.findById(id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/AyStudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.AyStudentDao; 4 | import com.ay.dao.AyUserAddressDao; 5 | import com.ay.model.AyStudent; 6 | import com.ay.model.AyUserAddress; 7 | import com.ay.service.AyStudentService; 8 | import com.ay.service.AyUserAddressService; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * @author Ay 15 | * @create 2018/05/01 16 | **/ 17 | @Service 18 | public class AyStudentServiceImpl implements AyStudentService { 19 | 20 | @Resource 21 | private AyStudentDao ayStudentDao; 22 | 23 | public AyStudent findById(Integer id) { 24 | return ayStudentDao.findById(id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/AyUserAddressServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.AyUserAddressDao; 4 | import com.ay.model.AyUserAddress; 5 | import com.ay.service.AyUserAddressService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | 10 | /** 11 | * @author Ay 12 | * @create 2018/05/01 13 | **/ 14 | @Service 15 | public class AyUserAddressServiceImpl implements AyUserAddressService { 16 | 17 | @Resource 18 | private AyUserAddressDao ayUserAddressDao; 19 | 20 | public AyUserAddress findById(Integer id) { 21 | return ayUserAddressDao.findById(id); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/AyUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.AyUserDao; 4 | import com.ay.model.AyUser; 5 | import com.ay.service.AyUserService; 6 | import org.apache.ibatis.session.RowBounds; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | @Service 16 | public class AyUserServiceImpl implements AyUserService { 17 | 18 | @Resource 19 | private AyUserDao ayUserDao; 20 | 21 | public List findAll() { 22 | return ayUserDao.findAll(); 23 | } 24 | 25 | // 26 | public AyUser findById(String id) { 27 | return ayUserDao.findById(id); 28 | } 29 | 30 | // 31 | // public List findByName(String name) { 32 | // return ayUserDao.findByName(name); 33 | // } 34 | // 35 | // public int countByName(String name) { 36 | // return ayUserDao.countByName(name); 37 | // } 38 | // 39 | public int insert(AyUser ayUser) { 40 | return ayUserDao.insert(ayUser); 41 | } 42 | 43 | @Transactional 44 | public int update(AyUser ayUser) { 45 | int count = ayUserDao.update(ayUser); 46 | String s = null; 47 | s.split(","); 48 | return count; 49 | } 50 | // 51 | // public int delete(int id) { 52 | // return ayUserDao.delete(id); 53 | // } 54 | // 55 | // public int deleteByName(String name) { 56 | // return ayUserDao.deleteByName(name); 57 | // } 58 | // 59 | // public List findByIds(List ids) { 60 | // return ayUserDao.findByIds(ids); 61 | // } 62 | // 63 | // public List findByNameAndPassword(String name, String password) { 64 | // return ayUserDao.findByNameAndPassword(name, password); 65 | // } 66 | 67 | // public List findByNameAndPassword(Map map) { 68 | // return ayUserDao.findByNameAndPassword(map); 69 | // } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/MoodServiveImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.MoodDao; 4 | import com.ay.dao.UserDao; 5 | import com.ay.dao.UserMoodPraiseRelDao; 6 | import com.ay.dto.MoodDTO; 7 | import com.ay.model.Mood; 8 | import com.ay.model.User; 9 | import com.ay.model.UserMoodPraiseRel; 10 | import com.ay.mq.MoodProducer; 11 | import com.ay.service.MoodService; 12 | import com.ay.service.UserService; 13 | import org.apache.activemq.command.ActiveMQQueue; 14 | import org.springframework.data.redis.core.RedisTemplate; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.util.CollectionUtils; 17 | 18 | import javax.annotation.Resource; 19 | import javax.jms.Destination; 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | /** 25 | * 描述:说说服务类 26 | * 27 | * @author Ay 28 | * @date 2018/1/6. 29 | */ 30 | @Service 31 | public class MoodServiveImpl implements MoodService { 32 | @Resource 33 | private MoodDao moodDao; 34 | @Resource 35 | private UserDao userDao; 36 | @Resource 37 | private UserMoodPraiseRelDao userMoodPraiseRelDao; 38 | 39 | @Resource 40 | private MoodProducer moodProducer; 41 | 42 | //队列 43 | private static Destination destination = new ActiveMQQueue("ay.queue.high.concurrency.praise"); 44 | 45 | 46 | public boolean praiseMoodForRedis(String userId, String moodId) { 47 | MoodDTO moodDTO = new MoodDTO(); 48 | moodDTO.setUserId(userId); 49 | moodDTO.setId(moodId); 50 | moodProducer.sendMessage(destination, moodDTO); 51 | 52 | // //1.存放到hashset中 53 | // redisTemplate.opsForSet().add(PRAISE_HASH_KEY , moodId); 54 | // //2.存放到set中 55 | // redisTemplate.opsForSet().add(moodId,userId); 56 | return false; 57 | } 58 | 59 | public List findAll() { 60 | List moodList = moodDao.findAll(); 61 | return converModel2DTO(moodList); 62 | } 63 | 64 | private List converModel2DTO(List moodList) { 65 | if (CollectionUtils.isEmpty(moodList)) return Collections.EMPTY_LIST; 66 | List moodDTOList = new ArrayList(); 67 | for (Mood mood : moodList) { 68 | MoodDTO moodDTO = new MoodDTO(); 69 | moodDTO.setId(mood.getId()); 70 | moodDTO.setContent(mood.getContent()); 71 | moodDTO.setPraiseNum(mood.getPraiseNum()); 72 | moodDTO.setPublishTime(mood.getPublishTime()); 73 | moodDTO.setUserId(mood.getUserId()); 74 | moodDTOList.add(moodDTO); 75 | //设置用户信息 76 | User user = userDao.find(mood.getUserId()); 77 | moodDTO.setUserName(user.getName()); 78 | moodDTO.setUserAccount(user.getAccount()); 79 | } 80 | return moodDTOList; 81 | } 82 | 83 | public boolean praiseMood(String userId, String moodId) { 84 | //保存关联关系 85 | UserMoodPraiseRel userMoodPraiseRel = new UserMoodPraiseRel(); 86 | userMoodPraiseRel.setUserId(userId); 87 | userMoodPraiseRel.setMoodId(moodId); 88 | userMoodPraiseRelDao.save(userMoodPraiseRel); 89 | //更新说说的点赞数量 90 | Mood mood = this.findById(moodId); 91 | mood.setPraiseNum(mood.getPraiseNum() + 1); 92 | this.update(mood); 93 | 94 | return Boolean.TRUE; 95 | } 96 | 97 | public boolean update(Mood mood) { 98 | return moodDao.update(mood); 99 | } 100 | 101 | public Mood findById(String id) { 102 | return moodDao.findById(id); 103 | } 104 | 105 | @Resource 106 | private RedisTemplate redisTemplate; 107 | 108 | private static final String PRAISE_HASH_KEY = "springmv.mybatis.boot.mood.id.list.key"; 109 | 110 | 111 | @Resource 112 | private UserService userService; 113 | 114 | public List findAllForRedis() { 115 | List moodList = moodDao.findAll(); 116 | if (CollectionUtils.isEmpty(moodList)) { 117 | return Collections.EMPTY_LIST; 118 | } 119 | List moodDTOList = new ArrayList(); 120 | for (Mood mood : moodList) { 121 | MoodDTO moodDTO = new MoodDTO(); 122 | moodDTO.setId(mood.getId()); 123 | moodDTO.setUserId(mood.getUserId()); 124 | //right = 总点赞数量 : 数据库的点赞数量 + redis的点赞数量 125 | moodDTO.setPraiseNum(mood.getPraiseNum() + redisTemplate.opsForSet().size(mood.getId()).intValue()); 126 | moodDTO.setPublishTime(mood.getPublishTime()); 127 | moodDTO.setContent(mood.getContent()); 128 | //通过userID查询用户 129 | User user = userService.find(mood.getUserId()); 130 | //用户名 131 | moodDTO.setUserName(user.getName()); 132 | //账户 133 | moodDTO.setUserAccount(user.getAccount()); 134 | moodDTOList.add(moodDTO); 135 | } 136 | return moodDTOList; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/SysUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | import com.ay.dao.SysUserDao; 3 | import com.ay.dto.SysUserDTO; 4 | import com.ay.model.SysUser; 5 | import com.ay.service.SysUserService; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.springframework.stereotype.Service; 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | /** 12 | * 用户服务实现类 13 | * Created by Ay on 2020/3/22. 14 | */ 15 | @Service 16 | public class SysUserServiceImpl implements SysUserService{ 17 | @Resource 18 | private SysUserDao sysUserDao; 19 | 20 | public List findAll() { 21 | return sysUserDao.findAll(); 22 | } 23 | 24 | public boolean save(SysUserDTO user) { 25 | user.setStatus("1"); 26 | sysUserDao.save(convert(user)); 27 | return true; 28 | } 29 | 30 | public boolean update(SysUserDTO user) { 31 | SysUser sysUser = convert(user); 32 | sysUserDao.update(sysUser); 33 | return true; 34 | } 35 | 36 | public SysUser findById(Integer id) { 37 | return sysUserDao.findById(id); 38 | } 39 | 40 | public SysUser convert(SysUserDTO user){ 41 | SysUser sysUser = new SysUser(); 42 | if(user.getId() != null){ 43 | sysUser.setId(Integer.valueOf(user.getId())); 44 | } 45 | sysUser.setName(user.getName()); 46 | sysUser.setNo(user.getNo()); 47 | sysUser.setStatus(user.getStatus()); 48 | if(user.getStatus().equals("在职")){ 49 | sysUser.setStatus("1"); 50 | } 51 | if(user.getStatus().equals("已离职")){ 52 | sysUser.setStatus("2"); 53 | } 54 | sysUser.setPosition(user.getPosition()); 55 | sysUser.setReason(user.getReason()); 56 | return sysUser; 57 | } 58 | 59 | public boolean updateStatus(SysUserDTO user) { 60 | sysUserDao.updateStatus(convert(user)); 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/UserMoodPraiseRelServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.UserMoodPraiseRelDao; 4 | import com.ay.model.UserMoodPraiseRel; 5 | import com.ay.service.UserMoodPraiseRelService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | 10 | /** 11 | * 描述:用户说说点赞关联服务类 12 | * 13 | * @author Ay 14 | * @date 2018/1/6. 15 | */ 16 | @Service 17 | public class UserMoodPraiseRelServiceImpl implements UserMoodPraiseRelService { 18 | 19 | @Resource 20 | private UserMoodPraiseRelDao userMoodPraiseRelDao; 21 | 22 | public boolean save(UserMoodPraiseRel userMoodPraiseRel) { 23 | return userMoodPraiseRelDao.save(userMoodPraiseRel); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ay/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.service.impl; 2 | 3 | import com.ay.dao.UserDao; 4 | import com.ay.dto.UserDTO; 5 | import com.ay.model.User; 6 | import com.ay.service.UserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * 描述:用户服务类 13 | * 14 | * @author Ay 15 | * @date 2018/1/6. 16 | */ 17 | @Service 18 | public class UserServiceImpl implements UserService { 19 | 20 | @Resource 21 | private UserDao userDao; 22 | 23 | public UserDTO find(String id) { 24 | User user = userDao.find(id); 25 | return converModel2DTO(user); 26 | } 27 | 28 | private UserDTO converModel2DTO(User user) { 29 | UserDTO userDTO = new UserDTO(); 30 | userDTO.setId(user.getId()); 31 | userDTO.setAccount(user.getAccount()); 32 | userDTO.setName(user.getName()); 33 | return userDTO; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/ay/validator/AyUserValidator.java: -------------------------------------------------------------------------------- 1 | package com.ay.validator; 2 | 3 | import com.ay.model.AyUser; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.validation.Errors; 6 | import org.springframework.validation.ValidationUtils; 7 | import org.springframework.validation.Validator; 8 | 9 | /** 10 | * 描述:用户数据校验类 11 | * 12 | * @author Ay 13 | * @create 2018/05/25 14 | **/ 15 | 16 | @Component 17 | public class AyUserValidator implements Validator { 18 | 19 | /** 20 | * This Validator validates *just* AyUser instances 21 | */ 22 | public boolean supports(Class clazz) { 23 | return AyUser.class.equals(clazz); 24 | } 25 | 26 | public void validate(Object obj, Errors e) { 27 | ValidationUtils.rejectIfEmpty(e, "name", "name.empty"); 28 | AyUser p = (AyUser) obj; 29 | if (p.getAge() < 0) { 30 | e.rejectValue("age", "年龄不能小于0岁"); 31 | } else if (p.getAge() > 150) { 32 | e.rejectValue("age", "年龄不能超过150岁"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/activemq.properties: -------------------------------------------------------------------------------- 1 | ### active mq服务器地址 2 | activemq_url=tcp://localhost:61616 3 | ### 服务器用户名 4 | activemq_username=admin 5 | ### 服务器密码 6 | activemq_password=admin -------------------------------------------------------------------------------- /src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | helperDialect=mysql 47 | reasonable=true 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 70 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://127.0.0.1:3306/springmvc-mybatis-book?serverTimezone=GMT 3 | jdbc.username=root 4 | jdbc.password=123456 -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ### set log levels ### 2 | log4j.rootLogger=DEBUG,Console 3 | #,File 4 | ### 输出到控制台 ### 5 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 6 | log4j.appender.Console.Target=System.out 7 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 9 | ### 输出到日志文件 ### 10 | #log4j.appender.File=org.apache.log4j.RollingFileAppender 11 | #log4j.appender.File.File=${project}/WEB-INF/logs/app.log 12 | #log4j.appender.File.DatePattern=_yyyyMMdd'.log' 13 | #log4j.appender.File.MaxFileSize=10MB 14 | #log4j.appender.File.Threshold=ALL 15 | #log4j.appender.File.layout=org.apache.log4j.PatternLayout 16 | #log4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%c]%m%n -------------------------------------------------------------------------------- /src/main/resources/mapper/AyRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/mapper/AySchoolMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/mapper/AyStudentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/mapper/AyUserAddressMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/mapper/AyUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 35 | 36 | 37 | a.id as "id", 38 | a.name as "name", 39 | a.password as "password" 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /src/main/resources/mapper/MoodMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, 18 | content, 19 | user_id, 20 | praise_num, 21 | publish_time 22 | 23 | 24 | 29 | 30 | 38 | 39 | 40 | update mood 41 | 42 | 43 | content = #{mood.content}, 44 | 45 | 46 | praise_num = #{mood.praiseNum}, 47 | 48 | 49 | WHERE id = #{mood.id} 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/resources/mapper/SysUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id, 17 | name, 18 | no, 19 | status, 20 | position, 21 | reason 22 | 23 | 24 | 30 | 31 | 37 | 38 | 40 | 41 | select max(id) + 1 as id from sys_user 42 | 43 | insert into sys_user(id, name ,no, status, position) 44 | value (#{id},#{name},#{no},#{status},#{position} ) 45 | 46 | 47 | 48 | update sys_user 49 | 50 | name = #{user.name}, 51 | no = #{user.no}, 52 | status = #{user.status}, 53 | position = #{user.position}, 54 | reason = #{user.reason} 55 | 56 | 57 | id = #{user.id} 58 | 59 | 60 | 61 | 62 | update sys_user 63 | 64 | status = #{user.status}, 65 | reason = #{user.reason} 66 | 67 | 68 | id = #{user.id} 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | id, 14 | name, 15 | account 16 | 17 | 18 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserMoodPraiseRelMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | insert into user_mood_praise_rel (user_id, mood_id) 9 | VALUE (#{userMoodPraiseRel.userId}, #{userMoodPraiseRel.moodId}) 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/resources/redis.properties: -------------------------------------------------------------------------------- 1 | redis.maxIdle=300 2 | redis.minIdle=100 3 | redis.maxWaitMillis=3000 4 | redis.testOnBorrow=true 5 | redis.maxTotal=500 6 | redis.host=127.0.0.1 7 | redis.port=6379 8 | redis.password= -------------------------------------------------------------------------------- /src/main/resources/spring-jms.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 13 | JMS连接工厂 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 队列模式模型 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 39 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/resources/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/resources/spring-redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/AyUserDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import com.ay.dao.AyUserDao; 4 | import com.ay.model.AyUser; 5 | import com.github.pagehelper.PageHelper; 6 | import com.github.pagehelper.PageInfo; 7 | import org.apache.ibatis.session.RowBounds; 8 | import org.apache.ibatis.session.SqlSession; 9 | import org.apache.ibatis.session.SqlSessionFactory; 10 | import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; 11 | import org.junit.Test; 12 | import org.mybatis.spring.SqlSessionFactoryBean; 13 | 14 | import javax.annotation.Resource; 15 | import java.sql.Connection; 16 | import java.util.List; 17 | 18 | /** 19 | * 描述:用户DAO测试类 20 | * 21 | * @author Ay 22 | * @create 2018/05/04 23 | **/ 24 | public class AyUserDaoTest extends BaseJunit4Test { 25 | 26 | @Resource 27 | private AyUserDao ayUserDao; 28 | 29 | // @Test 30 | // public void testFindAll(){ 31 | // List userList = ayUserDao.findAll(new RowBounds(0, 5)); 32 | // for(AyUser ayUser: userList){ 33 | // System.out.println("name: " + ayUser.getName()); 34 | // } 35 | // } 36 | 37 | @Test 38 | public void testPageHelper() { 39 | //startPage(第几页, 多少条数据) 40 | PageHelper.startPage(0, 1); 41 | //查询所有用户 42 | List userList = ayUserDao.findAll(); 43 | //用PageInfo对结果进行包装 44 | PageInfo pageInfo = new PageInfo(userList); 45 | } 46 | 47 | @Resource 48 | private SqlSessionFactoryBean sqlSessionFactoryBean; 49 | 50 | @Test 51 | public void testSessionCache() throws Exception { 52 | SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject(); 53 | SqlSession sqlSession = sqlSessionFactory.openSession(); 54 | AyUserDao ayUserDao = sqlSession.getMapper(AyUserDao.class); 55 | //第一次查询 56 | AyUser ayUser = ayUserDao.findById("1"); 57 | System.out.println("name: " + ayUser.getName() 58 | + " password:" + ayUser.getPassword()); 59 | 60 | //执行commit操作(如:更新、插入、删除等操作) 61 | AyUser user = new AyUser(); 62 | user.setId(1); 63 | user.setName("al"); 64 | ayUserDao.update(ayUser); 65 | 66 | //第二次查询 67 | AyUser ayUser2 = ayUserDao.findById("1"); 68 | System.out.println("name: " + ayUser2.getName() 69 | + " password:" + ayUser2.getPassword()); 70 | sqlSession.close(); 71 | ; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/BaseJunit4Test.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ContextConfiguration; 5 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 6 | 7 | /** 8 | * 描述:测试基类 9 | * 10 | * @author Ay 11 | * @create 2018/05/04 12 | **/ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) 15 | public class BaseJunit4Test { 16 | } 17 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/BusinessClassService.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | /** 4 | * 描述:业务类接口 5 | * 6 | * @author Ay 7 | * @create 2018/04/22 8 | **/ 9 | public interface BusinessClassService { 10 | 11 | void doSomeThing(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/BusinessClassServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * 描述:业务实现类 7 | * 8 | * @author Ay 9 | * @create 2018/04/22 10 | **/ 11 | public class BusinessClassServiceImpl implements BusinessClassService { 12 | 13 | /** 14 | * 处理业务 15 | */ 16 | public void doSomeThing() { 17 | System.out.println("do something ......"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MQTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import com.ay.dto.MoodDTO; 4 | import com.ay.model.Mood; 5 | import com.ay.mq.MoodProducer; 6 | import org.apache.activemq.command.ActiveMQQueue; 7 | import org.junit.Test; 8 | 9 | import javax.annotation.Resource; 10 | import javax.jms.Destination; 11 | 12 | /** 13 | * @author Ay 14 | * @create 2018/07/14 15 | **/ 16 | public class MQTest extends BaseJunit4Test { 17 | 18 | @Resource 19 | private MoodProducer moodProducer; 20 | 21 | //队列 22 | private static Destination destination = new ActiveMQQueue("ay.queue.high.concurrency-praise"); 23 | 24 | @Test 25 | public void testMQ() { 26 | MoodDTO mood = new MoodDTO(); 27 | mood.setId("1"); 28 | mood.setContent("aaaa"); 29 | moodProducer.sendMessage(destination, mood); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MoodDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import com.ay.dao.MoodDao; 4 | import com.ay.dao.UserDao; 5 | import com.ay.model.Mood; 6 | import org.junit.Test; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | /** 12 | * 描述:用户DAO测试类 13 | * 14 | * @author Ay 15 | * @create 2018/05/04 16 | **/ 17 | public class MoodDaoTest extends BaseJunit4Test { 18 | 19 | @Resource 20 | private MoodDao moodDao; 21 | 22 | @Test 23 | public void testFindAll() { 24 | List moodList = moodDao.findAll(); 25 | System.out.println(moodList.size()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MyLogger.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * 描述:日志类接口 7 | * 8 | * @author Ay 9 | * @create 2018/04/22 10 | **/ 11 | public interface MyLogger { 12 | 13 | /** 14 | * 纪录进入方法时间 15 | */ 16 | void saveIntoMethodTime(Method method); 17 | 18 | /** 19 | * 纪录退出方法时间 20 | */ 21 | void saveOutMethodTime(Method method); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MyLoggerHandler.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import javax.annotation.Resource; 4 | import java.lang.reflect.InvocationHandler; 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * 描述:日志类Handler 9 | * 10 | * @author Ay 11 | * @create 2018/04/22 12 | **/ 13 | public class MyLoggerHandler implements InvocationHandler { 14 | 15 | //原始对象 16 | private Object objOriginal; 17 | //这里很关键 18 | private MyLogger myLogger = new MyLoggerImpl(); 19 | 20 | public MyLoggerHandler(Object obj) { 21 | super(); 22 | this.objOriginal = obj; 23 | } 24 | 25 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 26 | Object result = null; 27 | //日志类的方法 28 | myLogger.saveIntoMethodTime(method); 29 | //调用代理类方法 30 | result = method.invoke(this.objOriginal, args); 31 | //日志类方法 32 | myLogger.saveOutMethodTime(method); 33 | return result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MyLoggerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * 描述:日志实现类 9 | * 10 | * @author Ay 11 | * @create 2018/04/22 12 | **/ 13 | public class MyLoggerImpl implements MyLogger { 14 | 15 | public void saveIntoMethodTime(Method method) { 16 | System.out.println("进入" + method.getName() + "方法时间为: " + System.currentTimeMillis()); 17 | } 18 | 19 | public void saveOutMethodTime(Method method) { 20 | System.out.println("退出" + method.getName() + "方法时间为:" + System.currentTimeMillis()); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/MyLoggerTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import java.lang.reflect.Proxy; 4 | 5 | /** 6 | * 描述:测试类 7 | * 8 | * @author Ay 9 | * @create 2018/04/22 10 | **/ 11 | public class MyLoggerTest { 12 | 13 | public static void main(String[] args) { 14 | int i = 1; 15 | Integer ii = 1; 16 | if (i == ii) { 17 | System.out.println("111"); 18 | } 19 | float iii = 1; 20 | if (iii == ii) { 21 | System.out.println("12222"); 22 | } 23 | 24 | //实例化真实项目中业务类 25 | BusinessClassService businessClassService = new BusinessClassServiceImpl(); 26 | //日志类的handler 27 | MyLoggerHandler myLoggerHandler = new MyLoggerHandler(businessClassService); 28 | //获得代理类对象 29 | BusinessClassService businessClass = (BusinessClassService) Proxy.newProxyInstance(businessClassService.getClass().getClassLoader(), businessClassService.getClass().getInterfaces(), myLoggerHandler); 30 | //执行代理类方法 31 | businessClass.doSomeThing(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/ProxyPattern.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | /** 4 | * 描述:客户端类 5 | * 6 | * @author Ay 7 | * @create 2018/04/22 8 | **/ 9 | public class ProxyPattern { 10 | public static void main(String[] args) { 11 | Proxy proxy = new Proxy(new RealSubject()); 12 | proxy.operation(); 13 | } 14 | } 15 | 16 | /** 17 | * 描述:抽象主题类 18 | * 19 | * @author Ay 20 | * @create 2018/04/22 21 | **/ 22 | abstract class Subject { 23 | abstract void operation(); 24 | } 25 | 26 | /** 27 | * 描述:具体主题类 28 | * 29 | * @author Ay 30 | * @create 2018/04/22 31 | **/ 32 | class RealSubject extends Subject { 33 | 34 | void operation() { 35 | System.out.println("operation ......"); 36 | } 37 | } 38 | 39 | /** 40 | * 描述:代理类 41 | * 42 | * @author Ay 43 | * @create 2018/04/22 44 | **/ 45 | class Proxy extends Subject { 46 | 47 | private Subject subject; 48 | 49 | public Proxy(Subject subject) { 50 | this.subject = subject; 51 | } 52 | 53 | void operation() { 54 | //前置处理 55 | this.preOperation(); 56 | //具体操作 57 | subject.operation(); 58 | //后置处理 59 | this.postOperation(); 60 | } 61 | 62 | void preOperation() { 63 | System.out.println("pre operation......"); 64 | } 65 | 66 | void postOperation() { 67 | System.out.println("post operation......"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/RedisTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import org.junit.Test; 4 | import org.springframework.data.redis.core.RedisTemplate; 5 | 6 | import javax.annotation.Resource; 7 | 8 | /** 9 | * redis缓存测试 10 | * 11 | * @author Ay 12 | * @create 2018/07/08 13 | **/ 14 | public class RedisTest extends BaseJunit4Test { 15 | 16 | @Resource 17 | private RedisTemplate redisTemplate; 18 | 19 | @Test 20 | public void testRedis() { 21 | redisTemplate.opsForValue().set("name", "ay"); 22 | String name = (String) redisTemplate.opsForValue().get("name"); 23 | System.out.println("value of name is:" + name); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/SpringTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import org.junit.Test; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author Ay 10 | * @date 2018/04/02 11 | */ 12 | @Service 13 | public class SpringTest { 14 | 15 | @Test 16 | public void testSpring() { 17 | ApplicationContext applicationContext = 18 | new ClassPathXmlApplicationContext("applicationContext.xml"); 19 | SpringTest springTest = (SpringTest) applicationContext.getBean("springTest"); 20 | springTest.sayHello(); 21 | 22 | } 23 | 24 | public void sayHello() { 25 | System.out.println("hello ay"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/test/com/ay/test/UserDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.ay.test; 2 | 3 | import com.ay.dao.UserDao; 4 | import com.ay.model.User; 5 | import org.junit.Test; 6 | 7 | import javax.annotation.Resource; 8 | import java.util.List; 9 | 10 | /** 11 | * 描述:用户DAO测试类 12 | * 13 | * @author Ay 14 | * @create 2018/05/04 15 | **/ 16 | public class UserDaoTest extends BaseJunit4Test { 17 | 18 | @Resource 19 | private UserDao userDao; 20 | 21 | @Test 22 | public void testFindAll() { 23 | User user = userDao.find("1"); 24 | System.out.println(user); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/error.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | 4 | 5 | 6 | Getting Started: Serving Web Content 7 | 8 | 9 | 10 | error !!! 11 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | 4 | 5 | 6 | Getting Started: Serving Web Content 7 | 8 | 9 | 10 | hello, ${name} 11 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/mood.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 5 | 6 | 7 | 8 | Getting Started: Serving Web Content 9 | 10 | 11 | 12 | 13 |
14 | 说说列表:
15 | 16 | ------------------------------------ 17 |
18 | 用户:${mood.userName}
19 | 说说内容:${mood.content}
20 | 发表时间: 21 | 22 | ${mood.publishTime} 23 |
24 | 点赞数:${mood.praiseNum}
25 |
26 | <%----%> 27 | 28 |
29 |
30 |
31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/saveUser.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | 4 | 5 | 6 | Getting Started: Serving Web Content 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
姓名:
密码:
年龄:
28 |
29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/success.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | 4 | 5 | 6 | Getting Started: Serving Web Content 7 | 8 | 9 | 10 | success !!! 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/updateUser.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 5 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 6 | 7 | 8 | 9 | Getting Started: Serving Web Content 10 | 11 | 12 | 13 | 14 |
员工信息更新

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
姓名
工号
职位
状态
离职原因
32 |
33 | 34 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/user.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | 4 | 5 | 6 | Getting Started: Serving Web Content 7 | 8 | 9 | 10 | success !!! 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/userIn.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 5 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 6 | 7 | 8 | 9 | Getting Started: Serving Web Content 10 | 11 | 12 | 13 | 14 |
新员工入职办理
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
姓名
工号
职位
30 |
31 | 32 |
33 | 34 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/userManage.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 5 | 6 | 7 | 8 | Getting Started: Serving Web Content 9 | 10 | 11 | 12 | 13 |
用户管理系统

14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 |
姓名工号职位状态操作
${user.name}${user.no}${user.position} ${user.status} 30 |
36 | 37 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/userOut.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 5 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 6 | 7 | 8 | 9 | Getting Started: Serving Web Content 10 | 11 | 12 | 13 | 14 |
员工离职办理

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
姓名
工号
职位
状态
离职原因
33 |
34 | 35 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | 9 | contextConfigLocation 10 | classpath:applicationContext.xml 11 | 12 | 13 | 14 | 15 | spring-dispatcher 16 | org.springframework.web.servlet.DispatcherServlet 17 | 18 | 19 | contextConfigLocation 20 | classpath:spring-mvc.xml 21 | 22 | 1 23 | 24 | 25 | spring-dispatcher 26 | 27 | / 28 | 29 | 30 | 31 | org.springframework.web.context.ContextLoaderListener 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | --------------------------------------------------------------------------------