├── .idea ├── .name ├── compiler.xml ├── encodings.xml ├── misc.xml ├── vcs.xml └── workspace.xml ├── README.md ├── image ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png ├── 18.png ├── 19.png ├── 2.png ├── 20.png ├── 21.png ├── 22.png ├── 23.png ├── 24.png ├── 25.png ├── 26.png ├── 27.png ├── 28.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── mr-entity ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── mrcoder │ │ │ └── mrentity │ │ │ ├── entity │ │ │ ├── master │ │ │ │ └── Student.java │ │ │ └── slave │ │ │ │ └── Teacher.java │ │ │ └── mapper │ │ │ ├── master │ │ │ └── StudentMapper.java │ │ │ └── slave │ │ │ └── TeacherMapper.java │ │ └── resources │ │ ├── generator │ │ ├── masterGenerator.xml │ │ └── slaveGenerator.xml │ │ └── mapper │ │ ├── master │ │ └── StudentMapper.xml │ │ └── slave │ │ └── TeacherMapper.xml └── target │ └── classes │ ├── com │ └── mrcoder │ │ └── mrentity │ │ ├── entity │ │ ├── master │ │ │ └── Student.class │ │ └── slave │ │ │ └── Teacher.class │ │ └── mapper │ │ ├── master │ │ └── StudentMapper.class │ │ └── slave │ │ └── TeacherMapper.class │ ├── generator │ ├── masterGenerator.xml │ └── slaveGenerator.xml │ └── mapper │ ├── master │ └── StudentMapper.xml │ └── slave │ └── TeacherMapper.xml ├── mr-service ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── mrcoder │ │ └── mrservice │ │ ├── RedisService.java │ │ ├── StudentService.java │ │ ├── TeacherService.java │ │ └── impl │ │ ├── StudentServiceImpl.java │ │ └── TeacherServiceImpl.java └── target │ └── classes │ └── com │ └── mrcoder │ └── mrservice │ ├── RedisService.class │ ├── StudentService.class │ ├── TeacherService.class │ └── impl │ ├── StudentServiceImpl.class │ └── TeacherServiceImpl.class ├── mr-utils ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── mrcoder │ │ └── mrutils │ │ └── redis │ │ └── RedisUtil.java └── target │ └── classes │ └── com │ └── mrcoder │ └── mrutils │ └── redis │ └── RedisUtil.class ├── pom.xml └── web-service ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── logs ├── logback_debug.log ├── logback_error.log ├── logback_info.log └── logback_warn.log ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── mrcoder │ │ │ └── webservice │ │ │ ├── WebServiceApplication.java │ │ │ ├── config │ │ │ ├── DruidConfig.java │ │ │ ├── MybatisConfig.java │ │ │ ├── RedisConfig.java │ │ │ ├── Swagger2Config.java │ │ │ ├── datasource │ │ │ │ ├── DataSourceConfig.java │ │ │ │ ├── MasterSqlSessionTemplateConfig.java │ │ │ │ ├── SlaveSqlSessionTemplateConfig.java │ │ │ │ └── TransactionManagerConfig.java │ │ │ └── wrapper │ │ │ │ ├── CustomWrapper.java │ │ │ │ └── MapWrapperFactory.java │ │ │ └── controller │ │ │ └── TestController.java │ └── resources │ │ ├── application.yml │ │ ├── jta.properties │ │ └── logback-spring.xml └── test │ └── java │ └── com │ └── mrcoder │ └── webservice │ └── WebServiceApplicationTests.java └── transaction-logs ├── springboot-mybatis.lck └── springboot-mybatis0.log /.idea/.name: -------------------------------------------------------------------------------- 1 | mrcoder-service -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Abstraction issuesJava 18 | 19 | 20 | Android 21 | 22 | 23 | Angular 24 | 25 | 26 | Assignment issuesJava 27 | 28 | 29 | Bitwise operation issuesJava 30 | 31 | 32 | Bitwise operation issuesJavaScript 33 | 34 | 35 | Class structureJava 36 | 37 | 38 | Cloning issuesJava 39 | 40 | 41 | Code style issuesJava 42 | 43 | 44 | Control flow issuesGroovy 45 | 46 | 47 | Control flow issuesJava 48 | 49 | 50 | Control flow issuesJavaScript 51 | 52 | 53 | CorrectnessLintAndroid 54 | 55 | 56 | Cucumber 57 | 58 | 59 | Declaration redundancyJava 60 | 61 | 62 | Dependency issuesJava 63 | 64 | 65 | EditorConfig 66 | 67 | 68 | Error handlingGroovy 69 | 70 | 71 | Error handlingJava 72 | 73 | 74 | Flow type checkerJavaScript 75 | 76 | 77 | General 78 | 79 | 80 | GeneralJavaScript 81 | 82 | 83 | Groovy 84 | 85 | 86 | IconsUsabilityLintAndroid 87 | 88 | 89 | ImportsJava 90 | 91 | 92 | Inheritance issuesJava 93 | 94 | 95 | InitializationJava 96 | 97 | 98 | Internationalization 99 | 100 | 101 | InternationalizationJava 102 | 103 | 104 | InternationalizationLintAndroid 105 | 106 | 107 | JUnitJava 108 | 109 | 110 | Java 111 | 112 | 113 | Java 5Java language level migration aidsJava 114 | 115 | 116 | Java 7Java language level migration aidsJava 117 | 118 | 119 | Java 8Java language level migration aidsJava 120 | 121 | 122 | Java 9Java language level migration aidsJava 123 | 124 | 125 | Java language level issuesJava 126 | 127 | 128 | Java language level migration aidsJava 129 | 130 | 131 | JavaScript 132 | 133 | 134 | JavaScript function metricsJavaScript 135 | 136 | 137 | JavadocJava 138 | 139 | 140 | Kotlin 141 | 142 | 143 | Kotlin Android 144 | 145 | 146 | Less 147 | 148 | 149 | LintAndroid 150 | 151 | 152 | MessagesCorrectnessLintAndroid 153 | 154 | 155 | MigrationKotlin 156 | 157 | 158 | Numeric issuesJava 159 | 160 | 161 | OSGi 162 | 163 | 164 | PerformanceJava 165 | 166 | 167 | PerformanceLintAndroid 168 | 169 | 170 | Plugin DevKit 171 | 172 | 173 | PortabilityJava 174 | 175 | 176 | Potentially confusing code constructsGroovy 177 | 178 | 179 | Potentially confusing code constructsJavaScript 180 | 181 | 182 | Probable bugsJava 183 | 184 | 185 | Probable bugsKotlin 186 | 187 | 188 | RegExp 189 | 190 | 191 | Resource managementJava 192 | 193 | 194 | Sass/SCSS 195 | 196 | 197 | SecurityLintAndroid 198 | 199 | 200 | Serialization issuesJava 201 | 202 | 203 | Spring 204 | 205 | 206 | Spring CoreSpring 207 | 208 | 209 | Style issuesKotlin 210 | 211 | 212 | Threading issuesGroovy 213 | 214 | 215 | Threading issuesJava 216 | 217 | 218 | TypeScript 219 | 220 | 221 | TypographyUsabilityLintAndroid 222 | 223 | 224 | UI Form 225 | 226 | 227 | UsabilityLintAndroid 228 | 229 | 230 | Verbose or redundant code constructsJava 231 | 232 | 233 | WebSocket 234 | 235 | 236 | XMLSpring CoreSpring 237 | 238 | 239 | XPath 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 18 | 19 | 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 | Van 46 | mj 47 | 48 | 49 | 50 | 52 | 53 | 59 | 65 | 66 | 67 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 16 | SELECT 17 | 18 | FROM student 19 | 20 | 21 | 27 | 28 | 29 | INSERT INTO 30 | student 31 | (age,grade,name) 32 | VALUES 33 | (#{age}, #{grade}, #{name}) 34 | 35 | 36 | 37 | UPDATE 38 | student 39 | SET 40 | age = #{age}, 41 | grade = #{grade}, 42 | name = #{name} 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM 49 | student 50 | WHERE 51 | id =#{id} 52 | 53 | 54 | -------------------------------------------------------------------------------- /mr-entity/src/main/resources/mapper/slave/TeacherMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id, name, age, course 13 | 14 | 15 | 20 | 21 | 27 | 28 | 29 | INSERT INTO 30 | teacher 31 | (age,course,name) 32 | VALUES 33 | (#{age}, #{course}, #{name}) 34 | 35 | 36 | 37 | UPDATE 38 | teacher 39 | SET 40 | age = #{age}, 41 | course = #{course}, 42 | name = #{name} 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM 49 | teacher 50 | WHERE 51 | id =#{id} 52 | 53 | 54 | -------------------------------------------------------------------------------- /mr-entity/target/classes/com/mrcoder/mrentity/entity/master/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-entity/target/classes/com/mrcoder/mrentity/entity/master/Student.class -------------------------------------------------------------------------------- /mr-entity/target/classes/com/mrcoder/mrentity/entity/slave/Teacher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-entity/target/classes/com/mrcoder/mrentity/entity/slave/Teacher.class -------------------------------------------------------------------------------- /mr-entity/target/classes/com/mrcoder/mrentity/mapper/master/StudentMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-entity/target/classes/com/mrcoder/mrentity/mapper/master/StudentMapper.class -------------------------------------------------------------------------------- /mr-entity/target/classes/com/mrcoder/mrentity/mapper/slave/TeacherMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-entity/target/classes/com/mrcoder/mrentity/mapper/slave/TeacherMapper.class -------------------------------------------------------------------------------- /mr-entity/target/classes/generator/masterGenerator.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 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 | 50 | 51 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 70 | 71 | -------------------------------------------------------------------------------- /mr-entity/target/classes/generator/slaveGenerator.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 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 | 49 | 50 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
69 | 70 | -------------------------------------------------------------------------------- /mr-entity/target/classes/mapper/master/StudentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id, name, age, grade 13 | 14 | 15 | 20 | 21 | 27 | 28 | 29 | INSERT INTO 30 | student 31 | (age,grade,name) 32 | VALUES 33 | (#{age}, #{grade}, #{name}) 34 | 35 | 36 | 37 | UPDATE 38 | student 39 | SET 40 | age = #{age}, 41 | grade = #{grade}, 42 | name = #{name} 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM 49 | student 50 | WHERE 51 | id =#{id} 52 | 53 | 54 | -------------------------------------------------------------------------------- /mr-entity/target/classes/mapper/slave/TeacherMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id, name, age, course 13 | 14 | 15 | 20 | 21 | 27 | 28 | 29 | INSERT INTO 30 | teacher 31 | (age,course,name) 32 | VALUES 33 | (#{age}, #{course}, #{name}) 34 | 35 | 36 | 37 | UPDATE 38 | teacher 39 | SET 40 | age = #{age}, 41 | course = #{course}, 42 | name = #{name} 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM 49 | teacher 50 | WHERE 51 | id =#{id} 52 | 53 | 54 | -------------------------------------------------------------------------------- /mr-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.mrcoder 6 | mr-service 7 | 0.0.1 8 | mr-service 9 | mr-service 10 | 11 | 12 | 13 | com.mrcoder 14 | mrcoder-service 15 | 1.0.0 16 | ../pom.xml 17 | 18 | 19 | 20 | 21 | com.mrcoder 22 | mr-entity 23 | 0.0.1 24 | 25 | 26 | com.mrcoder 27 | mr-utils 28 | 0.0.1 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /mr-service/src/main/java/com/mrcoder/mrservice/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrservice; 2 | 3 | import com.mrcoder.mrutils.redis.RedisUtil; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.core.StringRedisTemplate; 6 | import org.springframework.stereotype.Service; 7 | 8 | 9 | /** 10 | * redis 测试业务层 11 | */ 12 | @Service 13 | public class RedisService { 14 | 15 | @Autowired 16 | private StringRedisTemplate stringRedisTemplate; 17 | 18 | @Autowired 19 | private RedisUtil redisUtil;//内部封装了 RedisTemplate 20 | 21 | /** 22 | * 测试存储 String 类型数据 23 | */ 24 | public void setValue(String key, String string) { 25 | redisUtil.set(key, string); 26 | } 27 | 28 | /** 29 | * 测试读取 String 类型数据 30 | */ 31 | public Object getValue(String key) { 32 | boolean flag = redisUtil.hasKey(key); 33 | Object rs = null; 34 | if (flag) { 35 | rs = redisUtil.get(key); 36 | } 37 | return rs; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /mr-service/src/main/java/com/mrcoder/mrservice/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrservice; 2 | 3 | 4 | import com.mrcoder.mrentity.entity.master.Student; 5 | 6 | import java.util.List; 7 | 8 | public interface StudentService { 9 | 10 | public List getListByAnno(); 11 | 12 | public List getList(); 13 | 14 | public Student getById(Long id); 15 | 16 | public Integer save(Student s); 17 | 18 | public Integer update(Student s); 19 | 20 | public Integer delete(Long id); 21 | 22 | public void trans(int code); 23 | } 24 | -------------------------------------------------------------------------------- /mr-service/src/main/java/com/mrcoder/mrservice/TeacherService.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrservice; 2 | 3 | 4 | public class TeacherService { 5 | } 6 | -------------------------------------------------------------------------------- /mr-service/src/main/java/com/mrcoder/mrservice/impl/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrservice.impl; 2 | 3 | import com.mrcoder.mrentity.entity.master.Student; 4 | import com.mrcoder.mrentity.entity.slave.Teacher; 5 | import com.mrcoder.mrentity.mapper.master.StudentMapper; 6 | import com.mrcoder.mrentity.mapper.slave.TeacherMapper; 7 | import com.mrcoder.mrservice.StudentService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import java.util.List; 13 | 14 | @Service 15 | public class StudentServiceImpl implements StudentService { 16 | 17 | @Autowired 18 | private StudentMapper studentMapper; 19 | 20 | @Autowired 21 | private TeacherMapper teacherMapper; 22 | 23 | public List getListByAnno() { 24 | return studentMapper.getListByAnno(); 25 | } 26 | 27 | public List getList() { 28 | return studentMapper.getList(); 29 | } 30 | 31 | public Student getById(Long id) { 32 | return studentMapper.getById(id); 33 | } 34 | 35 | public Integer save(Student s) { 36 | return studentMapper.insert(s); 37 | } 38 | 39 | public Integer update(Student s) { 40 | return studentMapper.update(s); 41 | } 42 | 43 | public Integer delete(Long id) { 44 | return studentMapper.delete(id); 45 | } 46 | 47 | @Transactional 48 | public void trans(int code) { 49 | Student s1 = new Student(); 50 | s1.setAge(10); 51 | s1.setGrade(10); 52 | s1.setName("s1"); 53 | studentMapper.insert(s1); 54 | 55 | Teacher t1 = new Teacher(); 56 | t1.setAge(10); 57 | t1.setName("t1"); 58 | t1.setCourse(10); 59 | teacherMapper.insert(t1); 60 | int result = 1 / code; 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /mr-service/src/main/java/com/mrcoder/mrservice/impl/TeacherServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrservice.impl; 2 | 3 | public class TeacherServiceImpl { 4 | } 5 | -------------------------------------------------------------------------------- /mr-service/target/classes/com/mrcoder/mrservice/RedisService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-service/target/classes/com/mrcoder/mrservice/RedisService.class -------------------------------------------------------------------------------- /mr-service/target/classes/com/mrcoder/mrservice/StudentService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-service/target/classes/com/mrcoder/mrservice/StudentService.class -------------------------------------------------------------------------------- /mr-service/target/classes/com/mrcoder/mrservice/TeacherService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-service/target/classes/com/mrcoder/mrservice/TeacherService.class -------------------------------------------------------------------------------- /mr-service/target/classes/com/mrcoder/mrservice/impl/StudentServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-service/target/classes/com/mrcoder/mrservice/impl/StudentServiceImpl.class -------------------------------------------------------------------------------- /mr-service/target/classes/com/mrcoder/mrservice/impl/TeacherServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-service/target/classes/com/mrcoder/mrservice/impl/TeacherServiceImpl.class -------------------------------------------------------------------------------- /mr-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.mrcoder 6 | mr-utils 7 | 0.0.1 8 | mr-utils 9 | mr-utils 10 | 11 | 12 | com.mrcoder 13 | mrcoder-service 14 | 1.0.0 15 | ../pom.xml 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /mr-utils/src/main/java/com/mrcoder/mrutils/redis/RedisUtil.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.mrutils.redis; 2 | 3 | 4 | import org.springframework.data.redis.core.RedisTemplate; 5 | import org.springframework.util.CollectionUtils; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Set; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * @Description: redis 工具类 14 | */ 15 | public class RedisUtil { 16 | 17 | private RedisTemplate redisTemplate; 18 | 19 | public void setRedisTemplate(RedisTemplate redisTemplate) { 20 | this.redisTemplate = redisTemplate; 21 | } 22 | 23 | /** 24 | * 指定缓存失效时间 25 | * 26 | * @param key 键 27 | * @param time 时间(秒) 28 | * @return 29 | */ 30 | public boolean expire(String key, long time) { 31 | try { 32 | if (time > 0) { 33 | redisTemplate.expire(key, time, TimeUnit.SECONDS); 34 | } 35 | return true; 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | return false; 39 | } 40 | } 41 | 42 | /** 43 | * 根据key 获取过期时间 44 | * 45 | * @param key 键 不能为null 46 | * @return 时间(秒) 返回0代表为永久有效 47 | */ 48 | public long getExpire(String key) { 49 | return redisTemplate.getExpire(key, TimeUnit.SECONDS); 50 | } 51 | 52 | /** 53 | * 判断key是否存在 54 | * 55 | * @param key 键 56 | * @return true 存在 false不存在 57 | */ 58 | public boolean hasKey(String key) { 59 | try { 60 | return redisTemplate.hasKey(key); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | return false; 64 | } 65 | } 66 | 67 | /** 68 | * 删除缓存 69 | * 70 | * @param key 可以传一个值 或多个 71 | */ 72 | @SuppressWarnings("unchecked") 73 | public void del(String... key) { 74 | if (key != null && key.length > 0) { 75 | if (key.length == 1) { 76 | redisTemplate.delete(key[0]); 77 | } else { 78 | redisTemplate.delete(CollectionUtils.arrayToList(key)); 79 | } 80 | } 81 | } 82 | 83 | /** 84 | * 普通缓存获取 85 | * 86 | * @param key 键 87 | * @return 值 88 | */ 89 | public Object get(String key) { 90 | return key == null ? null : redisTemplate.opsForValue().get(key); 91 | } 92 | 93 | /** 94 | * 普通缓存放入 95 | * 96 | * @param key 键 97 | * @param value 值 98 | * @return true成功 false失败 99 | */ 100 | public boolean set(String key, Object value) { 101 | try { 102 | redisTemplate.opsForValue().set(key, value); 103 | return true; 104 | } catch (Exception e) { 105 | e.printStackTrace(); 106 | return false; 107 | } 108 | } 109 | 110 | /** 111 | * 普通缓存放入并设置时间 112 | * 113 | * @param key 键 114 | * @param value 值 115 | * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 116 | * @return true成功 false 失败 117 | */ 118 | public boolean set(String key, Object value, long time) { 119 | try { 120 | if (time > 0) { 121 | redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); 122 | } else { 123 | set(key, value); 124 | } 125 | return true; 126 | } catch (Exception e) { 127 | e.printStackTrace(); 128 | return false; 129 | } 130 | } 131 | 132 | /** 133 | * 递增 134 | * 135 | * @param key 键 136 | * @param delta 要增加几(大于0) 137 | * @return 138 | */ 139 | public long incr(String key, long delta) { 140 | if (delta < 0) { 141 | throw new RuntimeException("递增因子必须大于0"); 142 | } 143 | return redisTemplate.opsForValue().increment(key, delta); 144 | } 145 | 146 | /** 147 | * 递减 148 | * 149 | * @param key 键 150 | * @param delta 要减少几(小于0) 151 | * @return 152 | */ 153 | public long decr(String key, long delta) { 154 | if (delta < 0) { 155 | throw new RuntimeException("递减因子必须大于0"); 156 | } 157 | return redisTemplate.opsForValue().increment(key, -delta); 158 | } 159 | 160 | /** 161 | * HashGet 162 | * 163 | * @param key 键 不能为null 164 | * @param item 项 不能为null 165 | * @return 值 166 | */ 167 | public Object hget(String key, String item) { 168 | return redisTemplate.opsForHash().get(key, item); 169 | } 170 | 171 | /** 172 | * 获取hashKey对应的所有键值 173 | * 174 | * @param key 键 175 | * @return 对应的多个键值 176 | */ 177 | public Map hmget(String key) { 178 | return redisTemplate.opsForHash().entries(key); 179 | } 180 | 181 | /** 182 | * HashSet 183 | * 184 | * @param key 键 185 | * @param map 对应多个键值 186 | * @return true 成功 false 失败 187 | */ 188 | public boolean hmset(String key, Map map) { 189 | try { 190 | redisTemplate.opsForHash().putAll(key, map); 191 | return true; 192 | } catch (Exception e) { 193 | e.printStackTrace(); 194 | return false; 195 | } 196 | } 197 | 198 | /** 199 | * HashSet 并设置时间 200 | * 201 | * @param key 键 202 | * @param map 对应多个键值 203 | * @param time 时间(秒) 204 | * @return true成功 false失败 205 | */ 206 | public boolean hmset(String key, Map map, long time) { 207 | try { 208 | redisTemplate.opsForHash().putAll(key, map); 209 | if (time > 0) { 210 | expire(key, time); 211 | } 212 | return true; 213 | } catch (Exception e) { 214 | e.printStackTrace(); 215 | return false; 216 | } 217 | } 218 | 219 | /** 220 | * 向一张hash表中放入数据,如果不存在将创建 221 | * 222 | * @param key 键 223 | * @param item 项 224 | * @param value 值 225 | * @return true 成功 false失败 226 | */ 227 | public boolean hset(String key, String item, Object value) { 228 | try { 229 | redisTemplate.opsForHash().put(key, item, value); 230 | return true; 231 | } catch (Exception e) { 232 | e.printStackTrace(); 233 | return false; 234 | } 235 | } 236 | 237 | /** 238 | * 向一张hash表中放入数据,如果不存在将创建 239 | * 240 | * @param key 键 241 | * @param item 项 242 | * @param value 值 243 | * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 244 | * @return true 成功 false失败 245 | */ 246 | public boolean hset(String key, String item, Object value, long time) { 247 | try { 248 | redisTemplate.opsForHash().put(key, item, value); 249 | if (time > 0) { 250 | expire(key, time); 251 | } 252 | return true; 253 | } catch (Exception e) { 254 | e.printStackTrace(); 255 | return false; 256 | } 257 | } 258 | 259 | /** 260 | * 删除hash表中的值 261 | * 262 | * @param key 键 不能为null 263 | * @param item 项 可以使多个 不能为null 264 | */ 265 | public void hdel(String key, Object... item) { 266 | redisTemplate.opsForHash().delete(key, item); 267 | } 268 | 269 | /** 270 | * 判断hash表中是否有该项的值 271 | * 272 | * @param key 键 不能为null 273 | * @param item 项 不能为null 274 | * @return true 存在 false不存在 275 | */ 276 | public boolean hHasKey(String key, String item) { 277 | return redisTemplate.opsForHash().hasKey(key, item); 278 | } 279 | 280 | /** 281 | * hash递增 如果不存在,就会创建一个 并把新增后的值返回 282 | * 283 | * @param key 键 284 | * @param item 项 285 | * @param by 要增加几(大于0) 286 | * @return 287 | */ 288 | public double hincr(String key, String item, double by) { 289 | return redisTemplate.opsForHash().increment(key, item, by); 290 | } 291 | 292 | /** 293 | * hash递减 294 | * 295 | * @param key 键 296 | * @param item 项 297 | * @param by 要减少记(小于0) 298 | * @return 299 | */ 300 | public double hdecr(String key, String item, double by) { 301 | return redisTemplate.opsForHash().increment(key, item, -by); 302 | } 303 | 304 | /** 305 | * 根据key获取Set中的所有值 306 | * 307 | * @param key 键 308 | * @return 309 | */ 310 | public Set sGet(String key) { 311 | try { 312 | return redisTemplate.opsForSet().members(key); 313 | } catch (Exception e) { 314 | e.printStackTrace(); 315 | return null; 316 | } 317 | } 318 | 319 | /** 320 | * 根据value从一个set中查询,是否存在 321 | * 322 | * @param key 键 323 | * @param value 值 324 | * @return true 存在 false不存在 325 | */ 326 | public boolean sHasKey(String key, Object value) { 327 | try { 328 | return redisTemplate.opsForSet().isMember(key, value); 329 | } catch (Exception e) { 330 | e.printStackTrace(); 331 | return false; 332 | } 333 | } 334 | 335 | /** 336 | * 将数据放入set缓存 337 | * 338 | * @param key 键 339 | * @param values 值 可以是多个 340 | * @return 成功个数 341 | */ 342 | public long sSet(String key, Object... values) { 343 | try { 344 | return redisTemplate.opsForSet().add(key, values); 345 | } catch (Exception e) { 346 | e.printStackTrace(); 347 | return 0; 348 | } 349 | } 350 | 351 | /** 352 | * 将set数据放入缓存 353 | * 354 | * @param key 键 355 | * @param time 时间(秒) 356 | * @param values 值 可以是多个 357 | * @return 成功个数 358 | */ 359 | public long sSetAndTime(String key, long time, Object... values) { 360 | try { 361 | Long count = redisTemplate.opsForSet().add(key, values); 362 | if (time > 0) expire(key, time); 363 | return count; 364 | } catch (Exception e) { 365 | e.printStackTrace(); 366 | return 0; 367 | } 368 | } 369 | 370 | /** 371 | * 获取set缓存的长度 372 | * 373 | * @param key 键 374 | * @return 375 | */ 376 | public long sGetSetSize(String key) { 377 | try { 378 | return redisTemplate.opsForSet().size(key); 379 | } catch (Exception e) { 380 | e.printStackTrace(); 381 | return 0; 382 | } 383 | } 384 | 385 | /** 386 | * 移除值为value的 387 | * 388 | * @param key 键 389 | * @param values 值 可以是多个 390 | * @return 移除的个数 391 | */ 392 | public long setRemove(String key, Object... values) { 393 | try { 394 | Long count = redisTemplate.opsForSet().remove(key, values); 395 | return count; 396 | } catch (Exception e) { 397 | e.printStackTrace(); 398 | return 0; 399 | } 400 | } 401 | //===============================list================================= 402 | 403 | /** 404 | * 获取list缓存的内容 405 | * 406 | * @param key 键 407 | * @param start 开始 408 | * @param end 结束 0 到 -1代表所有值 409 | * @return 410 | */ 411 | public List lGet(String key, long start, long end) { 412 | try { 413 | return redisTemplate.opsForList().range(key, start, end); 414 | } catch (Exception e) { 415 | e.printStackTrace(); 416 | return null; 417 | } 418 | } 419 | 420 | /** 421 | * 获取list缓存的长度 422 | * 423 | * @param key 键 424 | * @return 425 | */ 426 | public long lGetListSize(String key) { 427 | try { 428 | return redisTemplate.opsForList().size(key); 429 | } catch (Exception e) { 430 | e.printStackTrace(); 431 | return 0; 432 | } 433 | } 434 | 435 | /** 436 | * 通过索引 获取list中的值 437 | * 438 | * @param key 键 439 | * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 440 | * @return 441 | */ 442 | public Object lGetIndex(String key, long index) { 443 | try { 444 | return redisTemplate.opsForList().index(key, index); 445 | } catch (Exception e) { 446 | e.printStackTrace(); 447 | return null; 448 | } 449 | } 450 | 451 | /** 452 | * 将list放入缓存 453 | * 454 | * @param key 键 455 | * @param value 值 456 | * @return 457 | */ 458 | public boolean lSet(String key, Object value) { 459 | try { 460 | redisTemplate.opsForList().rightPush(key, value); 461 | return true; 462 | } catch (Exception e) { 463 | e.printStackTrace(); 464 | return false; 465 | } 466 | } 467 | 468 | /** 469 | * 将list放入缓存 470 | * 471 | * @param key 键 472 | * @param value 值 473 | * @param time 时间(秒) 474 | * @return 475 | */ 476 | public boolean lSet(String key, Object value, long time) { 477 | try { 478 | redisTemplate.opsForList().rightPush(key, value); 479 | if (time > 0) expire(key, time); 480 | return true; 481 | } catch (Exception e) { 482 | e.printStackTrace(); 483 | return false; 484 | } 485 | } 486 | 487 | /** 488 | * 将list放入缓存 489 | * 490 | * @param key 键 491 | * @param value 值 492 | * @return 493 | */ 494 | public boolean lSet(String key, List value) { 495 | try { 496 | redisTemplate.opsForList().rightPushAll(key, value); 497 | return true; 498 | } catch (Exception e) { 499 | e.printStackTrace(); 500 | return false; 501 | } 502 | } 503 | 504 | /** 505 | * 将list放入缓存 506 | * 507 | * @param key 键 508 | * @param value 值 509 | * @param time 时间(秒) 510 | * @return 511 | */ 512 | public boolean lSet(String key, List value, long time) { 513 | try { 514 | redisTemplate.opsForList().rightPushAll(key, value); 515 | if (time > 0) expire(key, time); 516 | return true; 517 | } catch (Exception e) { 518 | e.printStackTrace(); 519 | return false; 520 | } 521 | } 522 | 523 | /** 524 | * 根据索引修改list中的某条数据 525 | * 526 | * @param key 键 527 | * @param index 索引 528 | * @param value 值 529 | * @return 530 | */ 531 | public boolean lUpdateIndex(String key, long index, Object value) { 532 | try { 533 | redisTemplate.opsForList().set(key, index, value); 534 | return true; 535 | } catch (Exception e) { 536 | e.printStackTrace(); 537 | return false; 538 | } 539 | } 540 | 541 | /** 542 | * 移除N个值为value 543 | * 544 | * @param key 键 545 | * @param count 移除多少个 546 | * @param value 值 547 | * @return 移除的个数 548 | */ 549 | public long lRemove(String key, long count, Object value) { 550 | try { 551 | Long remove = redisTemplate.opsForList().remove(key, count, value); 552 | return remove; 553 | } catch (Exception e) { 554 | e.printStackTrace(); 555 | return 0; 556 | } 557 | } 558 | } 559 | 560 | -------------------------------------------------------------------------------- /mr-utils/target/classes/com/mrcoder/mrutils/redis/RedisUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/mr-utils/target/classes/com/mrcoder/mrutils/redis/RedisUtil.class -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | com.mrcoder 8 | mrcoder-service 9 | 1.0.0 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.1.4.RELEASE 15 | 16 | 17 | 18 | pom 19 | 20 | mr-entity 21 | mr-service 22 | mr-utils 23 | web-service 24 | 25 | 26 | 27 | 28 | 1.8 29 | 2.1.4.RELEASE 30 | 2.0.0 31 | 1.1.16 32 | 8.0.11 33 | 1.4.7.RELEASE 34 | 1.2.57 35 | 1.3.2 36 | 2.6.1 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter 44 | ${sb.version} 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | ${sb.version} 51 | test 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-web 58 | ${sb.version} 59 | 60 | 61 | org.mybatis.spring.boot 62 | mybatis-spring-boot-starter 63 | ${mybatis.version} 64 | 65 | 66 | com.alibaba 67 | druid-spring-boot-starter 68 | ${druid.version} 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-starter-jta-atomikos 74 | ${sb.version} 75 | 76 | 77 | 78 | mysql 79 | mysql-connector-java 80 | ${mysql.version} 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-starter-aop 86 | ${sb.version} 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-starter-data-redis 92 | ${redis.version} 93 | 94 | 95 | 96 | com.alibaba 97 | fastjson 98 | ${fastjson.version} 99 | 100 | 101 | 102 | io.springfox 103 | springfox-swagger2 104 | ${swagger.version} 105 | 106 | 107 | io.springfox 108 | springfox-swagger-ui 109 | ${swagger.version} 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-compiler-plugin 120 | 3.8.0 121 | 122 | ${java.version} 123 | ${java.version} 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-surefire-plugin 129 | 130 | 131 | true 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /web-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /web-service/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if (mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if (mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if (!outputFile.getParentFile().exists()) { 87 | if (!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /web-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/web-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /web-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /web-service/logs/logback_debug.log: -------------------------------------------------------------------------------- 1 | 2019-04-29 15:28:17,178 DEBUG [main] c.m.w.WebServiceApplicationTests [StartupInfoLogger.java : 53] Running with Spring Boot v2.1.4.RELEASE, Spring v5.1.6.RELEASE 2 | -------------------------------------------------------------------------------- /web-service/logs/logback_error.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/web-service/logs/logback_error.log -------------------------------------------------------------------------------- /web-service/logs/logback_info.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/web-service/logs/logback_info.log -------------------------------------------------------------------------------- /web-service/logs/logback_warn.log: -------------------------------------------------------------------------------- 1 | 2019-04-29 15:28:20,216 WARN [main] c.a.icatch.provider.imp.AssemblerImp [Slf4jLogger.java : 24] Thanks for using Atomikos! Evaluate http://www.atomikos.com/Main/ExtremeTransactions for advanced features and professional support 2 | or register at http://www.atomikos.com/Main/RegisterYourDownload to disable this message and receive FREE tips & advice 3 | -------------------------------------------------------------------------------- /web-service/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /web-service/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /web-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.mrcoder 6 | web-service 7 | 0.0.1 8 | web-service 9 | web-service 10 | 11 | 12 | 13 | com.mrcoder 14 | mrcoder-service 15 | 1.0.0 16 | ../pom.xml 17 | 18 | 19 | 20 | 21 | 22 | com.mrcoder 23 | mr-entity 24 | 0.0.1 25 | 26 | 27 | com.mrcoder 28 | mr-utils 29 | 0.0.1 30 | 31 | 32 | com.mrcoder 33 | mr-service 34 | 0.0.1 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | com.mrcoder.webservice.WebServiceApplication 48 | ZIP 49 | 50 | 51 | 52 | 53 | repackage 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/WebServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan(basePackages = {"com.mrcoder"}) 9 | public class WebServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(WebServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/DruidConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config; 2 | 3 | 4 | import com.alibaba.druid.support.http.StatViewServlet; 5 | import com.alibaba.druid.support.http.WebStatFilter; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 10 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | /** 15 | * 配置 Druid登陆配置(白名单等) 16 | */ 17 | @Configuration 18 | public class DruidConfig { 19 | 20 | @Value("${spring.druid.name}") 21 | private String name; 22 | @Value("${spring.druid.pass}") 23 | private String pass; 24 | 25 | private Logger logger = LoggerFactory.getLogger(DruidConfig.class); 26 | 27 | /** 28 | * 配置 Druid控制台 白名单、黑名单、用户名、密码等 29 | * 访问地址 ip+port/projectContextPath/druid/index.html 30 | */ 31 | @Bean 32 | public ServletRegistrationBean DruidStatViewServlet() { 33 | logger.info("servletRegistrationBean configure is starting..."); 34 | //org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册. 35 | ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); 36 | //添加初始化参数 37 | servletRegistrationBean.addInitParameter("allow", "*"); 38 | servletRegistrationBean.addInitParameter("loginUsername", name); 39 | servletRegistrationBean.addInitParameter("loginPassword", pass); 40 | //是否可以重置 41 | servletRegistrationBean.addInitParameter("resetEnable", "false"); 42 | return servletRegistrationBean; 43 | } 44 | 45 | /** 46 | * 注册一个:filterRegistrationBean 47 | */ 48 | @Bean 49 | public FilterRegistrationBean druidStatFilter2() { 50 | logger.info("filterRegistrationBean configure is starting..."); 51 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); 52 | //添加过滤规则. 53 | filterRegistrationBean.addUrlPatterns("/*"); 54 | //添加不需要忽略的格式信息. 55 | filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); 56 | return filterRegistrationBean; 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/MybatisConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config; 2 | 3 | import com.mrcoder.webservice.config.wrapper.MapWrapperFactory; 4 | import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * mybatis配置类,将自定义的MapWrapperFactory覆盖默认的ObjectWrapperFactory 12 | */ 13 | @Configuration 14 | public class MybatisConfig { 15 | 16 | private Logger logger = LoggerFactory.getLogger(MybatisConfig.class); 17 | 18 | @Bean 19 | public ConfigurationCustomizer mybatisConfigurationCustomizer() { 20 | logger.info("initialize the ConfigurationCustomizer...."); 21 | return new ConfigurationCustomizer() { 22 | @Override 23 | public void customize(org.apache.ibatis.session.Configuration configuration) { 24 | configuration.setObjectWrapperFactory(new MapWrapperFactory()); 25 | } 26 | }; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 5 | import com.fasterxml.jackson.annotation.PropertyAccessor; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.mrcoder.mrutils.redis.RedisUtil; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Qualifier; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.data.redis.connection.RedisConnectionFactory; 14 | import org.springframework.data.redis.core.*; 15 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 16 | import org.springframework.data.redis.serializer.StringRedisSerializer; 17 | 18 | /** 19 | * @redis 配置类 20 | */ 21 | @Configuration 22 | public class RedisConfig { 23 | 24 | private Logger logger = LoggerFactory.getLogger(RedisConfig.class); 25 | 26 | @Bean 27 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) { 28 | RedisTemplate template = new RedisTemplate<>(); 29 | // 配置连接工厂 30 | template.setConnectionFactory(factory); 31 | 32 | //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式) 33 | Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); 34 | 35 | ObjectMapper om = new ObjectMapper(); 36 | // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public 37 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 38 | // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常 39 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 40 | jacksonSeial.setObjectMapper(om); 41 | 42 | // 值采用json序列化 43 | template.setValueSerializer(jacksonSeial); 44 | //使用StringRedisSerializer来序列化和反序列化redis的key值 45 | template.setKeySerializer(new StringRedisSerializer()); 46 | 47 | // 设置hash key 和value序列化模式 48 | template.setHashKeySerializer(new StringRedisSerializer()); 49 | template.setHashValueSerializer(jacksonSeial); 50 | template.afterPropertiesSet(); 51 | 52 | return template; 53 | } 54 | 55 | 56 | /** 57 | * 对hash类型的数据操作 58 | * 59 | * @param redisTemplate 60 | * @return 61 | */ 62 | @Bean 63 | public HashOperations hashOperations(RedisTemplate redisTemplate) { 64 | return redisTemplate.opsForHash(); 65 | } 66 | 67 | /** 68 | * 对redis字符串类型数据操作 69 | * 70 | * @param redisTemplate 71 | * @return 72 | */ 73 | @Bean 74 | public ValueOperations valueOperations(RedisTemplate redisTemplate) { 75 | return redisTemplate.opsForValue(); 76 | } 77 | 78 | /** 79 | * 对链表类型的数据操作 80 | * 81 | * @param redisTemplate 82 | * @return 83 | */ 84 | @Bean 85 | public ListOperations listOperations(RedisTemplate redisTemplate) { 86 | return redisTemplate.opsForList(); 87 | } 88 | 89 | /** 90 | * 对无序集合类型的数据操作 91 | * 92 | * @param redisTemplate 93 | * @return 94 | */ 95 | @Bean 96 | public SetOperations setOperations(RedisTemplate redisTemplate) { 97 | return redisTemplate.opsForSet(); 98 | } 99 | 100 | /** 101 | * 对有序集合类型的数据操作 102 | * 103 | * @param redisTemplate 104 | * @return 105 | */ 106 | @Bean 107 | public ZSetOperations zSetOperations(RedisTemplate redisTemplate) { 108 | return redisTemplate.opsForZSet(); 109 | } 110 | 111 | 112 | /** 113 | * 使用上面初始化的RedisTemplate实例来初始化一个RedisUtil对象 114 | * ps:@Qualifier("redisTemplate") 可以不用加,如果存在RedisTemplate实例,spring会默认注入 115 | */ 116 | @Bean 117 | public RedisUtil redisUtil(@Qualifier("redisTemplate") RedisTemplate redisTemplate) { 118 | RedisUtil redisUtil = new RedisUtil(); 119 | redisUtil.setRedisTemplate(redisTemplate); 120 | return redisUtil; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config; 2 | 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | /** 15 | * @Description: swagger2配置类 16 | */ 17 | @Configuration 18 | @EnableSwagger2 19 | public class Swagger2Config { 20 | 21 | @Bean 22 | public Docket createRestApi() { 23 | return new Docket(DocumentationType.SWAGGER_2) 24 | .apiInfo(apiInfo()) 25 | .select() 26 | .apis(RequestHandlerSelectors.basePackage("com.mrcoder.webservice.controller")) 27 | .paths(PathSelectors.any()) 28 | .build(); 29 | } 30 | 31 | private ApiInfo apiInfo() { 32 | return new ApiInfoBuilder() 33 | .title("SPRING-BOOT整合MYBATIS--API说明文档") 34 | .description("2019-04-26") 35 | .version("1.0.0") 36 | .license("署名-MrCoder") 37 | .build(); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/datasource/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.datasource; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.DependsOn; 10 | import org.springframework.context.annotation.Primary; 11 | import org.springframework.core.env.Environment; 12 | 13 | import javax.sql.DataSource; 14 | import java.util.Properties; 15 | 16 | /** 17 | * 数据源配置类 18 | */ 19 | @Configuration 20 | public class DataSourceConfig { 21 | 22 | @Autowired 23 | private Environment env; 24 | 25 | @Value("${spring.datasource.type}") 26 | private String dataSourceType; 27 | 28 | /** 29 | * 配置主数据源,多数据源中必须要使用@Primary指定一个主数据源 30 | * 其次DataSource里用的是DruidXADataSource ,而后注册到AtomikosDataSourceBean并且返回 31 | */ 32 | @Primary 33 | @Bean(name = "masterDataSource") 34 | @DependsOn({"txManager"}) 35 | public DataSource masterDataSource() { 36 | AtomikosDataSourceBean ds = new AtomikosDataSourceBean(); 37 | Properties prop = build(env, "spring.datasource.druid.master."); 38 | ds.setXaDataSourceClassName(dataSourceType); 39 | ds.setPoolSize(5); 40 | ds.setXaProperties(prop); 41 | return ds; 42 | } 43 | 44 | /** 45 | * 配置次数据源 46 | * 其次DataSource里用的是DruidXADataSource ,而后注册到AtomikosDataSourceBean并且返回 47 | */ 48 | @Bean(name = "slaveDataSource") 49 | @DependsOn({"txManager"}) 50 | public DataSource slaveDataSource() { 51 | AtomikosDataSourceBean ds = new AtomikosDataSourceBean(); 52 | Properties prop = build(env, "spring.datasource.druid.slave."); 53 | ds.setXaDataSourceClassName(dataSourceType); 54 | ds.setPoolSize(5); 55 | ds.setXaProperties(prop); 56 | return ds; 57 | } 58 | 59 | private Properties build(Environment env, String prefix) { 60 | Properties prop = new Properties(); 61 | prop.put("name", env.getProperty(prefix + "name")); 62 | prop.put("url", env.getProperty(prefix + "url")); 63 | prop.put("username", env.getProperty(prefix + "username")); 64 | prop.put("password", env.getProperty(prefix + "password")); 65 | prop.put("driverClassName", env.getProperty(prefix + "driverClassName", "")); 66 | prop.put("filters", env.getProperty(prefix + "filters")); 67 | prop.put("maxActive", env.getProperty(prefix + "maxActive", Integer.class)); 68 | prop.put("initialSize", env.getProperty(prefix + "initialSize", Integer.class)); 69 | prop.put("maxWait", env.getProperty(prefix + "maxWait", Integer.class)); 70 | prop.put("minIdle", env.getProperty(prefix + "minIdle", Integer.class)); 71 | prop.put("timeBetweenEvictionRunsMillis", 72 | env.getProperty(prefix + "timeBetweenEvictionRunsMillis", Integer.class)); 73 | prop.put("minEvictableIdleTimeMillis", env.getProperty(prefix + "minEvictableIdleTimeMillis", Integer.class)); 74 | prop.put("validationQuery", env.getProperty(prefix + "validationQuery")); 75 | prop.put("testWhileIdle", env.getProperty(prefix + "testWhileIdle", Boolean.class)); 76 | prop.put("testOnBorrow", env.getProperty(prefix + "testOnBorrow", Boolean.class)); 77 | prop.put("testOnReturn", env.getProperty(prefix + "testOnReturn", Boolean.class)); 78 | prop.put("poolPreparedStatements", env.getProperty(prefix + "poolPreparedStatements", Boolean.class)); 79 | prop.put("maxOpenPreparedStatements", env.getProperty(prefix + "maxOpenPreparedStatements", Integer.class)); 80 | return prop; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/datasource/MasterSqlSessionTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.datasource; 2 | 3 | 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Qualifier; 14 | import org.springframework.beans.factory.annotation.Value; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 18 | 19 | import javax.sql.DataSource; 20 | 21 | /** 22 | * MasterSqlSessionTemplateConfig配置类 23 | */ 24 | @Configuration 25 | //下面的sqlSessionTemplateRef 值需要和生成的SqlSessionTemplate bean name相同,如果没有指定name,那么就是方法名 26 | @MapperScan(basePackages = {"com.mrcoder.mrentity.mapper.master"}, sqlSessionTemplateRef = "masterSqlSessionTemplate") 27 | public class MasterSqlSessionTemplateConfig { 28 | 29 | @Value("${mybatis.mapper-locations}") 30 | private String mapper_location; 31 | 32 | @Value("${mybatis.type-aliases-package}") 33 | private String type_aliases_package; 34 | 35 | @Value("${mybatis.configuration.map-underscore-to-camel-case}") 36 | private boolean mapUnderscoreToCamelCase; 37 | 38 | //将MybatisConfig类中初始化的对象注入进来 39 | @Autowired 40 | private ConfigurationCustomizer customizer; 41 | 42 | private Logger logger = LoggerFactory.getLogger(MasterSqlSessionTemplateConfig.class); 43 | 44 | /** 45 | * 自定义sqlSessionFactory配置(因为没有用到MybatisAutoConfiguration自动配置类,需要手动配置) 46 | */ 47 | @Bean 48 | public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception { 49 | logger.info("mapper文件地址为:{}", mapper_location); 50 | //在基本的 MyBatis 中,session 工厂可以使用 SqlSessionFactoryBuilder 来创建。 51 | //而在 MyBatis-spring 中,则使用SqlSessionFactoryBean 来替代: 52 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 53 | bean.setDataSource(dataSource); 54 | //如果重写了 SqlSessionFactory 需要在初始化的时候手动将 mapper 地址 set到 factory 中,否则会报错: 55 | //org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 56 | bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapper_location)); 57 | //下面这个setTypeAliasesPackage无效,是mybatis集成springBoot的一个bug,暂时未能解决 58 | bean.setTypeAliasesPackage(type_aliases_package); 59 | org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); 60 | logger.info("mybatis配置驼峰转换为:{}", mapUnderscoreToCamelCase); 61 | configuration.setMapUnderscoreToCamelCase(mapUnderscoreToCamelCase); 62 | //因为没有用mybatis-springBoot自动装配,所以需要手动将configuration装配进去,要不然自定义的map key驼峰转换不起作用 63 | customizer.customize(configuration); 64 | bean.setConfiguration(configuration); 65 | return bean.getObject(); 66 | } 67 | 68 | /** 69 | * SqlSessionTemplate 是 SqlSession接口的实现类,是spring-mybatis中的,实现了SqlSession线程安全 70 | */ 71 | @Bean 72 | public SqlSessionTemplate masterSqlSessionTemplate(@Qualifier("masterSqlSessionFactory") SqlSessionFactory sqlSessionFactory) { 73 | SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory); 74 | return template; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/datasource/SlaveSqlSessionTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.datasource; 2 | 3 | 4 | import org.apache.ibatis.session.SqlSessionFactory; 5 | import org.mybatis.spring.SqlSessionFactoryBean; 6 | import org.mybatis.spring.SqlSessionTemplate; 7 | import org.mybatis.spring.annotation.MapperScan; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | 14 | import javax.sql.DataSource; 15 | 16 | /** 17 | * SlaveSqlSessionTemplateConfig配置类 18 | */ 19 | @Configuration 20 | @MapperScan(basePackages = {"com.mrcoder.mrentity.mapper.slave"}, sqlSessionTemplateRef = "slaveSqlSessionTemplate") 21 | public class SlaveSqlSessionTemplateConfig { 22 | 23 | @Value("${mybatis.mapper-locations}") 24 | private String mapper_location; 25 | 26 | @Bean 27 | public SqlSessionFactory slaveSqlSessionFactory(@Qualifier("slaveDataSource") DataSource dataSource) throws Exception { 28 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 29 | bean.setDataSource(dataSource); 30 | //如果重写了 SqlSessionFactory 需要在初始化的时候手动将 mapper 地址 set到 factory 中,否则会报错: 31 | //org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 32 | bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapper_location)); 33 | return bean.getObject(); 34 | } 35 | 36 | @Bean 37 | public SqlSessionTemplate slaveSqlSessionTemplate(@Qualifier("slaveSqlSessionFactory") SqlSessionFactory sqlSessionFactory) { 38 | SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory); 39 | return template; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/datasource/TransactionManagerConfig.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.datasource; 2 | 3 | 4 | import com.atomikos.icatch.jta.UserTransactionImp; 5 | import com.atomikos.icatch.jta.UserTransactionManager; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.DependsOn; 9 | import org.springframework.transaction.jta.JtaTransactionManager; 10 | 11 | import javax.transaction.TransactionManager; 12 | import javax.transaction.UserTransaction; 13 | 14 | /** 15 | * 多数据源事务管理器配置类 16 | */ 17 | @Configuration 18 | public class TransactionManagerConfig { 19 | 20 | /** 21 | * 分布式事务使用JTA管理,不管有多少个数据源只要配置一个 JtaTransactionManager 22 | * 23 | * @return 24 | */ 25 | @Bean(name = "atomikosTransactionManager", initMethod = "init", destroyMethod = "close") 26 | public TransactionManager atomikosTransactionManager() throws Throwable { 27 | UserTransactionManager userTransactionManager = new UserTransactionManager(); 28 | userTransactionManager.setForceShutdown(false); 29 | return userTransactionManager; 30 | } 31 | 32 | @Bean(name = "txManager") 33 | @DependsOn({ "userTransaction", "atomikosTransactionManager" }) 34 | public JtaTransactionManager transactionManager() throws Throwable { 35 | UserTransaction userTransaction = userTransaction(); 36 | TransactionManager atomikosTransactionManager = atomikosTransactionManager(); 37 | return new JtaTransactionManager(userTransaction, atomikosTransactionManager); 38 | } 39 | 40 | @Bean(name = "userTransaction") 41 | public UserTransaction userTransaction() throws Throwable { 42 | UserTransactionImp userTransactionImp = new UserTransactionImp(); 43 | userTransactionImp.setTransactionTimeout(10000); 44 | return userTransactionImp; 45 | } 46 | } -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/wrapper/CustomWrapper.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.wrapper; 2 | 3 | 4 | import com.google.common.base.CaseFormat; 5 | import org.apache.ibatis.reflection.MetaObject; 6 | import org.apache.ibatis.reflection.wrapper.MapWrapper; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * @Description: 自定义wrapper处理spring boot + mybatis返回结果为map时的key值转换为驼峰 12 | */ 13 | public class CustomWrapper extends MapWrapper { 14 | 15 | public CustomWrapper(MetaObject metaObject, Map map) { 16 | super(metaObject, map); 17 | } 18 | 19 | @Override 20 | public String findProperty(String name, boolean useCamelCaseMapping) { 21 | if (useCamelCaseMapping) { 22 | return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name); 23 | } 24 | return name; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/config/wrapper/MapWrapperFactory.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.config.wrapper; 2 | 3 | 4 | import org.apache.ibatis.reflection.MetaObject; 5 | import org.apache.ibatis.reflection.wrapper.ObjectWrapper; 6 | import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * 实现接口 ObjectWrapperFactory,通过包装工厂来创建自定义的wrapper 12 | */ 13 | public class MapWrapperFactory implements ObjectWrapperFactory { 14 | 15 | @Override 16 | public boolean hasWrapperFor(Object object) { 17 | return object != null && object instanceof Map; 18 | } 19 | 20 | @Override 21 | public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) { 22 | return new CustomWrapper(metaObject, (Map) object); 23 | } 24 | } -------------------------------------------------------------------------------- /web-service/src/main/java/com/mrcoder/webservice/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice.controller; 2 | 3 | import com.mrcoder.mrentity.entity.master.Student; 4 | import com.mrcoder.mrservice.RedisService; 5 | import com.mrcoder.mrservice.StudentService; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | 16 | 17 | @RestController 18 | @Api(value = "Test", description = "Test测试Controller") 19 | public class TestController { 20 | 21 | @Autowired 22 | private StudentService studentService; 23 | 24 | @Autowired 25 | private RedisService redisService; 26 | 27 | 28 | private Log logger = LogFactory.getLog(getClass()); 29 | 30 | @ApiOperation(value = "log测试接口", notes = "测试写level日志") 31 | @RequestMapping("log") 32 | public void testAll() { 33 | logger.info("====info"); 34 | logger.warn("====warn"); 35 | logger.error("====error"); 36 | } 37 | 38 | //列表查询 39 | @RequestMapping("getStudentList") 40 | public ResponseEntity> getStudentList() { 41 | return ResponseEntity.ok(studentService.getList()); 42 | } 43 | 44 | //列表查询 45 | @RequestMapping("getStudentListByAnno") 46 | public ResponseEntity> getStudentListByAnno() { 47 | return ResponseEntity.ok(studentService.getListByAnno()); 48 | } 49 | 50 | //新增 51 | @RequestMapping("addStudent") 52 | public int addStudent() { 53 | Student student = new Student(); 54 | student.setAge(1); 55 | student.setGrade(1); 56 | student.setName("student"); 57 | return studentService.save(student); 58 | } 59 | 60 | //更新 61 | @RequestMapping("updateStudent/{id}") 62 | public int updateStudent(@PathVariable(name = "id") Long id) { 63 | Student student = new Student(); 64 | student.setAge(10); 65 | student.setGrade(10); 66 | student.setName("update"); 67 | student.setId(id); 68 | return studentService.update(student); 69 | } 70 | 71 | //删除 72 | @RequestMapping("deleteStudent/{id}") 73 | public int deleteStudent(@PathVariable(name = "id") Long id) { 74 | return studentService.delete(id); 75 | } 76 | 77 | //事务 78 | @RequestMapping("transSuccess") 79 | public void transSuccess() { 80 | //人为制造0除异常测试事务分布式事务回滚 81 | studentService.trans(1); 82 | } 83 | 84 | //事务 85 | @RequestMapping("transRoll") 86 | public void transRoll() { 87 | //人为制造0除异常测试事务分布式事务回滚 88 | studentService.trans(0); 89 | } 90 | 91 | //redis string读写 92 | @RequestMapping(value = "/redis") 93 | public String redis() { 94 | 95 | redisService.setValue("test", "test123"); 96 | return redisService.getValue("test").toString(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /web-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | ## 公共配置start 2 | ## 配置数据源相关信息 3 | spring: 4 | ## 环境配置 5 | profiles: 6 | active: dev 7 | ## 数据源设置 8 | datasource: 9 | type: com.alibaba.druid.pool.xa.DruidXADataSource 10 | druid: 11 | ## 连接池配置 12 | master: 13 | ## JDBC配置 14 | name: master 15 | url: jdbc:mysql://192.168.145.131:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8 16 | username: root 17 | password: 123456 18 | driver-class-name: com.mysql.cj.jdbc.Driver 19 | filters: stat 20 | maxActive: 20 21 | initialSize: 1 22 | maxWait: 60000 23 | minIdle: 1 24 | timeBetweenEvictionRunsMillis: 60000 25 | minEvictableIdleTimeMillis: 300000 26 | validationQuery: select 'x' 27 | testWhileIdle: true 28 | testOnBorrow: true 29 | testOnReturn: true 30 | poolPreparedStatements: true 31 | maxOpenPreparedStatements: 20 32 | slave: 33 | ## JDBC配置 34 | name: slave 35 | url: jdbc:mysql://192.168.145.131:3306/test2?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8 36 | username: root 37 | password: 123456 38 | driver-class-name: com.mysql.cj.jdbc.Driver 39 | filters: stat 40 | maxActive: 20 41 | initialSize: 1 42 | maxWait: 60000 43 | minIdle: 1 44 | timeBetweenEvictionRunsMillis: 60000 45 | minEvictableIdleTimeMillis: 300000 46 | validationQuery: select 'x' 47 | testWhileIdle: true 48 | testOnBorrow: true 49 | testOnReturn: true 50 | poolPreparedStatements: true 51 | maxOpenPreparedStatements: 20 52 | 53 | redis: 54 | host: 127.0.0.1 # redis服务所在的地址 55 | port: 6379 56 | password: # redis的密码默认为空 57 | pool: 58 | max-active: 8 #连接池最大连接数(使用负值表示没有限制) 59 | max-idle: 8 #连接池最大空闲数 60 | min-idle: 1 #连接池最小空闲数 61 | max-wait: 60000 #获取连接的超时等待事件 62 | timeout: 30000 #连接redis服务器的最大等待时间 63 | 64 | #druid监控页面用户名和密码 65 | druid: 66 | name: admin 67 | pass: admin 68 | 69 | 70 | ## 该配置节点为独立的节点 71 | mybatis: 72 | mapper-locations: classpath:mapper/*/*.xml # 注意:一定要对应mapper映射xml文件的所在路径 73 | type-aliases-package: com.mrcoder.mrentity.entity # 注意:对应实体类的路径 74 | configuration: 75 | map-underscore-to-camel-case: true 76 | 77 | ## 公共配置 end 78 | 79 | 80 | --- 81 | ## 开发环境配置 82 | spring: 83 | profiles: dev 84 | server: 85 | port: 8080 86 | 87 | --- 88 | ## 测试环境配置 89 | spring: 90 | profiles: test 91 | server: 92 | port: 8082 93 | 94 | --- 95 | ## 生产环境配置 96 | spring: 97 | profiles: prod 98 | server: 99 | port: 8084 100 | -------------------------------------------------------------------------------- /web-service/src/main/resources/jta.properties: -------------------------------------------------------------------------------- 1 | com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory 2 | com.atomikos.icatch.max_timeout=600000 3 | com.atomikos.icatch.default_jta_timeout=600000 4 | com.atomikos.icatch.log_base_dir =transaction-logs 5 | com.atomikos.icatch.log_base_name=springboot-mybatis 6 | com.atomikos.icatch.serial_jta_transactions=false -------------------------------------------------------------------------------- /web-service/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | logback 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | debug 12 | 13 | 14 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 15 | 16 | 17 | 18 | 19 | 20 | logs/logback_debug.log 21 | 22 | 23 | ${path}/logback_debug.log.%d{yyyy-MM-dd}-%i.zip 24 | ${maxHistory} 25 | 27 | ${maxFileSize} 28 | 29 | 30 | 31 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 32 | 33 | 34 | 35 | DEBUG 36 | ACCEPT 37 | DENY 38 | 39 | 40 | 41 | 42 | logs/logback_info.log 43 | 44 | 45 | ${path}/logback_info.log.%d{yyyy-MM-dd}-%i.zip 46 | ${maxHistory} 47 | 49 | ${maxFileSize} 50 | 51 | 52 | 53 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 54 | 55 | 56 | 57 | INFO 58 | ACCEPT 59 | DENY 60 | 61 | 62 | 63 | 64 | logs/logback_warn.log 65 | 66 | 67 | ${path}/logback_warn.log.%d{yyyy-MM-dd}-%i.zip 68 | ${maxHistory} 69 | 71 | ${maxFileSize} 72 | 73 | 74 | 75 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 76 | 77 | 78 | 79 | WARN 80 | ACCEPT 81 | DENY 82 | 83 | 84 | 85 | 86 | 87 | logs/logback_error.log 88 | 89 | 90 | ${path}/logback_error.log.%d{yyyy-MM-dd}-%i.zip 91 | ${maxHistory} 92 | 94 | ${maxFileSize} 95 | 96 | 97 | 98 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 99 | 100 | 101 | 102 | ERROR 103 | ACCEPT 104 | DENY 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /web-service/src/test/java/com/mrcoder/webservice/WebServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.mrcoder.webservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class WebServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /web-service/transaction-logs/springboot-mybatis.lck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/web-service/transaction-logs/springboot-mybatis.lck -------------------------------------------------------------------------------- /web-service/transaction-logs/springboot-mybatis0.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrCoderStack/SpringBootFrame/be58b12c737a92223173a9e4df38789496eaff7c/web-service/transaction-logs/springboot-mybatis0.log --------------------------------------------------------------------------------