基本 Java Bean
Posted ylz8401
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本 Java Bean相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ck.test</groupId> <artifactId>CK_Test</artifactId> <version>1.0.0</version> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <framework.bom.version>3.18.0</framework.bom.version> <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version> <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> <maven-source-plugin.version>3.0.1</maven-source-plugin.version> <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> <maven-war-plugin.version>3.0.0</maven-war-plugin.version> <maven-install-plugin.version>2.5.2</maven-install-plugin.version> </properties> <dependencyManagement> <dependencies> <!-- Framework --> <dependency> <groupId>com.XXX.framework</groupId> <artifactId>framework-bom</artifactId> <version>$framework.bom.version</version> <type>pom</type> <scope>import</scope> </dependency> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.2</version> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!-- guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>$maven-compiler-plugin.version</version> <configuration> <source>$java.version</source> <target>$java.version</target> <encoding>$project.build.sourceEncoding</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>$maven-surefire-plugin.version</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>$maven-source-plugin.version</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>$maven-jar-plugin.version</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>$maven-war-plugin.version</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>2.5</version> </plugin> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <downloadSources>true</downloadSources> <ajdtVersion>none</ajdtVersion> <additionalConfig> <file> <name>.settings/org.eclipse.jdt.core.prefs</name> <content> org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.compliance=1.7 </content> </file> </additionalConfig> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
package com.ck.test.misc; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ComparisonChain; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor public class Book implements Comparable<Book> private String title; private String author; private String publisher; private String isbn; private double price; @Override public int hashCode() return Objects.hashCode(title, author, publisher, isbn); @Override public boolean equals(Object obj) if(this == obj) return true; if(obj == null) return false; if(getClass() != obj.getClass()) return false; if(!(obj instanceof Book)) return false; Book other = (Book)obj; return Objects.equal(title, other.getTitle()) && Objects.equal(author, other.getAuthor()) && Objects.equal(publisher, other.getPublisher()) && Objects.equal(isbn, other.getIsbn()) && price == other.getPrice(); @Override public String toString() return MoreObjects.toStringHelper(this).omitNullValues() .add("title", title) .add("author", author) .add("publisher", publisher) .add("isbn", isbn) .add("price", price) .toString(); public static void main(String[] args) Book book = new Book("Core Java", "Tom", "JackMa", "11-22-33-44", 12.80); System.out.println(book); @Override public int compareTo(Book o) return ComparisonChain.start() .compare(this.title, o.getTitle()) .compare(this.author, o.getAuthor()) .compare(this.publisher, o.publisher) .compare(this.isbn, o.getIsbn()) .compare(this.price, o.getPrice()) .result();
以上是关于基本 Java Bean的主要内容,如果未能解决你的问题,请参考以下文章
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段
报错“Field pet in XXX.HelloController required a bean of type ‘XXX.Pet‘ that could not be found.“(代码片段
我的C/C++语言学习进阶之旅JNI开发之Java传递实体Bean到C++层,实体Bean包含intfloat等基本类型和数组arrayList集合等
我的C/C++语言学习进阶之旅JNI开发之Java传递实体Bean到C++层,实体Bean包含intfloat等基本类型和数组arrayList集合等
java.util.MissingResourceException: Can't find bundle for base name init, locale zh_CN问题的处理(代码片段