日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring 一二事(8) - annotation 形式的 MVC

發布時間:2025/4/16 javascript 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring 一二事(8) - annotation 形式的 MVC 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 <!-- 2 component:把一個類放入到spring容器中,該類就是一個component 3 在base-package指定的包及子包下掃描所有的類 4 --> 5 <context:component-scan base-package="com.lee.spring012.scan.mvc.annotation"></context:component-scan>

IStuDAO.java

1 package com.lee.spring012.scan.mvc.annotation; 2 3 public interface IStuDAO { 4 public void saveStu(); 5 }

IStuService.java

1 package com.lee.spring012.scan.mvc.annotation; 2 3 public interface IStuService { 4 public void saveStu(); 5 }

PersonAction.java

1 package com.lee.spring012.scan.mvc.annotation; 2 3 import javax.annotation.Resource; 4 5 import org.springframework.context.annotation.Scope; 6 import org.springframework.stereotype.Controller; 7 8 @Controller 9 @Scope("prototype") // action為多例 10 public class PersonAction { 11 12 @Resource 13 public IStuService stuServiceImpl; 14 15 public void displaySave() { 16 System.out.println("mvc action: saving stu..."); 17 stuServiceImpl.saveStu(); 18 } 19 20 }

StuDAOImpl.java

1 package com.lee.spring012.scan.mvc.annotation; 2 3 import org.springframework.stereotype.Repository; 4 5 @Repository 6 public class StuDAOImpl implements IStuDAO { 7 8 @Override 9 public void saveStu() { 10 System.out.println("mvc dao: saving stu..."); 11 } 12 13 }

StuServiceImpl.java

1 package com.lee.spring012.scan.mvc.annotation; 2 3 import javax.annotation.Resource; 4 5 import org.springframework.stereotype.Service; 6 7 @Service 8 public class StuServiceImpl implements IStuService { 9 10 @Resource 11 public IStuDAO stuDAOImpl; 12 13 @Override 14 public void saveStu() { 15 System.out.println("mvc service: saving stu..."); 16 stuDAOImpl.saveStu(); 17 } 18 19 }

測試

1 package com.lee.spring012.scan.mvc.annotation; 2 3 import org.junit.Test; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.support.ClassPathXmlApplicationContext; 6 7 public class PersonTest { 8 9 @Test 10 public void testPersonAction() { 11 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-scan-mvc.xml"); 12 PersonAction person = (PersonAction)context.getBean("personAction"); 13 person.displaySave(); 14 } 15 16 }

github地址:https://github.com/leechenxiang/maven-spring001-helloworld

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Spring 一二事(8) - annotation 形式的 MVC的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。