开发规范

XML

  1. 书写规范:非生成的SQL一律使用大写,缩进、对齐必须工整
  2. 注释规范

例:


    

通用Java规范

  1. 编码前,务必熟读Java代码规范,规范文档地址详见SVN http://218.17.157.105:8055/repos/vcomponent/Document/0.项目管理/0.项目规范/JAVA规范.doc;
  2. 编码前,务必导入eclipse注释模板,模版地址详见SVN http://218.17.157.105:8055/repos/vcomponent/Document/0.项目管理/0.项目规范/codetemplates.xml;
  3. 接口和实现类均要写上注释;
  4. Java中对属性、方法、类进行修改时,请加上自己的名字,如:
    你(userName)修改前的代码如下:
 /**
 * 切面方法体环绕
 * 
 * @date 2016年11月25日 上午10:11:33
 * @author zhaoj
 * @since V1.0.3
 * @return
 */
 private Object aroundAdvice() {
          return null;
 }

修改后应加入注释@author userName

 /**
 * 切面方法体环绕
 * 
 * @date 2016年11月25日 上午10:11:33
 * @author zhaoj
 * @author userName
 * @since V1.0.3
 * @return
 */
 private Object aroundAdvice() {
     return null;
 }

Bo(Bean Object)

  1. 字段名规范
  • 不随意增加基础类型字段,如:ExamUser对象有属性名为id的属性,则切勿再添加属性名为idsid1id2idNotEqual一类的重复属性,一律使用id属性;
  • 在扩展对象类型字段时,新增的业务实体属性名与业务实体名一致,避免重复定义,且只能做声明,不能初始化,如:
public class ExamUser extends AbstractExamUser{
        private ExamCourse examCourse;
        private ExamPolicy examPolicy;
        private ExamType examType;
        private ExamStudentAnswer examStudentAnswer;
        //下面的初始化是极其不推荐的,切勿使用
        //private ExamStudentAnswer examStudentAnswer = new ExamStudentAnswer ();
}
  1. Bo需重写toString()方法;

Dao(Data Access Object)

  1. BaseDao实现类中已经封装了非常丰富的表操作,在写新的接口之前,要先思考一个问题:在不影响功能和性能的情况下,使用生成的代码能否满足需求;

Service

  1. 统一通过getDao()的方式调用Dao层代码,如:
public class ExamScopeServiceImpl extends BizBaseServiceImpl implements ExamScopeService{
        @Resource
        private ExamQuestionDao examQuestionDao;

        public List studentQuery(ExamScope bo) {
                return getDao().studentQuery(bo);
        }

        public Integer queryCount(ExamScope bo) {
                return examQuestionDao.queryCount(bo);
        }
}
  1. 涉及到事务的操作,务必方法上加上@Transactional注解;
  2. Service层尽量只注入Dao,不推荐注入Service,避免形成闭回环,如:
public class AService{
        //不推荐
        @Resource
        private BService bService ;
}
public class BService{
        //不推荐
        @Resource
        private AService aService ;
}
  1. BaseService实现类中已经封装了非常丰富的表操作,在写新的接口之前,要先思考一个问题:在不影响功能和性能的情况下,使用生成的代码能否满足需求?

Controller

  1. 统一通过getService()的方式调用Service层代码,如:
public class ExamUserController extends BizBaseController {
        @Override
        public ModelAndView showMain(){
                Paginator paginator = new Paginator();
                List list = getService().queryByPageWithSort(paginator, new SortData(Direction.ASC,properties,"EXAM_USER.ID"));
        
                ModelAndView mv = getModelAndView(getClassRequestMapping() + "/showMain");
                mv.addObject("resultList", list)
                mv.addObject("paginator",paginator)
                mv.addObject("sortData",sortData);
                return mv;
        }
}
  1. Controller层尽量只注入Service,不推荐注入Dao
  2. @RequestMapping中的value值与函数名需保持一致
public class ExamUserController extends BizBaseController {
        @RequestMapping(value = "/showMain")
        public ModelAndView showMain(){
                Paginator paginator = new Paginator();
                List list = getService().queryByPageWithSort(paginator, new SortData(Direction.ASC,properties,"EXAM_USER.ID"));
        
                ModelAndView mv = getModelAndView(getClassRequestMapping() + "/showMain");
                mv.addObject("resultList", list)
                mv.addObject("paginator",paginator)
                mv.addObject("sortData",sortData);
                return mv;
        }
}
  1. 后台验证的问题必须引起注意:入参合法性判断,此处的合法性包括:输入规则合法(例如正则表达式后台验证)及数据冲突合法性(例如双浏览器操作)
  2. 确定如下函数名均不能满足你,再去定义一个新的函数:
//主页面
showMain()
//带条件的显示主页面,主要用于“返回”按钮
showMain(T, Paginator, SortData)
//搜索、分页查询
list(T, Paginator, SortData)
//添加页面
add()
//编辑
edit(Integer)
//保存
save(T)
//单个删除
delete(Integer)
//查看
show(Integer)
//批量删除
batchDelete(Integer[])
//批量更新
batchUpdate(Integer[], T)
//批量插入
batchInsert(T[])
  1. 统一调用getModelAndView(String modelName)方法构建视图,如:
getModelAndView(String)
  1. 统一调用addObject(String attributeName, Object attributeValue)方法组装模版数据,如:
ModelAndView mv = getModelAndView(getClassRequestMapping() + "/showMain");
mv.addObject("resultList", list);
  1. 推荐使用如下方式获取Bean
//推荐使用
ExamUser examUser1 = AppContext..getBean(ExamUser.class);
//不推荐使用
//ExamUser examUser2 = (ExamUser)AppContext.getBean("examUser");
  1. 统一使用如下方式获取当前用户
//Controller、Service、Dao层通用
AppContext.getCurrentUserId();
  1. 在合适的场景下,使用queryCount(T bo)去代替query(T bo)
  2. Servive注入时,加@Resource注解即可,无需@Resource(name="vslObjectServiceImpl")Service注入Dao同理:
@Controller
@RequestMapping("/admin/vslObject")
public class VslObjectController extends BizBaseController {
          //@Resource(name="vslObjectServiceImpl")
          @Resource
          VslObjectService service;
}
  1. 每个带有@RequestMapping注解的方法都应加上@LogMark(memo="备注"),用于记录日志;

HTML

  1. 标签必须对齐
  2. 学会用Google浏览器中调整简单样式
  3. Freemarker在页面上的常用操作:
//格式化数字输出
<#setting number_format="#">
//获取枚举国际化propertis文件中键为“Bool.YES”的值
${resourceBundle("Bool.YES")}
//---------------------------------------宏及常用宏的使用---------------------------------------
//引入宏
<#import "/common/tag.htm" as tag>
//截取字符串
<@tag.substr content="${item.examQuestion.content!}
//根据枚举生成select下拉框
<@enum.select id="bo.result" type="com.vnetoo.common.enums.Bool" header="true" default=""/>
//根据枚举生成radio单选框
<@enum.radio id="bo.type" type="com.vnetoo.common.enums.Bool" default="${bo.type}"/>
//根据枚举生成checkbox复选框
<@enum.checkbox id="bo.type" type="com.vnetoo.common.enums.Bool" default="${bo.type}"/>

JS

  1. 学会用console.log()
  2. 学会用Google浏览器 F12中打断点,可以利用console.log()来打断点
  3. 学会在Google浏览器 F12查看变量
  4. 学会用Google浏览器 改样式
  5. 选择器要重点熟悉

你可能感兴趣的:(开发规范)