Project Lombok is a java library that automatically plugs into your editor and build tools to generate boilerplate code such as class constructors, field getter and setter, hashCode etc.
In order to use it, set lombok as one of the maven dependencies.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
The javac can understand the lombok annotations doesn't mean your IDE can understand them. Eclipse, for example, need to have a the lombok.jar registered, so that it can use it to compile your code before running it. The Eclipse installation is easy, lombok.jar did that for you. You just have to download the jar, run it with
java -jar lombok.jar
the rest of the work is handled by the jar. It scan your computer to find the eclipse and install itself into your chosen eclipse programs.
Now you can write code such as
package com.example.my.mydemo.dao;
import lombok.Getter;
import lombok.Setter;
@Setter @Getter
public class Client {
private String name;
private String email;
private long id;
}
With the lombok annotation @Getter @Setter, javac or eclipse treat them as equivalent to the following code
package com.example.my.mydemo.dao;
public class Client {
private String name;
private String email;
private long id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
So, when other java code need to access getter and setters, it won't fail.
package com.example.my.mydemo.dao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import com.example.my.mydemo.model.Client;
public class ClientDao {
private final JdbcTemplate jdbcTemplate;
private static final String CLIENTSELECT = "select name, email, id from "
+ "Client where id = ?";
public ClientDao(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public Client getClient(String clientId) {
Client client = jdbcTemplate.queryForObject(CLIENTSELECT, new Object[]{clientId},
new BeanPropertyRowMapper<Client>(Client.class));
return client;
}
}
That is easy.
Even better, we can use @Data annotation to get many code for free, it is equivalent to @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode all together.
apple watch 6 titanium 3 pcs slot machine game
ReplyDeleteapple watch 6 2020 ford ecosport titanium titanium 3 pcs ceramic or titanium flat iron slot machine game machine ion titanium on brassy hair - apple watch 6 titanium titanium canteen 3 pcs slot machine game machine, apple watch 6 titanium 3 pcs slot oakley titanium sunglasses machine game machine