導航:首頁 > 方法技巧 > 如何調用service層方法

如何調用service層方法

發布時間:2022-07-06 06:11:58

⑴ service層能不能直接調用service層

可以的,和control層調service方式一樣的

怎麼在jsp頁面中調用service層中類的方法

首先在配置文件里註明bean,如下所示:

[html] view plain
<beans:bean id="clientService" class="cn.bandlive.service.impl.ClientServiceImpl">
<property name="clientMapper" ref="clientDao"></property>
<property name="clientThirdplatformMapper" ref="clientThirdplatformDao"></property>
</beans:bean>

然後在jsp的<%%>中通過WebApplicationContextUtils工具類獲取ApplicationContext對象,如下所示:

[html] view plain
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());

ClientService clientService = (ClientService) ctx.getBean("clientService");
這樣你就可以調用clientService裡面的方法

如何在jsp中調用service層的方法

一般來說,在jsp層不應該直接調用service層的方法,應該訪問的是控制層,由控制層調用service層。如果你非要在jsp中調用service層方法,可以在jsp的頭文件中使用<%%>的形式直接定義service層對象,然後直接在裡面調用。

⑷ ,我用的標準的ssh框架,現在的問題是我寫了一個普通類想調用service層的方法,我該怎麼做

private ****Service service; (SET、GET方法)
service.方法名();

⑸ 如題,普通java類怎麼調用service層的類

簡單點的話直接通過new關鍵字創建service層實例,使用到框架可以和spring整合,在service層類上加@service將服務層對象放入spring容器,在controller使用@resource或@autowire將服務層對象注入進來

⑹ 怎麼調用service層

首先解釋面上意思,service是業務層,是數據訪問層。 呵呵,這個問題我曾經也有過,記得以前剛學編程的時候,都是在service里直接調用,service裡面就new一個類對象,調用,其他有

⑺ 自定義過濾器怎麼調用service層方法

通過spring的工廠類來拿,如xxx.getbean('xxx') 一般用過濾器不會經常訪問service層吧,都是得到HttpRequest和HttpResponse類,來進行一些檢驗,然後通過filterChain.doFilter(request, response);來轉到下一個過濾器,或者請求轉發、重定向到下

⑻ 過濾器中調用service層中的方法,該怎麼處理

也是在AndroidManifest中,service注冊後寫在 標簽里 application頁面application Nodes中點擊你要更改的services,右邊的permission中改也行。 比如 android.intent.action.ACTION_DATE_CHANGE 即可允許修改系統日期

⑼ Service層可以相互調用嗎

技術上來說,可以調用。但是不建議這樣使用,除非你這個方法是service公用的工具類。之所以不建議調用,是為了減少耦合性,同一層之間,最好不要耦合。

⑽ spring基於註解的普通類怎麼調用@Services註解的service方法

1、添加util方法:

package com.hzc.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
* 普通類調用Spring註解方式的Service層bean
* Created by HZC on 2015/10/21.
*/
public class SpringBeanFactoryUtils implements ApplicationContextAware {
private static ApplicationContext appCtx;

/**
* 此方法可以把ApplicationContext對象inject到當前類中作為一個靜態成員變數。
*
* @param applicationContext ApplicationContext 對象.
* @throws BeansException
* @author hzc
*/

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
appCtx = applicationContext;
}

/**
* 獲取ApplicationContext
*
* @return
* @author hzc
*/
public static ApplicationContext getApplicationContext() {
return appCtx;
}

/**
* 這是一個便利的方法,幫助我們快速得到一個BEAN
*
* @param beanName bean的名字
* @return 返回一個bean對象
* @author hzc
*/
public static Object getBean(String beanName) {
return appCtx.getBean(beanName);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2、在spring的配置文件.xml中添加

<bean id="springBeanFactoryUtils" class="com.haier.util.SpringBeanFactoryUtils"/>
1
1
3、service方法

package com.hzc.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
* Created by HZC on 2015/10/20.
*/
@Service("ckPayoffService")
public class CKPayoffServiceImpl implements ICKPayoffOrderService {

private static final Logger log = LoggerFactory.getLogger(CKPayoffServiceImpl.class);

/**
* 測試
*
* @author HZC
* @createDate 2015-10-21
*/
@Override
@Transactional
public void calculatePayoff() {
System.out.println("--------------------------gogogogogo---------------");
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
4、使用

CKPayoffServiceImpl ckps = (CKPayoffServiceImpl) SpringBeanFactoryUtils.getBean("ckPayoffService");
ckps.calculatePayoff();
1
2
1
2
在普通類中就可以調用service實例方法了,執行calculatePayoff方法,列印「————————–gogogogogo—————」

閱讀全文

與如何調用service層方法相關的資料

熱點內容
市場研究學的方法有很多 瀏覽:404
治療各種皮膚病的怪方法 瀏覽:449
搜狗瀏覽器更改主頁設置在哪裡設置方法 瀏覽:379
81x79的脫式計算方法 瀏覽:312
體恤的裁剪方法與步驟 瀏覽:453
宮頸癌保守治療方法 瀏覽:103
gl8節溫器解決方法 瀏覽:545
叉車使用方法 瀏覽:667
軟土黃土地基的處理方法有哪些 瀏覽:557
天車導繩安裝方法 瀏覽:368
記憶宮殿方法如何背誦文言文 瀏覽:716
wifi插線正確連接方法電信 瀏覽:409
七彩梅如何種植方法 瀏覽:390
語文背誦難題解決方法 瀏覽:380
胡椒研磨器使用方法 瀏覽:149
魚塘渾水怎麼處理方法 瀏覽:286
63x101計算方法 瀏覽:299
升降器lin線的正確檢測方法 瀏覽:902
麻辣香膏使用方法 瀏覽:185
生化試劑鐵離子檢測方法 瀏覽:100