grails - Grails地理位置-初始值设定项

标签 grails geoip

我们正在开发我们的项目。我们希望根据用户访问我们网站的国家/地区向用户显示数据。
我有一个存储国家/地区位置的字段。通过使用geoip grails插件。

我的问题是,我们是否可以在未命中任何 Controller / Action 的情况下,使用覆盖该网站的国家/地区名称来初始化 session ,可以说在某些配置文件中或其他位置。

最佳答案

您应该可以在Filter中执行此操作。像这样,以grails-app/conf的形式放在GeoFilters.groovy中:

class GeoFilters {
  def geoIpService

  def filters = {
    countryCheck(controller:'*', action:'*') {
      before = {
        if( !session.geolocation ) {
          session.geolocation = geoIpService.getLocation( request.remoteAddr )
        }
      }
    }
  }
}

应该(尽管我还没有尝试过)检查 session 中是否存在geolocation,如果不存在,则应从geoIpService中获取它。

关于grails - Grails地理位置-初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149823/

相关文章:

mongodb - GORM-获取域类属性的原始DB值

在 grails 应用程序中自定义 ehcache.xml 后抛出异常

tomcat - 在 Tomcat6 上运行的 Grails 应用程序抛出的 NotSerializableException

mongodb - 如何使用Grails配置MongoDB

grails - Grails 3 中的运行脚本替代方案

performance - MaxMind GeoLite mysql 与二进制数据性能

python - 在 Appengine 上使用 Pygeoip - 没有名为 mmap 的模块

geocoding - 如何使用maxmind从IP地址获取纬度和经度?

geoip - maxmind geolite city 精度不断降低

perl - MaxMind Writer 创建自定义数据库以与 ELK Stack 中的 geoip 一起使用