发表于: 2017-05-09 19:49:51
2 1210
今日目标:
把demo改成注解方式实现。
1.将springmvc-servlet中之前配置的Controller删掉,加上一行将Controller指定在某个包的语句。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.qhs.rest.controller" />
</beans>
2.修改IndexController:删除掉对接口的实现,增加一个导包(对Controller注解的支持),并且在类前面加上@Controller注解。
同时在方法前加上@RequestMapping("/index")注解,表明由它处理访问/index的请求。
package com.qhs.rest.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
public class IndexController {
@RequestMapping("/index")
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
ModelAndView mav = new ModelAndView("index.jsp");
mav.addObject("msg","HelloSpringMVC");
return mav;
}
}
明日目标:
和任务1一样,配置MyBatis和c3p0连接池。
研究这接口咋实现……
评论