java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaEE, JavaME, JavaSE)的总称。本站提供基于Java框架struts,spring,hibernate等的桌面应用、web交互及移动终端的开发技巧与资料

保持永久学习的心态,将成就一个优秀的你,来 继续搞起java知识。

配置文件web.xml

&lt;!-- <a href="http://www.cfei.net/archives/tag/spring" title="浏览关于“Spring”的文章" target="_blank" class="tag_link">Spring</a>的log4j监听器 --&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
    &lt;/listener&gt;

    &lt;!-- 核心控制器 --&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;Spring&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
            &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;listener&gt;
        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Spring&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

Action:

@Controller
public class Book {

    protected TestService testService;

    @RequestMapping(value = ("/book"))
    public void add() {
        System.out.println("--http://localhost:8080/Spring/book");
        testService.test();
    }

    @RequestMapping(value = "/test/11")
    public void test1() {
        System.out.println("---http://localhost:8080/Spring/test/11----join success--");
        testService.test();
    }

    // @RequestMapping(value = "/test/{pame1}")
    // public void test2(@PathVariable("pame1") String pame) {
    // System.out.println("---http://localhost:8080/Spring/test/qwe----join success--:" + pame);
    // testService.test();
    // }

    @RequestMapping(value = "/test", params = "pame1")
    public void test3(@PathParam("pame1") String pame1) {
        System.out.println("---http://localhost:8080/Spring/test?pame1=111----join success--:" + pame1);
        testService.test();
    }

    public TestService getTestService() {
        return testService;
    }

    @Resource
    public void setTestService(TestService testService) {
        this.testService = testService;
    }
}
@Controller
@RequestMapping("/spring.do")
public class TestAction {

    protected TestService testService;

    /**
     * Adds the.--http://localhost:8080/Spring/spring.do?method=add
     * 
     * @param book the book
     * @return the string
     */
    @RequestMapping(params = "method=add")
    public void add(Book book) {
        System.out.println("bookname:" + book.getName());
        System.out.println("author:" + book.getAuthor());
        testService.test();
    }

    public TestService getTestService() {
        return testService;
    }

    @Resource
    public void setTestService(TestService testService) {
        this.testService = testService;
    }

}

Service:

@Service
public class TestService {

    protected TestDao testDao;

    public void test() {
        System.out.println("---join in service success----");
        testDao.Test();
    }

    public TestDao getTestDao() {
        return testDao;
    }

    @Resource
    public void setTestDao(TestDao testDao) {
        this.testDao = testDao;
    }

}

DAO:

@Repository
public class TestDao {

    public void Test() {
        System.out.println("---dao success---");
    }

}

spring

因为水平有限,难免有疏忽或者不准确的地方,希望大家能够直接指出来,我会及时改正。一切为了知识的分享。

后续会有更多的精彩的内容分享给大家。