Giter Site home page Giter Site logo

template's Introduction

架构

前台不表

后台

典型的MVC+三层架构。

### SSH

  • Spring: 系统的所有对象均由spring托管,spring会自动创建对象及依赖注入。
  • Struts: 只做路由,所以的请求会被导到相应的控制器(Action或者Api)
  • Hibernate: ORM

下面以/action/news/subpage/1为例,说明整个流程

控制层(Action)

请求被struts导到ViewSubPageAction,struts会向spring要求一个ViewSubPageAction对象,spring会创建一个此对象,并注入相关依赖,将路由中最后的1提取取来,做为参数,调用对象的setPageNum方法注入参数。

Action调用相关Service(业务层)完成业务,并准备好一个Model对象(在ViewSubPageAction中,是mResult)。

确保Action执行完毕后,getXXX方法可以用。则在渲染Jsp时,Jsp中可以直接使用XXX。

另外,作为Ajax后端的控制器,我一律命名为XXXApi。参见ViewNewsDetailApi了解如何返回json对象。

表现层(Jsp)

根据struts-new.xml的配置,ViewSubPageAction执行完毕后,调用/WEB-INF/view/news/subpage.jsp进行渲染。此时,我们可以直接在jsp中调用${result.XXX}

业务层(Service)

com.n2cj.service.impl中的一堆XXXServiceImpl组成了业务层,控制层调用业务层来完成各种任务。

注意!所有Service对象都是单例,所以,请确保这些对象都是线程安全的!默认情况下,如果它们都是无状态,那么,mysql的事务机制可以保证对mysql的操作都是线程安全的。

存储层(Dao+Entity)

Mysql ORM是在这一层做的。你们按照自己的业务,改成你们的数据库。

目前,我没有帮你们弄缓存相关的东西,如果你们需要,到时再加个redis缓存层。这些缓存可以通过spring annotation加到Service上面,不对其他代码产生任何影响,比较好用,用到再说吧。

配置管理

所有的配置都放在了common/app.properites,在代码中需要时,使用@Value注入,在spring配置文件中需要时,使用${}语法。注意,在生产环境中,我们可以提供一个新的配置文件,来对它进行覆盖。这个等你们要发布时再说吧。

另外,还在一个logback.xml,是用来配置log的,这个你们用默认的就行了,生产环境中同样会覆盖。

运行

  • 使用maven运行:
    • 进行目录,运行mvn tomcat7:run
    • 打开浏览器,访问localhost:8080即可
  • 使用eclipse
    • 配置好tomcat7
    • 在tomcat7中,将项目的contextPath设置为/(默认是/+项目名)
    • 右键runOnServer

发布

发布时还有一些注意事项,到时再说吧

template's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.