⑴ 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—————”