今天接触SSM框架的第三天,终于通过篇博客成功的搭建好了SSM框架,
后台Mybatis生成dao、entity和mapper后,测试成功,能够正常读写数据库了,
但是,在加入页面之后,通过controller不能实现页面的跳转,特求助~~
访问情况:
点击跳转后,
出现404的错误,个人认为,可能市没有找到controller
代码:
messageController.java
@Controller
@RequestMapping("/message")
public class messageController {
@RequestMapping("/rea.md")
public String gotest(){
System.out.println("执行到这里了");
return "reach";
}
@Resource
private MessageMapper mapper;
@RequestMapping("showUser.md")
public void selectUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
int userID = Integer.parseInt(request.getParameter("id"));
Message message = mapper.selectByPrimaryKey(userID);
System.out.println(message.getCommand()+message.getContent()+message.getDescription());
}
}
index.jsp
<%@page contentType="text/html; charset=UTF-8" language="java" %>
<html>
<head>
<title>首页</title>
</head>
<body>
<h2>Hello World!</h2>
<a href="/message/rea.md">点击跳转</a>
<p id="test">Hello World!</p>
<button type="button" onclick="selectUser()">onclick test</button>
</body>
</html>
reach.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>跳到这里了</title>
</head>
<body>
跳转成功!!!
</body>
</html>
文件路径: