java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaEE, JavaME, JavaSE)的总称。本站提供基于Java框架struts,spring,hibernate等的桌面应用、web交互及移动终端的开发技巧与资料
保持永久学习的心态,将成就一个优秀的你,来 继续搞起java知识。
配置文件web.xml
<!-- <a href="http://www.cfei.net/archives/tag/spring" title="浏览关于“Spring”的文章" target="_blank" class="tag_link">Spring</a>的log4j监听器 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 核心控制器 -->
<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
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
因为水平有限,难免有疏忽或者不准确的地方,希望大家能够直接指出来,我会及时改正。一切为了知识的分享。
后续会有更多的精彩的内容分享给大家。
支付宝扫一扫
微信扫一扫
