Korean Services

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 ????? ??? ?? ????:

javax.sql.DataSource dataSource
??? ?? ??? dataSource? Spring? JdbcTemplate? ?? ???? SQL ??? ??? ? ????. ??? ??? Groovy Sql ? ?????.

???? ????

???? ?? ??(multitier) ???? ???, ???? ??? ??(dependency injection)? ?? ?? ???? ??? ? ????. ?? ??? ?????? ???? ???? ??? ?????:

class CountryService {
    def String sayHello(String name) {
        return "hello ${name}"
    }
}

class GreetingController { CountryService countryService def helloAction = { render(countryService.sayHello(params.name)) } }

?? ?????. ???? http://myserver:8080/myapp/greeting/helloAction?name=Falken ? ???? "hello Falken"??? ???? ?? ???? ??? ????. ????? ?? ? ??? ??? ???? ? ?????.

??? ?, ? ??????? ?? ????? ???? ??? ? ????. ??? ??? ?? ??? ?? Spring Bean Factory? ?? ??? ? ?? Bean ?????.

?? ????? ???? ??? ?? ?????? ?????:

package serviceinterfaces;

public interface CountryServiceInt { public String sayHello(String name); }

? ??? "<..>/myapp/src/java/serviceinterfaces" ????? ?????.

??? ?? CountryServiceInt ?????? ????? Groovy ???? CountryService? ?????:

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