diff --git a/doc/insert20190309.sql b/doc/insert20190309.sql new file mode 100644 index 0000000000000000000000000000000000000000..5c48a755cd2eff1f7db9c79b129ae1265b015abf --- /dev/null +++ b/doc/insert20190309.sql @@ -0,0 +1,12 @@ + +insert into t_article(create_time, update_time,title, content) VALUES +(1552068421000,1552068421000,'个人博客','Python简单。可以把开发者的思想从编程语言的细节里解放出来,更关注实际要解决的问题。'), +(1552068421000,1552068421000,'个人博客','智联招聘某员工匿名透露:我们内部数据统计,通过大把(千万级)的简历分析得到的结果:。但Python从来不该背锅:!'), +(1552068421000,1552068421000,'个人博客','人说巴甘长的像女孩:粉红的脸蛋上有一层黄绒毛,笑起来眼睛像弓一样弯着。他家在内蒙古东科尔沁的赫热塔拉村,春冬萧瑟,夏天才像草原。大片绿草'), +(1552068421000,1552068421000,'个人博客','蹲下,再采红火苗似的萨日朗花。那时他三四岁,还穿着开裆裤,经常露出两瓣屁股。妈说:“老天爷'), +(1552068421000,1552068421000,'个人博客','巴甘的父亲敏山被火车撞死了。他和妈妈一起生活,庄稼活------比如割玉米,由大舅江其布帮忙。大舅独身,只有一皮3岁的雪青骟马。'), +(1552068421000,1552068421000,'个人博客','智联招聘某员工匿名透露:我们内部数据统计,通过大把(千万级)的简历分析得到的结果:。但Python从来不该背锅:!'), +(1552068421000,1552068421000,'个人博客','Python简单。可以把开发者的思想从编程语言的细节里解放出来,更关注实际要解决的问题。'), +(1552068421000,1552068421000,'个人博客','智联招聘某员工匿名透露:我们内部数据统计,通过大把(千万级)的简历分析得到的结果:。但Python从来不该背锅:!'), +(1552068421000,1552068421000,'个人博客','Python简单。可以把开发者的思想从编程语言的细节里解放出来,更关注实际要解决的问题。'), +(1552068421000,1552068421000,'个人博客','智联招聘某员工匿名透露:我们内部数据统计,通过大把(千万级)的简历分析得到的结果:。但Python从来不该背锅:!'); \ No newline at end of file diff --git a/pom.xml b/pom.xml index fc3813da55645a058a1e097625393fd4817c7959..b786ba19d5aad52a9a5423609bd8e114c8036035 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,11 @@ hutool-all 4.1.14 + + + org.springframework.boot + spring-boot-starter-aop + diff --git a/src/main/java/com/library/nbt/aspect/WebLogAcpect.java b/src/main/java/com/library/nbt/aspect/WebLogAcpect.java new file mode 100644 index 0000000000000000000000000000000000000000..c8e270f6083884fea030bf75a4d29fa851702bba --- /dev/null +++ b/src/main/java/com/library/nbt/aspect/WebLogAcpect.java @@ -0,0 +1,58 @@ +package com.library.nbt.aspect; + +import com.alibaba.fastjson.JSON; +import com.library.nbt.utils.DateUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.Arrays; + +/** + * 使用@Aspect注解将一个java类定义为切面类 + * 使用@Pointcut定义一个切入点,可以是一个规则表达式,比如下例中某个package下的所有函数,也可以是一个注解等。 + * 根据需要在切入点不同位置的切入内容 + * 使用@Before在切入点开始处切入内容 + * 使用@After在切入点结尾处切入内容 + * 使用@AfterReturning在切入点return内容之后切入内容(可以用来对处理返回值做一些加工处理) + * 使用@Around在切入点前后切入内容,并自己控制何时执行切入点自身的内容 + * 使用@AfterThrowing用来处理当切入内容部分抛出异常之后的处理逻辑 + */ +@Aspect +@Component +public class WebLogAcpect { + + private static final Logger LOG = LoggerFactory.getLogger(WebLogAcpect.class); + + @Pointcut("execution(public * com.library.nbt.service.impl..*.*(..))") + public void WebLog(){}; + + + @Before("WebLog()") + public void doBefore(JoinPoint joinPoint)throws Exception{ + // 接收到请求,记录请求内容 + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + + // 记录下请求内容 + LOG.info("访问URL接口 : " + request.getRequestURL().toString()); + LOG.info("请求IP : " + request.getRemoteAddr()); + LOG.info("执行类 : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); + LOG.info("运行时间:" + DateUtils.timeStamp2Date(String.valueOf(System.currentTimeMillis()),"yyyy-MM-dd HH:mm:ss")); + } + + @AfterReturning(returning = "ret", pointcut = "WebLog()") + public void doAfterReturning(Object ret) throws Throwable { + // 处理完请求,返回内容 + LOG.info("请求结束,返回数据 : " + JSON.toJSONString(ret)); + LOG.info("运行结束时间:" + DateUtils.timeStamp2Date(String.valueOf(System.currentTimeMillis()),"yyyy-MM-dd HH:mm:ss")); + } +} diff --git a/src/main/java/com/library/nbt/controller/ArticleController.java b/src/main/java/com/library/nbt/controller/ArticleController.java index a2ca1144cacbf494a1511b632c2d25a62580b199..6ee013aa84fde0ced5762b8c5ca1164304353594 100644 --- a/src/main/java/com/library/nbt/controller/ArticleController.java +++ b/src/main/java/com/library/nbt/controller/ArticleController.java @@ -30,7 +30,21 @@ public class ArticleController { private String url; - @ApiOperation(value = "通过ID获取单个文章表", notes = "通过id获取文章信息") + @ApiOperation(value = "通过获取最近文章表", notes = "通过获取最近文章信息") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful request"), + @ApiResponse(code = 500, message = "internal server error")}) + @RequestMapping(value = "/v1/article/lately/{number}", method = RequestMethod.GET) + public Result getEntityNumber(@ApiParam(value = "条数", required = true) @PathVariable(value = "number") Integer number) { + try { + List articleEntityView = articleService.getEntityNumber(number); + return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntityView); + } catch (Exception e) { + return ResultUtil.error(ResultUtil.SUCCESS_CODE_200, e.getMessage()); + } + } + + @ApiOperation(value = "通过id获取文章表", notes = "通过id获取文章信息") @ApiResponses(value = { @ApiResponse(code = 200, message = "successful request"), @ApiResponse(code = 500, message = "internal server error")}) diff --git a/src/main/java/com/library/nbt/controller/CodeController.java b/src/main/java/com/library/nbt/controller/CodeController.java index 3c4752754b6ce4a2d895d779dcf98aaac2bec610..2fa6e80217382c74135a1f03925075f28457feef 100644 --- a/src/main/java/com/library/nbt/controller/CodeController.java +++ b/src/main/java/com/library/nbt/controller/CodeController.java @@ -37,7 +37,7 @@ public class CodeController { Object[] objs = VerifyUtil.createImage(); //将验证码存入Session session.setAttribute("imageCode", objs[0]); - System.out.println("接收前的session:" + session.getId()); +// System.out.println("接收前的session:" + session.getId()); //将图片输出给浏览器 BufferedImage image = (BufferedImage) objs[1]; diff --git a/src/main/java/com/library/nbt/dao/ArticleEntityMapper.java b/src/main/java/com/library/nbt/dao/ArticleEntityMapper.java index e8916d7150f616a7c28f13c314492473e5f0147a..6a4d010f8b5ca82e0a83f4d1f85f681c4de6a6ed 100644 --- a/src/main/java/com/library/nbt/dao/ArticleEntityMapper.java +++ b/src/main/java/com/library/nbt/dao/ArticleEntityMapper.java @@ -3,6 +3,8 @@ package com.library.nbt.dao; import com.library.nbt.model.entity.ArticleEntity; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface ArticleEntityMapper { int deleteByPrimaryKey(Integer id); @@ -16,4 +18,6 @@ public interface ArticleEntityMapper { int updateByPrimaryKeySelective(ArticleEntity record); int updateByPrimaryKey(ArticleEntity record); + + List getEntityNumber(Integer number); } \ No newline at end of file diff --git a/src/main/java/com/library/nbt/dao/UserEntityMapper.java b/src/main/java/com/library/nbt/dao/UserEntityMapper.java index a900c066e1501d1aed5fdbcd2bb69e2a8eb13073..5aa9b88dbe1e6ea753dee0350223d33e2bb6cf1b 100644 --- a/src/main/java/com/library/nbt/dao/UserEntityMapper.java +++ b/src/main/java/com/library/nbt/dao/UserEntityMapper.java @@ -21,5 +21,5 @@ public interface UserEntityMapper { List findAll(); - UserEntity selectByPrimaryUsername(UserEntity userEntity); + UserEntity selectByPrimaryUserEntity(UserEntity userEntity); } \ No newline at end of file diff --git a/src/main/java/com/library/nbt/dao/mapper/ArticleEntityMapper.xml b/src/main/java/com/library/nbt/dao/mapper/ArticleEntityMapper.xml index ca73dd9523fcb4ece3b7807b01351c6d60d1bb7a..3fba6c9b0f16d3f960a289d9e65ba8c9fc80e156 100644 --- a/src/main/java/com/library/nbt/dao/mapper/ArticleEntityMapper.xml +++ b/src/main/java/com/library/nbt/dao/mapper/ArticleEntityMapper.xml @@ -125,4 +125,11 @@ comment_count = #{commentCount,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} + \ No newline at end of file diff --git a/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml b/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml index 23a4936b8395d65d5c3ca8c3e0415cc6f0f4c53a..9912fdd34101dafd9720ef433b59eaabd2308b5c 100644 --- a/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml +++ b/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml @@ -18,11 +18,54 @@ - id, create_time, update_time, enabled, username, nick_name, password, phone, birthday, + id, create_time, update_time, enabled, username, nick_name, password, phone, birthday, age, profile_photo, rights, ip, login_end_time + + + + AND createTime = #{createTime,jdbcType=BIGINT} + + + AND update_time = #{updateTime,jdbcType=BIGINT} + + + AND enabled = #{enabled,jdbcType=INTEGER} + + + AND username = #{username,jdbcType=VARCHAR} + + + AND nick_name = #{nick_name,jdbcType=VARCHAR} + + + AND password = #{password,jdbcType=VARCHAR} + + + AND phone = #{phone,jdbcType=INTEGER} + + + AND birthday = #{birthday,jdbcType=BIGINT} + + + AND age = #{age,jdbcType=INTEGER} + + + AND profile_photo = #{profilePhoto,jdbcType=VARCHAR} + + + AND rights = #{rights,jdbcType=INTEGER} + + + AND ip = #{ip,jdbcType=VARCHAR} + + + AND login_end_time = #{loginEndTime,jdbcType=BIGINT} + + + - select from t_user - where username = #{username,jdbcType=VARCHAR} - AND password = #{password,jdbcType=VARCHAR} + \ No newline at end of file diff --git a/src/main/java/com/library/nbt/service/ArticleService.java b/src/main/java/com/library/nbt/service/ArticleService.java index af4426942f14ea594c86b5851ea7772565ba595f..3495aa0978b0731ebd2415959baa4fc27dc6efca 100644 --- a/src/main/java/com/library/nbt/service/ArticleService.java +++ b/src/main/java/com/library/nbt/service/ArticleService.java @@ -3,5 +3,8 @@ package com.library.nbt.service; import com.library.nbt.model.entity.ArticleEntity; import com.library.nbt.model.view.ArticleEntityView; +import java.util.List; + public interface ArticleService extends BaseService { + List getEntityNumber(Integer number); } diff --git a/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java b/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java index e41375fd32cb576506154a6b47c0c9dd710adca6..adbd7d6bba4f35a66de10925e87225faf4a56531 100644 --- a/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import java.util.ArrayList; import java.util.List; @Service @@ -84,4 +85,15 @@ public class ArticleServiceImpl implements ArticleService { } + @Override + public List getEntityNumber(Integer number) { + List articleEntities = articleEntityMapper.getEntityNumber(number); + List articleEntityViews = new ArrayList<>(); + for (ArticleEntity articleEntity:articleEntities){ + ArticleEntityView articleEntityView = new ArticleEntityView(); + BeanUtils.copyProperties(articleEntity,articleEntityView); + articleEntityViews.add(articleEntityView); + } + return articleEntityViews; + } } diff --git a/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java b/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java index 2c9cbfabe2c702b8daab89f31bfd87ad3c6ee43c..7d9a49f55fa43332ab7bf3cd10c4bae5664b3fcb 100644 --- a/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java +++ b/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java @@ -1,14 +1,10 @@ package com.library.nbt.service.impl; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import com.alibaba.fastjson.JSON; import com.library.nbt.dao.UserEntityMapper; import com.library.nbt.model.entity.UserEntity; import com.library.nbt.model.view.UserEntityView; import com.library.nbt.service.UserService; import com.library.nbt.utils.CusAccessObjectUtil; -import com.library.nbt.utils.ResultUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -19,9 +15,6 @@ import org.springframework.util.ObjectUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; @Service public class UserServiceImpl implements UserService { @@ -33,9 +26,17 @@ public class UserServiceImpl implements UserService { @Override public UserEntityView saveEntity(UserEntityView userEntityView) throws Exception { + UserEntity userEntityResult = new UserEntity(); + userEntityResult.setUsername(userEntityView.getUsername()); + //查询数据库中是否存在用户 + userEntityResult = userEntityMapper.selectByPrimaryUserEntity(userEntityResult); + if (!ObjectUtils.isEmpty(userEntityResult)){ + throw new Exception("账号已被注册"); + } UserEntity userEntity = new UserEntity(); BeanUtils.copyProperties(userEntityView,userEntity); + userEntity.setCreateTime(System.currentTimeMillis()); userEntity.setUpdateTime(System.currentTimeMillis()); userEntity.setEnabled(1); @@ -109,7 +110,7 @@ public class UserServiceImpl implements UserService { if (session.getAttribute("imageCode").toString().equalsIgnoreCase(userEntityView.getCode())) { UserEntity userEntity = new UserEntity(); BeanUtils.copyProperties(userEntityView,userEntity); - UserEntity userEntityResult = userEntityMapper.selectByPrimaryUsername(userEntity); + UserEntity userEntityResult = userEntityMapper.selectByPrimaryUserEntity(userEntity); if (ObjectUtils.isEmpty(userEntityResult)){ throw new NullPointerException("账户不存在或密码错误"); } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 668c8d859fa78cd3a9d565c0aa79b195ec9fc8ed..f76ea49ce5687ae0484192512a0f54d1ec34b6ae 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -33,4 +33,7 @@ logging.config=classpath:log/dev/logback.xml file.rootPath=E: -file.sonPath=/img/ \ No newline at end of file +file.sonPath=/img/ + +#aopע +spring.aop.proxy-target-class=true \ No newline at end of file