=UTF-8
7 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8 | org.eclipse.jdt.core.compiler.source=1.5
9 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.validation.prefs:
--------------------------------------------------------------------------------
1 | disabled=06target
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SSMM-Demo
2 |
3 | 本项目是一个基于 Spring MVC + Spring + Mybatis + Redis + Maven 的入门级(拥有完整的登录/注册逻辑)Demo,是在SSM-Demo项目的基础上修改、调整而来,主要涉及以下几项技术及知识点:
4 |
5 | - 使用SpringMVC作MVC控制器;
6 | - 使用Spring作IOC容器;
7 | - Spring AOP 的应用:日志模块的抽取、Redis查询缓存配置、声明式事务管理
8 | - Spring 声明式事务管理;
9 | - Spring CharacterEncodingFilter 过滤器;
10 | - 使用Mybatis作持久层(ORM)框架:以面向对象的方式对PO类的操作映射成为对应的持久化操作;
11 | - 使用Mybatis的Mapper映射器(Mappper接口);
12 | - 使用Maven进行项目构建和依赖管理;
13 | - MySQL作关系数据库,用于数据存储;
14 | - Redis作内存级别缓存(NoSQL数据库入门),以AOP形式配置到项目中;
15 | - Web 分层结构、模式及原理,以及各项流行技术的整合等。
16 |
17 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | cn.edu.tju
5 | SSMMDemo
6 | 0.0.1-SNAPSHOT
7 | war
8 | SSMMDemo
9 |
10 |
11 | UTF-8
12 |
13 |
14 |
15 |
16 | org.apache.openejb
17 | javaee-api
18 | 5.0-1
19 | provided
20 |
21 |
22 |
23 | javax.servlet.jsp
24 | jsp-api
25 | 2.1
26 | provided
27 |
28 |
29 |
30 | javax.servlet
31 | jstl
32 | 1.2
33 |
34 |
35 |
36 | org.springframework
37 | spring-webmvc
38 | 4.0.4.RELEASE
39 |
40 |
41 |
42 | org.aspectj
43 | aspectjrt
44 | 1.8.10
45 |
46 |
47 | org.aspectj
48 | aspectjweaver
49 | 1.8.10
50 |
51 |
52 |
53 | org.mybatis
54 | mybatis
55 | 3.3.1
56 |
57 |
58 |
59 | org.mybatis
60 | mybatis-spring
61 | 1.3.0
62 |
63 |
64 |
65 | org.springframework
66 | spring-tx
67 | 4.0.4.RELEASE
68 |
69 |
70 |
71 | commons-dbcp
72 | commons-dbcp
73 | 1.2.2
74 |
75 |
76 |
77 | log4j
78 | log4j
79 | 1.2.17
80 |
81 |
82 |
83 | mysql
84 | mysql-connector-java
85 | 5.1.29
86 |
87 |
88 |
89 | org.springframework
90 | spring-jdbc
91 | 4.0.4.RELEASE
92 |
93 |
94 |
95 |
96 | redis.clients
97 | jedis
98 | 2.8.0
99 |
100 |
101 |
102 |
103 |
104 |
105 | org.apache.tomcat.maven
106 | tomcat7-maven-plugin
107 | 2.1
108 |
109 |
110 | http://localhost:8080/manager/text
111 | tomcat7
112 | /${project.artifactId}
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/aspect/LogAspect.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.aspect;
2 |
3 | import java.util.Arrays;
4 | import java.util.Date;
5 |
6 | import javax.annotation.Resource;
7 |
8 | import org.aspectj.lang.ProceedingJoinPoint;
9 | import org.aspectj.lang.annotation.Around;
10 | import org.aspectj.lang.annotation.Aspect;
11 | import org.springframework.stereotype.Component;
12 |
13 | import cn.edu.tju.rico.mapper.LogMapper;
14 | import cn.edu.tju.rico.model.entity.Log;
15 |
16 | /**
17 | * Title: LogAspect.java
18 | * Description: 在控制台打印日志的切面类
19 | *
20 | * @author rico
21 | * @created 2017年4月24日 上午9:10:52
22 | */
23 | @Component
24 | // 由Spring来创建Aspect类
25 | @Aspect
26 | // 声明该类是一个切面
27 | public class LogAspect {
28 |
29 | private LogMapper logMapper;
30 |
31 | public LogMapper getLogMapper() {
32 | return logMapper;
33 | }
34 |
35 | @Resource
36 | public void setLogMapper(LogMapper logMapper) {
37 | this.logMapper = logMapper;
38 | }
39 |
40 | // Around Advice:可以修改目标方法的参数及返回值
41 | @Around("execution(* cn.edu.tju.rico.service.impl.UserServiceImpl.login(..))")
42 | public Object loginLog(ProceedingJoinPoint jp) throws Throwable {
43 | System.out.println("用户开始登录...");
44 |
45 | // 获取目标方法的参数
46 | Object[] args = jp.getArgs();
47 |
48 | // 获取目标方法的返回值
49 | Boolean rvt = (Boolean) jp.proceed(args);
50 |
51 | // 打印系统执行信息: 目标对象+目标方法
52 | System.out.println("系统正在执行方法: " + jp.getTarget().getClass().getName()
53 | + "." + jp.getSignature().getName());
54 |
55 | // 打印系统执行信息: 目标对象+目标方法
56 | System.out.println("传入方法的参数为: " + Arrays.toString(args));
57 |
58 | if (rvt.booleanValue() == true) {
59 | logMapper
60 | .saveLog(new Log(new Date(), "用户 " + args[0] + " 登录成功..."));
61 | } else {
62 | logMapper
63 | .saveLog(new Log(new Date(), "用户 " + args[0] + " 登录失败..."));
64 | }
65 |
66 | System.out.println("用户登录完毕... ");
67 |
68 | return rvt; // 将目标方法的返回值不做任何处理便返回
69 | }
70 |
71 | @Around("execution(* cn.edu.tju.rico.service.impl.UserServiceImpl.regist(..))")
72 | public Object registLog(ProceedingJoinPoint jp) throws Throwable {
73 | System.out.println("用户开始注册...");
74 |
75 | // 获取目标方法的参数
76 | Object[] args = jp.getArgs();
77 |
78 | // 获取目标方法的返回值
79 | Boolean rvt = (Boolean) jp.proceed(args);
80 |
81 | // 打印系统执行信息: 目标对象+目标方法
82 | System.out.println("系统正在执行方法: " + jp.getTarget().getClass().getName()
83 | + "." + jp.getSignature().getName());
84 |
85 | // 打印系统执行信息: 目标对象+目标方法
86 | System.out.println("传入方法的参数为: " + Arrays.toString(args));
87 |
88 | if (rvt.booleanValue() == true) {
89 | logMapper
90 | .saveLog(new Log(new Date(), "用户 " + args[0] + " 注册成功..."));
91 | } else {
92 | logMapper
93 | .saveLog(new Log(new Date(), "用户 " + args[0] + " 注册失败..."));
94 | }
95 |
96 | System.out.println("用户注册完毕...");
97 |
98 | return rvt; // 将目标方法的返回值不做任何处理便返回
99 | }
100 |
101 | @Around("execution(* cn.edu.tju.rico.service.impl.UserServiceImpl.getUser(..))")
102 | public Object selectUserLog(ProceedingJoinPoint jp) throws Throwable {
103 | System.out.println("开始查询指定用户信息...");
104 |
105 | // 获取目标方法的参数
106 | Object[] args = jp.getArgs();
107 |
108 | // 获取目标方法的返回值
109 | Object rvt = jp.proceed(args);
110 |
111 | // 打印系统执行信息: 目标对象+目标方法
112 | System.out.println("系统正在执行方法: " + jp.getTarget().getClass().getName()
113 | + "." + jp.getSignature().getName());
114 |
115 | // 打印系统执行信息: 目标对象+目标方法
116 | System.out.println("传入方法的参数为: " + Arrays.toString(args));
117 |
118 | if (rvt != null) {
119 | logMapper.saveLog(new Log(new Date(), "存在ID为 " + args[0]
120 | + " 的用户,查询成功..."));
121 | } else {
122 | logMapper.saveLog(new Log(new Date(), "不存在ID为 " + args[0]
123 | + " 的用户,查询失败..."));
124 | }
125 |
126 | System.out.println("查询指定用户信息完毕... ");
127 |
128 | return rvt; // 将目标方法的返回值不做任何处理便返回
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/aspect/RedisAspect.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.aspect;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.aspectj.lang.ProceedingJoinPoint;
6 | import org.aspectj.lang.annotation.Around;
7 | import org.aspectj.lang.annotation.Aspect;
8 | import org.springframework.stereotype.Component;
9 |
10 | import cn.edu.tju.rico.cache.RedisCache;
11 |
12 | /**
13 | * Title: Redis切面
14 | * Description:在查询数据库前先查询Redis,若查询失败,则穿透到数据库,并将从数据库查询到的数据保存至Redis,
15 | * 然后下次查询可直接命中Redis缓存.
16 | *
17 | * @author rico
18 | * @created 2017年6月27日 上午11:04:26
19 | */
20 | @Component
21 | @Aspect
22 | public class RedisAspect {
23 |
24 | private RedisCache redisCache;
25 |
26 | public RedisCache getRedisCache() {
27 | return redisCache;
28 | }
29 |
30 | @Resource(name = "redisCache")
31 | public void setRedisCache(RedisCache redisCache) {
32 | this.redisCache = redisCache;
33 | }
34 |
35 | @Around("execution(* cn.edu.tju.rico.service.impl.UserServiceImpl.getUser(..))")
36 | public Object around(ProceedingJoinPoint joinPoint) {
37 |
38 | System.out.println("先从Redis中查询数据...");
39 |
40 | // 获取目标方法参数
41 | int id = 0;
42 | Object[] args = joinPoint.getArgs();
43 | if (args != null && args.length > 0) {
44 | id = (Integer) args[0];
45 | }
46 |
47 | // Redis中Key的格式
48 | String redisKey = String.valueOf(id);
49 |
50 | // 前置:先到redis中查询缓存
51 | Object objectFromRedis = redisCache.getDataFromFromRedis(redisKey);
52 | if (null != objectFromRedis) { // 缓存命中
53 | System.out.println("从Redis中查询到了数据,不需要查询数据库...");
54 | return objectFromRedis;
55 | }
56 |
57 | // 缓存未命中
58 | System.out.println("没有从Redis中查到数据...");
59 |
60 | // 后置:从数据库中查询并将查询结果存入redis中
61 | Object object = null;
62 | try {
63 | object = joinPoint.proceed(); // 执行目标方法
64 | } catch (Throwable e) {
65 | e.printStackTrace();
66 | }
67 | System.out.println("从数据库中查询到数据...");
68 | System.out.println("将数据库查询结果存储到Redis中...");
69 | redisCache.setDatatoRedis(redisKey, object);
70 |
71 | return object;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/cache/RedisCache.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.cache;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.stereotype.Component;
6 |
7 | import cn.edu.tju.rico.util.SerializeUtil;
8 | import redis.clients.jedis.Jedis;
9 | import redis.clients.jedis.JedisPool;
10 |
11 | /**
12 | * Title: Redis 缓存存取
13 | * Description: 将数据保存到Redis或者将数据从Redis取出
14 | * @author rico
15 | * @created 2017年6月27日 上午11:09:19
16 | */
17 | @Component
18 | public class RedisCache {
19 |
20 | private JedisPool jedisPool;
21 |
22 | public JedisPool getJedisPool() {
23 | return jedisPool;
24 | }
25 |
26 | @Resource(name = "jedisPool")
27 | public void setJedisPool(JedisPool jedisPool) {
28 | this.jedisPool = jedisPool;
29 | }
30 |
31 | /**
32 | * @description 从Redis缓存中查询,反序列化
33 | * @author rico
34 | * @created 2017年6月27日 上午9:33:14
35 | * @param redisKey
36 | * @return
37 | */
38 | public Object getDataFromFromRedis(String redisKey){
39 |
40 | // 查询
41 | Jedis jedis = jedisPool.getResource();
42 | byte[] result = jedis.get(redisKey.getBytes());
43 | // 查询为空,Redis中不包含目标数据
44 | if (null == result) {
45 | return null;
46 | }
47 |
48 | // 查询到结果,反序列化
49 | return SerializeUtil.unSerialize(result);
50 | }
51 |
52 |
53 | /**
54 | * @description 将数据库的查询结果放入Redis,序列化
55 | * @author rico
56 | * @created 2017年6月27日 上午9:32:36
57 | * @param redisKey
58 | * @param obj
59 | */
60 | public void setDatatoRedis(String redisKey, Object obj){
61 |
62 | // 序列化
63 | byte[] bytes = SerializeUtil.serialize(obj);
64 |
65 | // 存入Redis
66 | Jedis jedis = jedisPool.getResource();
67 | String success = jedis.set(redisKey.getBytes(), bytes);
68 |
69 | if ("OK".equals(success)) {
70 | System.out.println("数据成功保存到缓存Redis...");
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/controller/ChoiceController.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | /**
7 | * Title: ChoiceController
8 | * Description: 处理去应用首页、去登录和去注册三个请求
9 | * @author rico
10 | * @created 2017年6月12日 下午12:02:14
11 | */
12 | @Controller
13 | @RequestMapping("/choice")
14 | public class ChoiceController {
15 |
16 | @RequestMapping("/choose")
17 | public String choose() {
18 | return "index"; // 逻辑视图,返回首页
19 | }
20 |
21 | @RequestMapping("/tologin")
22 | public String goLogin() {
23 | return "login"; // 逻辑视图,登录页面
24 | }
25 |
26 | @RequestMapping("/toregist")
27 | public String goRegist() {
28 | return "regist"; // 逻辑视图,注册页面
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/controller/LoginController.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.controller;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.Model;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.SessionAttributes;
11 |
12 | import cn.edu.tju.rico.service.UserService;
13 |
14 | /**
15 | * Title: LoginController
16 | * Description: 处理登录请求
17 | * @author rico
18 | * @created 2017年6月12日 下午12:05:46
19 | */
20 | @Controller
21 | @SessionAttributes("uname") // 将uname放到HttpSession当中
22 | public class LoginController {
23 |
24 | private UserService userService;
25 |
26 | public UserService getUserService() {
27 | return userService;
28 | }
29 |
30 | @Resource(name = "userService")
31 | public void setUserService(UserService userService) {
32 | this.userService = userService;
33 | }
34 |
35 | @RequestMapping(value = "/login", method=RequestMethod.POST)
36 | public String login(@RequestParam("uname") String uname,
37 | @RequestParam("passwd") String passwd, Model model) {
38 | boolean flag = userService.login(uname, passwd);
39 | if (flag) { // 若登录验证成功,则将uname放入HttpSession中,并转到"欢迎页"
40 | model.addAttribute("uname", uname);
41 | return "welcome"; // 逻辑视图,转向欢迎页面
42 | }
43 | return "login"; // 逻辑视图,依然转向登录页面
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/controller/RegistController.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.controller;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 |
9 | import cn.edu.tju.rico.dto.UserDTO;
10 | import cn.edu.tju.rico.service.UserService;
11 |
12 | /**
13 | * Title: RegistController
14 | * Description: 处理用户的注册请求
15 | * @author rico
16 | * @created 2017年6月12日 上午11:57:42
17 | */
18 | @Controller
19 | public class RegistController {
20 |
21 | private UserService userService;
22 |
23 | public UserService getUserService() {
24 | return userService;
25 | }
26 |
27 | @Resource(name = "userService")
28 | public void setUserService(UserService userService) {
29 | this.userService = userService;
30 | }
31 |
32 | @RequestMapping(value = "/regist", method = RequestMethod.POST)
33 | public String regist(UserDTO userDto){ // HandlerAdaptor将form表单中的各属性映射到userDto对象中
34 | System.out.println(userDto);
35 | boolean flag = userService.regist(userDto);
36 | return flag ? "login" : "regist"; // 根据注册结果,转向特定页面
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/controller/UserQueryController.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.controller;
2 |
3 | import javax.annotation.Resource;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.servlet.ModelAndView;
8 |
9 | import cn.edu.tju.rico.model.entity.User;
10 | import cn.edu.tju.rico.service.UserService;
11 |
12 | /**
13 | * Title: UserQueryController
14 | * Description: 处理查看指定用户ID的用户信息请求
15 | * @author rico
16 | * @created 2017年4月24日 上午9:07:29
17 | */
18 | @Controller
19 | public class UserQueryController {
20 |
21 | private UserService userService;
22 |
23 | public UserService getUserService() {
24 | return userService;
25 | }
26 |
27 | @Resource(name="userService")
28 | public void setUserService(UserService userService) {
29 | this.userService = userService;
30 | }
31 |
32 | @RequestMapping("/query")
33 | public ModelAndView showUser(@RequestParam("id") int id){
34 | long start = System.currentTimeMillis();
35 |
36 | ModelAndView mv = new ModelAndView();
37 | User user = (User) userService.getUser(id);
38 | System.out.println(user);
39 | if (user != null) {
40 | mv.addObject("user", user);
41 | }else{
42 | mv.addObject("tip", "不存在此用户...");
43 | }
44 | mv.setViewName("show"); // 设定逻辑视图
45 | long end = System.currentTimeMillis();
46 | System.out.println("耗时 : " + (end - start));
47 | return mv;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/dto/UserDTO.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.dto;
2 |
3 | /**
4 | * Title: UserDTO.java
5 | * Description: DTO(Data Transfer Object),用于传值,
6 | * 与domain/entity/po/bean不同的是DTO不作持久化(包含确认密码的User)
7 | * @author rico
8 | * @created 2017年4月24日 上午9:24:16
9 | */
10 | public class UserDTO {
11 |
12 | private String uname;
13 | private String passwd;
14 | private String passwd1;
15 | private String gentle;
16 | private String email;
17 | private String city;
18 |
19 | public String getUname() {
20 | return uname;
21 | }
22 |
23 | public void setUname(String uname) {
24 | this.uname = uname;
25 | }
26 |
27 | public String getPasswd() {
28 | return passwd;
29 | }
30 |
31 | public void setPasswd(String passwd) {
32 | this.passwd = passwd;
33 | }
34 |
35 | public String getGentle() {
36 | return gentle;
37 | }
38 |
39 | public void setGentle(String gentle) {
40 | this.gentle = gentle;
41 | }
42 |
43 | public String getEmail() {
44 | return email;
45 | }
46 |
47 | public void setEmail(String email) {
48 | this.email = email;
49 | }
50 |
51 | public String getCity() {
52 | return city;
53 | }
54 |
55 | public void setCity(String city) {
56 | this.city = city;
57 | }
58 |
59 | public String getPasswd1() {
60 | return passwd1;
61 | }
62 |
63 | public void setPasswd1(String passwd1) {
64 | this.passwd1 = passwd1;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "UserDTO [uname=" + uname + ", passwd=" + passwd + ", passwd1="
70 | + passwd1 + ", gentle=" + gentle + ", email=" + email
71 | + ", city=" + city + "]";
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/mapper/LogMapper.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.mapper;
2 |
3 | import org.apache.ibatis.annotations.Insert;
4 | import org.apache.ibatis.annotations.Options;
5 |
6 | import cn.edu.tju.rico.model.entity.Log;
7 |
8 |
9 | /**
10 | * Title: Log PO类与SQL的映射关系
11 | * Description: 以面向对象的方式对PO类Log的操作映射成为对应的持久化操作
12 | * @author rico
13 | * @created 2017年6月12日 下午12:09:34
14 | */
15 | public interface LogMapper {
16 |
17 | /**
18 | * @description 将日志持久化到数据库中
19 | * @author rico
20 | * @created 2017年6月12日 下午12:15:33
21 | * @param log
22 | */
23 | @Insert("insert into log_inf(date,msg) values (#{date,jdbcType=TIMESTAMP},#{msg})")
24 | @Options(useGeneratedKeys=true, keyProperty="id") // 自动生成主键
25 | public void saveLog(Log log);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.mapper;
2 |
3 | import org.apache.ibatis.annotations.Insert;
4 | import org.apache.ibatis.annotations.Options;
5 | import org.apache.ibatis.annotations.Param;
6 | import org.apache.ibatis.annotations.Select;
7 |
8 | import cn.edu.tju.rico.model.entity.User;
9 |
10 |
11 | /**
12 | * Title: User PO类与SQL的映射关系
13 | * Description: 以面向对象的方式对PO类User的操作映射成为对应的持久化操作
14 | * @author rico
15 | * @created 2017年6月12日 下午12:09:34
16 | */
17 | public interface UserMapper {
18 |
19 |
20 | /**
21 | * @description 根据指定的uname,passwd查询用户
22 | * @author rico
23 | * @created 2017年6月12日 下午12:18:31
24 | * @param uname
25 | * @param passwd
26 | * @return
27 | */
28 | @Select("select * from user_inf where uname = #{uname} and passwd = #{passwd}")
29 | public User findUserByUnameAndPasswd(@Param("uname") String uname,
30 | @Param("passwd") String passwd);
31 |
32 |
33 | /**
34 | * @description 持久化用户,向数据库插入一条用户记录
35 | * @author rico
36 | * @created 2017年6月12日 下午12:19:01
37 | * @param user
38 | */
39 | @Insert("insert into user_inf(uname, passwd, gentle, email, city) values (#{uname},#{passwd},#{gentle},#{email},#{city})")
40 | @Options(useGeneratedKeys = true, keyProperty="id")
41 | public void saveUser(User user);
42 |
43 |
44 | /**
45 | * @description 根据指定的uname查询用户
46 | * @author rico
47 | * @created 2017年6月12日 下午12:19:24
48 | * @param uname
49 | * @return
50 | */
51 | @Select("select * from user_inf where uname = #{uname}")
52 | public User findUserByUname(@Param("uname") String uname);
53 |
54 |
55 | /**
56 | * @description 根据指定的id查询用户
57 | * @author rico
58 | * @created 2017年6月12日 下午12:19:40
59 | * @param id
60 | * @return
61 | */
62 | @Select("select * from user_inf where id = #{id}")
63 | public User findUserById(@Param("id") int id);
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/model/entity/Log.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.model.entity;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Title: Log.java
7 | * Description: 日志实体,用于持久化
8 | * @author rico
9 | * @created 2017年4月24日 上午9:26:42
10 | */
11 | public class Log {
12 |
13 | private int id;
14 | private Date date;
15 | private String msg;
16 |
17 | public Log() {
18 | super();
19 | }
20 |
21 | public Log(Date date, String msg) {
22 | super();
23 | this.date = date;
24 | this.msg = msg;
25 | }
26 |
27 | public int getId() {
28 | return id;
29 | }
30 |
31 | public void setId(int id) {
32 | this.id = id;
33 | }
34 |
35 | public Date getDate() {
36 | return date;
37 | }
38 |
39 | public void setDate(Date date) {
40 | this.date = date;
41 | }
42 |
43 | public String getMsg() {
44 | return msg;
45 | }
46 |
47 | public void setMsg(String msg) {
48 | this.msg = msg;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Log [date=" + date + ", msg=" + msg + "]";
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/model/entity/User.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.model.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | import cn.edu.tju.rico.dto.UserDTO;
6 |
7 | /**
8 | * Title: User.java
9 | * Description: 用户实体,用于持久化
10 | * @author rico
11 | * @created 2017年4月24日 上午9:27:16
12 | */
13 | public class User implements Serializable{
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | private int id;
18 | private String uname;
19 | private String passwd;
20 | private String gentle;
21 | private String email;
22 | private String city;
23 |
24 | public User() {
25 | super();
26 | }
27 |
28 | /**
29 | * 构造函数
30 | * @description 用DTO构建Entity
31 | * @author rico
32 | * @created 2017年4月24日 上午9:27:34
33 | * @param userDTO
34 | */
35 | public User(UserDTO userDTO) {
36 | this.uname = userDTO.getUname();
37 | this.passwd = userDTO.getPasswd();
38 | this.gentle = userDTO.getGentle();
39 | this.email = userDTO.getEmail();
40 | this.city = userDTO.getCity();
41 | }
42 |
43 | public int getId() {
44 | return id;
45 | }
46 |
47 | public void setId(int id) {
48 | this.id = id;
49 | }
50 |
51 | public String getUname() {
52 | return uname;
53 | }
54 |
55 | public void setUname(String uname) {
56 | this.uname = uname;
57 | }
58 |
59 | public String getPasswd() {
60 | return passwd;
61 | }
62 |
63 | public void setPasswd(String passwd) {
64 | this.passwd = passwd;
65 | }
66 |
67 | public String getGentle() {
68 | return gentle;
69 | }
70 |
71 | public void setGentle(String gentle) {
72 | this.gentle = gentle;
73 | }
74 |
75 | public String getEmail() {
76 | return email;
77 | }
78 |
79 | public void setEmail(String email) {
80 | this.email = email;
81 | }
82 |
83 | public String getCity() {
84 | return city;
85 | }
86 |
87 | public void setCity(String city) {
88 | this.city = city;
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return "User [id=" + id + ", uname=" + uname + ", gentle=" + gentle
94 | + ", email=" + email + ", city=" + city + "]";
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/service/LogService.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.service;
2 |
3 | import cn.edu.tju.rico.model.entity.Log;
4 |
5 |
6 | /**
7 | * Title: LogService.java
8 | * Description: 对日志相关的业务逻辑的抽象(面向接口编程)
9 | * @author rico
10 | * @created 2017年4月24日 上午9:28:54
11 | */
12 | public interface LogService {
13 |
14 | /**
15 | * @description 日志保存
16 | * @author rico
17 | * @created 2017年4月24日 上午9:29:36
18 | * @param log
19 | */
20 | public void addLog(Log log);
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/service/UserService.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.service;
2 |
3 | import cn.edu.tju.rico.dto.UserDTO;
4 | import cn.edu.tju.rico.model.entity.User;
5 |
6 | /**
7 | * Title: UserService.java
8 | * Description: 对用户相关的业务逻辑的抽象(面向接口编程)
9 | * @author rico
10 | * @created 2017年4月24日 上午9:28:09
11 | */
12 | public interface UserService {
13 |
14 |
15 | /**
16 | * @description 用户登录逻辑
17 | * @author rico
18 | * @created 2017年4月24日 上午9:29:48
19 | * @param uname
20 | * @param passwd
21 | * @return
22 | */
23 | public boolean login(String uname, String passwd);
24 |
25 |
26 | /**
27 | * @description 用户注册逻辑
28 | * @author rico
29 | * @created 2017年4月24日 上午9:30:02
30 | * @param userDto
31 | * @return
32 | */
33 | public boolean regist(UserDTO userDto);
34 |
35 |
36 | /**
37 | * @description 用户获取逻辑
38 | * @author rico
39 | * @created 2017年4月24日 上午9:30:15
40 | * @param id
41 | * @return
42 | */
43 | public Object getUser(int id);
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/service/impl/LogServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.service.impl;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.stereotype.Component;
6 |
7 | import cn.edu.tju.rico.mapper.LogMapper;
8 | import cn.edu.tju.rico.model.entity.Log;
9 | import cn.edu.tju.rico.service.LogService;
10 |
11 | /**
12 | * Title: LogServiceImpl.java
13 | * Description: LogService 的逻辑实现类
14 | * @author rico
15 | * @created 2017年4月24日 上午9:30:33
16 | */
17 | @Component("logService")
18 | public class LogServiceImpl implements LogService{
19 |
20 | /** 由Spring容器管理 (@author: rico) */
21 | private LogMapper logMapper;
22 |
23 | public LogMapper getLogMapper() {
24 | return logMapper;
25 | }
26 |
27 | @Resource
28 | public void setLogMapper(LogMapper logMapper) {
29 | this.logMapper = logMapper;
30 | }
31 |
32 |
33 |
34 | /**
35 | * @description 日志保存
36 | * @author rico
37 | * @created 2017年4月24日 上午9:31:19
38 | * @param log
39 | * @see cn.edu.tju.rico.service.LogService#add(cn.edu.tju.rico.model.entity.Log)
40 | */
41 | public void addLog(Log log) {
42 | // TODO Auto-generated method stub
43 | logMapper.saveLog(log);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/service/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.service.impl;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.transaction.annotation.Isolation;
7 | import org.springframework.transaction.annotation.Propagation;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | import cn.edu.tju.rico.dto.UserDTO;
11 | import cn.edu.tju.rico.mapper.UserMapper;
12 | import cn.edu.tju.rico.model.entity.User;
13 | import cn.edu.tju.rico.service.UserService;
14 |
15 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
16 | @Component("userService")
17 | public class UserServiceImpl implements UserService {
18 |
19 | private UserMapper userMapper;
20 |
21 | public UserMapper getUserMapper() {
22 | return userMapper;
23 | }
24 |
25 | @Resource
26 | // 默认按名称(userMapper)注入,若名称匹配失败,则按照类型匹配
27 | public void setUserMapper(UserMapper userMapper) {
28 | this.userMapper = userMapper;
29 | }
30 |
31 | /**
32 | * @description 登录逻辑的具体实现,对应事务包括用户的查询和日志的插入两部分
33 | * @author rico
34 | * @created 2017年4月24日 上午9:34:07
35 | * @param uname
36 | * @param passwd
37 | * @return 用户名、密码匹配成功,返回true;否则,返回false;
38 | * @see cn.edu.tju.rico.service.UserService#login(java.lang.String,
39 | * java.lang.String)
40 | */
41 | @Transactional(readOnly = false) //必须设置为false,因为此处切入了日志的保存逻辑
42 | public boolean login(String uname, String passwd) {
43 | // TODO Auto-generated method stub
44 | User user = userMapper.findUserByUnameAndPasswd(uname, passwd);
45 | return user == null ? false : true;
46 | }
47 |
48 | /**
49 | * @description 用户注册逻辑的具体实现
50 | * @author rico
51 | * @created 2017年6月12日 下午12:21:45
52 | * @param userDto
53 | * @return
54 | * @see cn.edu.tju.rico.service.UserService#regist(cn.edu.tju.rico.dto.UserDTO)
55 | */
56 | @Transactional(readOnly = false) //必须设置为false,因为此处切入了日志的保存逻辑
57 | public boolean regist(UserDTO userDto) {
58 | if (!userDto.getPasswd().equals(userDto.getPasswd1())
59 | || userMapper.findUserByUname(userDto.getUname()) != null) {
60 | return false;
61 | } else {
62 | User user = new User(userDto);
63 | userMapper.saveUser(user);
64 | return true;
65 | }
66 | }
67 |
68 | /**
69 | * @description 用户获取逻辑的具体实现
70 | * @author rico
71 | * @created 2017年6月12日 下午12:22:00
72 | * @param id
73 | * @return
74 | * @see cn.edu.tju.rico.service.UserService#getUser(int)
75 | */
76 |
77 | @Transactional(readOnly = false) //必须设置为false,因为此处切入了日志的保存逻辑
78 | public Object getUser(int id) {
79 | // TODO Auto-generated method stub
80 | return userMapper.findUserById(id);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/test/Test.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.test;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 |
7 | import org.springframework.core.io.DefaultResourceLoader;
8 | import org.springframework.core.io.Resource;
9 | import org.springframework.core.io.ResourceLoader;
10 | import org.springframework.core.io.UrlResource;
11 |
12 | public class Test {
13 | public static void main(String[] args) throws IOException {
14 | ResourceLoader resloLoader = new DefaultResourceLoader();
15 | Resource res = resloLoader
16 | .getResource("https://www.baidu.com/");
17 | System.out.println(res instanceof UrlResource); // true
18 | BufferedReader bf = new BufferedReader(new InputStreamReader(res.getInputStream()));
19 | StringBuilder sb = new StringBuilder();
20 | String temp = null;
21 | while ((temp = bf.readLine())!= null) {
22 | sb.append(temp);
23 | }
24 | System.out.println(sb.toString());
25 | System.out.println("\n-----------------------------\n");
26 | res = resloLoader.getResource("classpath:test.txt");
27 | bf = new BufferedReader(new InputStreamReader(res.getInputStream()));
28 | sb = new StringBuilder();
29 | temp = null;
30 | while ((temp = bf.readLine())!= null) {
31 | sb.append(temp);
32 | }
33 | System.out.println(sb.toString());
34 | System.out.println("\n-----------------------------\n");
35 | res = resloLoader.getResource("file:C:\\Users\\ricco\\Desktop\\test\\test.txt");
36 | bf = new BufferedReader(new InputStreamReader(res.getInputStream()));
37 | sb = new StringBuilder();
38 | temp = null;
39 | while ((temp = bf.readLine())!= null) {
40 | sb.append(temp);
41 | }
42 | System.out.println(sb.toString());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/cn/edu/tju/rico/util/SerializeUtil.java:
--------------------------------------------------------------------------------
1 | package cn.edu.tju.rico.util;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.IOException;
6 | import java.io.ObjectInputStream;
7 | import java.io.ObjectOutputStream;
8 |
9 | /**
10 | * Title: 序列化/反序列化工具,负责byte[]和Java 对象之间的相互转换
11 | * Description:借助于JDK提供的序列化技术,使Redis能够对Java对象进行缓存 1.
12 | * 要求缓存实体(即Java对象)实现序列化Serializable接口; 2.
13 | * 序列化工具类:Jedis对序列化的支持,是提供了字节数组byte[]作为参数。
14 | *
15 | * @author rico
16 | * @created 2017年6月27日 上午11:13:34
17 | */
18 |
19 | public class SerializeUtil {
20 |
21 | /**
22 | * @description 序列化
23 | * @author rico
24 | * @created 2017年6月27日 上午11:13:22
25 | * @param obj
26 | * @return
27 | */
28 | public static byte[] serialize(Object obj) {
29 |
30 | ObjectOutputStream oos = null;
31 | ByteArrayOutputStream baos = null;
32 |
33 | try {
34 | // 字节数组输出流在内存中创建一个字节数组缓冲区,所有发送到输出流的数据保存在该字节数组缓冲区中
35 | baos = new ByteArrayOutputStream();
36 | oos = new ObjectOutputStream(baos);
37 |
38 | // 对指定的obj对象进行序列化,把得到的字节序列写到一个目标输出流中
39 | oos.writeObject(obj);
40 | // 创建一个新分配的字节数组,数组的大小和当前输出流的大小相同,内容是当前输出流的拷贝
41 | byte[] byteArray = baos.toByteArray();
42 | return byteArray;
43 |
44 | } catch (IOException e) {
45 | e.printStackTrace();
46 | }
47 | return null;
48 | }
49 |
50 | /**
51 | * @description 反序列化
52 | * @author rico
53 | * @created 2017年6月27日 上午11:13:26
54 | * @param bytes
55 | * @return
56 | */
57 | public static Object unSerialize(byte[] bytes) {
58 |
59 | ByteArrayInputStream bais = null;
60 |
61 | try {
62 | bais = new ByteArrayInputStream(bytes);
63 | ObjectInputStream ois = new ObjectInputStream(bais);
64 | // 从源输入流中读取字节序列,再将其反序列化成为一个Java对象并返回
65 | return ois.readObject();
66 | } catch (Exception e) {
67 | e.printStackTrace();
68 | }
69 | return null;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
39 | classpath:jdbc.properties
40 | classpath:redis.properties
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/src/main/resources/jdbc.properties:
--------------------------------------------------------------------------------
1 | #mysql settings
2 | jdbc.driverClassName=com.mysql.jdbc.Driver
3 | jdbc.url=jdbc:mysql://localhost:3306/ssm
4 | jdbc.username=root
5 | jdbc.password=root
6 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Global logging configuration
2 | log4j.rootLogger=ERROR, stdout
3 | # MyBatis logging configuration...
4 | log4j.logger.cn.edu.tju.rico.mapper.LogMapper=DEBUG
5 | log4j.logger.cn.edu.tju.rico.mapper.UserMapper=DEBUG
6 | # Console output...
7 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/redis.properties:
--------------------------------------------------------------------------------
1 | #redis settings
2 | redis.minIdle=5
3 | redis.maxIdle=10
4 | redis.maxTotal=50
5 | redis.maxWaitMillis=1500
6 | redis.testOnBorrow=true
7 | redis.numTestsPerEvictionRun=1024
8 | redis.timeBetweenEvictionRunsMillis=30000
9 | redis.minEvictableIdleTimeMillis=1800000
10 | redis.softMinEvictableIdleTimeMillis=10000
11 | redis.testWhileIdle=true
12 | redis.blockWhenExhausted=false
13 |
14 | #redisConnectionFactory settings
15 | redis.host=127.0.0.1
16 | redis.port=6379
--------------------------------------------------------------------------------
/src/main/resources/springmvc.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 | /WEB-INF/content/
31 |
32 |
33 |
34 | .jsp
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/resources/test.txt:
--------------------------------------------------------------------------------
1 | 哈哈,Rico。
--------------------------------------------------------------------------------
/src/main/webapp/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/.gitignore:
--------------------------------------------------------------------------------
1 | /classes
2 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/content/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme() + "://"
5 | + request.getServerName() + ":" + request.getServerPort()
6 | + path + "/";
7 | %>
8 |
9 |
10 |
11 |
12 |
13 | 首页
14 |
15 |
16 |
17 |
18 |
19 |
22 |
28 |
29 |
30 |
31 |
32 |
We Bare Bears
33 |
34 |
35 |

36 |
37 |
38 |
39 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/content/login.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 | %>
6 |
7 |
8 |
9 |
10 |
11 |
12 | 登录页
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
登录页面
23 |
24 |
25 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/content/regist.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 | %>
6 |
7 |
8 |
9 |
10 |
11 |
12 | 注册页
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
注册页面
23 |
24 |
25 |
26 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/content/show.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme() + "://"
5 | + request.getServerName() + ":" + request.getServerPort()
6 | + path + "/";
7 | %>
8 |
9 |
10 |
11 |
12 |
13 |
14 | 用户信息页
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | ${tip}
26 |
27 | 用户信息表
28 |
29 |
30 | ID |
31 | Uname |
32 | Gentle |
33 | City |
34 | Email |
35 |
36 |
37 | ${user.id} |
38 | ${user.uname} |
39 | ${user.gentle} |
40 | ${user.city} |
41 | ${user.email} |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/content/welcome.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 | %>
6 |
7 |
8 |
9 |
10 |
11 |
12 | 欢迎页
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | ${uname} ,欢迎您~
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | SSMDemo
7 |
8 | index.html
9 | index.htm
10 | index.jsp
11 | default.html
12 | default.htm
13 | default.jsp
14 |
15 |
16 |
17 |
18 | org.springframework.web.context.ContextLoaderListener
19 |
20 |
21 |
22 | contextConfigLocation
23 | classpath:applicationContext.xml
24 |
25 |
26 |
27 |
28 | SpringMVC
29 | org.springframework.web.servlet.DispatcherServlet
30 |
31 | contextConfigLocation
32 | classpath:springmvc.xml
33 |
34 | 1
35 |
36 |
37 | SpringMVC
38 | /
39 |
40 |
41 |
42 |
43 | CharacterEncodingFilter
44 | org.springframework.web.filter.CharacterEncodingFilter
45 |
46 | encoding
47 | utf-8
48 |
49 |
50 |
51 | CharacterEncodingFilter
52 | /*
53 |
54 |
--------------------------------------------------------------------------------
/src/main/webapp/img/3b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubofrico/SSMM-Demo/28651e179a9081f0db041b45655d4b89b71fd05b/src/main/webapp/img/3b.png
--------------------------------------------------------------------------------
/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%
3 | String path = request.getContextPath();
4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 | %>
6 |
7 |
8 |
9 |
10 |
11 |
12 | My JSP 'index.jsp' starting page
13 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 | This is my JSP page.
25 |
26 |
27 |
--------------------------------------------------------------------------------