1.所需的jar
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
2.lombok安装
①. 我用的是sts,安装lombok,把下载的lombok.jar放在D:\sts-3.9.0.RELEASE目录下,
②. 运行java -jar lombok.jar
弹出如下界面
点击确定,再次点击Specify,选择sts安装目录
点击Install / Update
③. 查看是否成功,打开sts.ini
查看是否有如下信息,有即成功
或
④.重启STS
3.代码示例
①.User对象---@Data
import javax.persistence.Column;
import lombok.Data;
@Data
public class User {
private int userId;
private String userName;
private String address;
private int sex;
private String userPass;
private int roleId;
private String roleName;
}
②.Controller----@slf4j
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shy.springmvc.entity.User;
import lombok.extern.slf4j.Slf4j;
@RequestMapping(value="/web")
@Controller
@Slf4j
public class BaseController {
@RequestMapping(value="/app1")
@ResponseBody
public String Test1() {
User user = new User();
user.getUserName();
user.setAddress("admin");
String addr = user.getAddress();
log.info("Address-------------:"+addr);
return "";
}
}