`
samjavaeye
  • 浏览: 187673 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Multiple String Literals

 
阅读更多
【原因分析】
在同一个java文件,相同的字符串出现了多次。例如:
public String doAdd(HttpServletRequest request) {
        String name = request.getParameter("name");
        ......
}
public String doUpdate(HttpServletRequest request) {
        String newName = request.getParameter("name");
        ......
}
 
【影响分析】
重复的代码会增加维护难度,如果字符串内容变更了,则需要同时修改多处。
 
【修改建议】
将相同的字符串定义成一个常量。例如:
private static final String PARAM_NAME = "name";
public String doAdd(HttpServletRequest request) {
        String name = request.getParameter(PARAM_NAME);
        ......
}
public String doUpdate(HttpServletRequest request) {
        String newName = request.getParameter(PARAM_NAME);
        ......
}
分享到:
评论

相关推荐

    VA_X_Setup1940

    Surround With feature is no longer invokable within comments, string literals, and tags in XML/HTML/XAML. (case=74045) Fix for Visual Studio reporting an exception when scrolling quickly through ...

    C++ by Example

    way to teach computer programming concepts is with multiple examples. Command descriptions, format syntax, and language references are not enough to teach a newcomer a programming language. Only by ...

    JavaScript权威指南

    Multiple Windows and Frames Chapter 14. The Document Object Section 14.1. Document Overview Section 14.2. Dynamically Generated Documents Section 14.3. Document Color Properties Section ...

    python3.6.5参考手册 chm

    PEP 498: Formatted string literals PEP 526: Syntax for variable annotations PEP 515: Underscores in Numeric Literals PEP 525: Asynchronous Generators PEP 530: Asynchronous Comprehensions PEP 487:...

    ARM® Compiler v5.06 for µVision® armasm User Guide

    7.13 String literals 7.14 Numeric expressions 7.15 Syntax of numeric literals 7.16 Syntax of floating-point literals 7.17 Logical expressions 7.18 Logical literals 7.19 Unary operators 7.20 Binary ...

    JSP Simple Examples

    Suppose if we have a declare an array of type String, then it will store only the String value not any other data type. When we have a closely related data of the same type and scope, it is better to...

    acpi控制笔记本风扇转速

    produced when this parameter was a null string (""). Now, the original input filename is used as the AML output filename, with an ".aml" extension. Implemented a generic batch command mode for the ...

    node-ts-dedent:TypeScript软件包,可巧妙地修剪和去除多行字符串中的压痕

    TypeScript Dedent ... multiple lines. Luckily dedent is here to keep it readable without lots of spaces ending up in the string itself.` ) ; console . log ( dedent ` A string that gets so long y

    Programming in Objective-C 4th Edition

    Accessing Properties Using the Dot Operator 134 Multiple Arguments to Methods 135 Methods Without Argument Names 137 Operations on Fractions 137 Local Variables 140 Method Arguments 141 The static ...

    Crafting a Compiler by Charles N. Fisher Richard J. LeBlanc 带目录版

    4.5.2 Deriving the Empty String 128 4.5.3 First Sets 130 4.5.4 Follow Sets 134 4.6 Exercises 138 5 Top-Down Parsing 143 5.1 Overview 144 5.2 LL(k) Grammars 145 5.3 Recursive-Descent LL(1) Parsers 149 ...

    Addison.Wesley.C++.by.Dissection.2002.pdf

    2.1.4 Literals......... 29 2.1.5 Operators and Punctuators..... . 31 2.2 Input/Output......... . 31 2.3 Program Structure........ . 34 2.3.1 Redirection........ . 36 2.4 Simple Types......... . 37 ...

    javascript权威指南(第六版)

    10.2 String Methods for Pattern Matching 259 10.3 The RegExp Object 261 11. JavaScript Subsets and Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 11.1 ...

    Google C++ International Standard.pdf

    5.13 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6 Basic concepts 39 6.1 Declarations and definitions . . . . . . . . . . . . . . . . . . . ...

    SystemVerilog Reference Manual 3.1a(中英文版)+最新SV IEEE 标准

    2.6 String literals....................................................................................................................................5 2.7 Array literals ...............................

    The Definitive Guide to NetBeans Platform

    Contents at a Glance Foreword . . . . . . . . ....About the Author ....About the Technical Reviewers ....Acknowledgments....Introduction ....■CHAPTER 1 Introduction ....■CHAPTER 2 Structure of the NetBeans Platform ....

    The way to go

    go程序设计语言 Contents Preface................................................................................................................................. xix PART 1—WHY LEARN GO—GETTING ...

    C++ 标准 ISO 14882-2011

    2.14 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3 Basic concepts 34 3.1 Declarations and definitions . . . . . . . . . . . . . . . . . . ...

    [Go语言入门(含源码)] The Way to Go (with source code)

    The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................

    Thinking in Java 4th Edition

    Literals .................................. 73 Exponential notation ................... 74 Bitwise operators .................. 75 Shift operators ......................76 Ternary if-else operator ......

    Doctrine ORM for PHP.pdf

    Table of Contents Introduction....................................................................................................13 Code Examples.........................................................

Global site tag (gtag.js) - Google Analytics