Last updated by admin 3 years ago
???
Grails ???
???? ?? ??? ???? ?? ???? ???? ?? ??????. ???? ??? ???? ???? ??? ??? ??? ???? ??????. ???? ????? ?? ??? ?? ? ??(atomic) ?? ??? ?????. ??? ??? ??? ???? ????? ?????.???? ?? ??(middle tier)? ????? ??, ???? AOP ??? ??? ?? ???? ??? ??? ???.???? ?????? ??? ?????. ??? ??? ???? ??, ?????? ???? ??? ???? ?? ?? ????.???? ?? ?? ??
??? ???? ??? ??? ??? ???? ???? ??, ?? "Service"? ??? ???. ??? ???(country service)? "CountryService"? ?? ????? ???.????? ?? ???? ?? ???? ??? ?????. ?? ??? ???? ?? ???? ???? ?????? ?????. ????? ???? ???? "transactional" ??? false? ???? ???:class CountryService {
boolean transactional = false
}??? ??(Dependency Injection)
??? ???? ?? ???? ??(inject)? ?? ????. CountryService? ????? "countryService"?? ??? ?????? ?? ???:CountryService countryService
javax.sql.DataSource dataSource
???? ????
???? ?? ??(multitier) ???? ???, ???? ??? ??(dependency injection)? ?? ?? ???? ??? ? ????. ?? ??? ?????? ???? ???? ??? ?????:class CountryService {
def String sayHello(String name) {
return "hello ${name}"
}
}class GreetingController {
CountryService countryService
def helloAction = {
render(countryService.sayHello(params.name))
}
}package serviceinterfaces;public interface CountryServiceInt { public String sayHello(String name); }
class CountryService implements serviceinterfaces.CountryServiceInt { def String sayHello(String name) { return "hello ${name}" } }
ApplicationContext ctx = (ApplicationContext) request.getSession().getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT); CountryServiceInt service = (CountryServiceInt) ctx.getBean("countryService"); String str = service.sayHello(request.getParameter.("name")); //do something with str



