package com.niugang.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.niugang.bean.UserQuery;
import com.niugang.entity.User;
@Repository
public interface UserDao {
List queryListByPage(UserQuery user);
User get(Integer id);
void save(User user);
void delete(Integer id);
int queryCount(UserQuery user);
}
User.java
package com.niugang.entity;
public class User {
private Integer id;
private String name;
private Integer age;
private String phone;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", age=" + age + ", phone=" + phone + ", password=" + password
+ "]";
}
}
CheckException.java
package com.niugang.exception;
/**
* 检测异常
* @author niugang
* 只能继承RuntimeException spring aop只能捕获RuntimeException异常
*
*/
public class CheckException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CheckException() {
}
public CheckException(String message) {
super(message);
}
public CheckException(Throwable cause) {
super(cause);
}
public CheckException(String message, Throwable cause) {
super(message, cause);
}
public CheckException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
UserService.java
package com.niugang.service;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.niugang.bean.UserQuery;
import com.niugang.dao.UserDao;
import com.niugang.entity.User;
import com.niugang.exception.CheckException;
@Service
public class UserService {
private static Logger logger = LoggerFactory.getLogger(UserService.class);
@Resource
private UserDao userDao;
public List queryListByPage(UserQuery user) {
logger.info("access queryListByPage method params is:{}", user.toString());
return userDao.queryListByPage(user);
}
@Transactional
public void save(User user) {
logger.info("access get method params is:{}", user.toString());
if (StringUtils.isBlank(user.getName())) {
throw new CheckException("用户名不能为空");
}
if (user.getAge() == null) {
throw new CheckException("年龄不能为空");
}
if (StringUtils.isBlank(user.getPhone())) {
throw new CheckException("电话不能为空");
}
user.setPassword("123456");
userDao.save(user);
//为了验证事务
//throw new CheckException("添加数据错误");
}
public User get(Integer id) {
logger.info("access get method param is:{}", id);
return userDao.get(id);
}
public void delete(Integer id) {
logger.info("access delete method param is:{}", id);
userDao.delete(id);
}
public int queryCount(UserQuery user) {
logger.info("access queryCount method param is:{}", user.toString());
return userDao.queryCount(user);
}
}
CodeConstant.java
package com.niugang.utils;
/**
* 常量表
* @author niugang
*
*/
public class CodeConstant {
/**
* 没有登录
*/
public static final int NO_LOGIN = -1;
/**
* 成功
*/
public static final int SUCCESS = 0;
/**
* 检查
*/
public static final int CHECK_FAIL = 1;
/**
* 没有权限
*/
public static final int NO_PERMISSION = 2;
/**
* 位置异常
*/
public static final int UNKNOWN_EXCEPTION = -99;
/**
* 默认页码
*/
public static final int DEFAULT_PAGE_NUMBER=1;
/**
* 默认页面大小
*/
public static final int DEFAULT_PAGE_SIZE=5;
}
Page.java
package com.niugang.utils;
/**
* 页面对象
*
* @author niugang
*
*/
public class Page {
/**
* 页码
*/
private int pageNumber = CodeConstant.DEFAULT_PAGE_NUMBER;
/**
* 页面大小
*/
private int pageSize = CodeConstant.DEFAULT_PAGE_SIZE;
/**
* 总页数
*/
private int totalPage;
/**
* 总记录数
*/
private int totalCount;
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
if (totalCount % pageSize == 0) {
return totalCount / pageSize;
}
return totalCount / pageSize + 1;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
}
PageResultBean.java
package com.niugang.utils;
import java.io.Serializable;
import java.util.List;
/**
* controller层返回带分页对象
* @author niugang
*
*/
public class PageResultBean extends Page implements Serializable,Result{
private static final long serialVersionUID = 1L;
/**
* 返回的信息
*/
private String resultMessage = "success";
/**
* 返回码
*/
private Integer resultCode=CodeConstant.SUCCESS;
/**
* 返回的数据
*/
private List data;
public PageResultBean() {
super();
}
public PageResultBean(String resultMessage, Integer resultCode, List data) {
super();
this.resultMessage = resultMessage;
this.resultCode = resultCode;
this.data = data;
}
public String getResultMessage() {
return resultMessage;
}
public void setResultMessage(String resultMessage) {
this.resultMessage = resultMessage;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
}
Result.java
package com.niugang.utils;
/**
* 标示性接口
* @author niugang
*
*/
public interface Result{
}
ResultBean.java
package com.niugang.utils;
import java.io.Serializable;
/**
* controller层返回对象
* @author niugang
*
* @param
*/
public class ResultBean implements Serializable,Result{
private static final long serialVersionUID = 1L;
/**
* 放回的信息
*/
private String resultMessage = "success";
/**
* 返回码
*/
private Integer resultCode=CodeConstant.SUCCESS;
/**
* 返回的数据
*/
private T data;
public ResultBean() {
super();
}
public ResultBean(String resultMessage, Integer resultCode, T data) {
super();
this.resultMessage = resultMessage;
this.resultCode = resultCode;
this.data = data;
}
public String getResultMessage() {
return resultMessage;
}
public void setResultMessage(String resultMessage) {
this.resultMessage = resultMessage;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
id, name, age,phone
and id=#{id}
and name=#{name}
and age=#{age}
and phone=#{phone}
insert into user (name,password,age,phone)
values(#{name},#{password},#{age},#{phone})
delete from user where id
=#{id}
今天和同事争论一问题,关于静态变量与非静态变量的初始化顺序,谁先谁后,最终想整理出来!测试代码:
import java.util.Map;
public class T {
public static T t = new T();
private Map map = new HashMap();
public T(){
System.out.println(&quo
完整命令
CREATE DATABASE mynewdb USER SYS IDENTIFIED BY sys_password USER SYSTEM IDENTIFIED BY system_password LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/m
多线程并发使用同一个channel
java.nio.BufferOverflowException: null
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:183) ~[na:1.7.0_60-ea]
at java.nio.ByteBuffer.put(ByteBuffer.java:832) ~[na:1.7.0_60-ea]