diff --git a/star/pom.xml b/star/pom.xml index 12a27dd..e68fffa 100644 --- a/star/pom.xml +++ b/star/pom.xml @@ -71,16 +71,9 @@ ${springboot.version} - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 1.3.2 - - com.alibaba - druid + druid-spring-boot-starter 1.1.10 @@ -126,13 +119,6 @@ 2.5.0 - - - tk.mybatis - mapper-spring-boot-starter - 2.0.4 - - org.slf4j slf4j-api @@ -144,6 +130,20 @@ commons-lang3 3.0 + + + + com.baomidou + mybatis-plus-boot-starter + 2.2.0 + + + + + org.apache.velocity + velocity-engine-core + 2.0 + \ No newline at end of file diff --git a/star/star-biz/src/main/java/com/gui/star/biz/common/BaseService.java b/star/star-biz/src/main/java/com/gui/star/biz/common/BaseService.java deleted file mode 100644 index b006c9b..0000000 --- a/star/star-biz/src/main/java/com/gui/star/biz/common/BaseService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gui.star.biz.common; - -import java.util.List; - -public interface BaseService { - - List findAll(); - - T findById(Long id); - - int save(T t); - - int update(T t); - - int remove(Long id); -} diff --git a/star/star-biz/src/main/java/com/gui/star/biz/common/BaseServiceImpl.java b/star/star-biz/src/main/java/com/gui/star/biz/common/BaseServiceImpl.java deleted file mode 100644 index a906cdc..0000000 --- a/star/star-biz/src/main/java/com/gui/star/biz/common/BaseServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.gui.star.biz.common; - -import java.util.List; - -import com.gui.star.dal.common.CommonMapper; - -public abstract class BaseServiceImpl implements BaseService { - - public abstract CommonMapper getMapper(); - - @Override - public List findAll() { - return getMapper().selectAll(); - } - - @Override - public T findById(Long id) { - return getMapper().selectByPrimaryKey(id); - } - - @Override - public int save(T t) { - return getMapper().insert(t); - } - - @Override - public int remove(Long id) { - return getMapper().deleteByPrimaryKey(id); - } - - @Override - public int update(T t) { - return getMapper().updateByPrimaryKey(t); - } -} diff --git a/star/star-biz/src/main/java/com/gui/star/biz/event/listener/ContainerEventListener.java b/star/star-biz/src/main/java/com/gui/star/biz/event/listener/ContainerEventListener.java index 1ce4230..57b7f66 100644 --- a/star/star-biz/src/main/java/com/gui/star/biz/event/listener/ContainerEventListener.java +++ b/star/star-biz/src/main/java/com/gui/star/biz/event/listener/ContainerEventListener.java @@ -1,12 +1,12 @@ package com.gui.star.biz.event.listener; +import com.gui.star.biz.event.events.TestEvent; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import com.gui.star.biz.event.events.TestEvent; - /** * spring事件监听器 * @@ -23,6 +23,7 @@ * */ @Component +@Slf4j public class ContainerEventListener { /** * 监听容器启动事件 @@ -34,10 +35,10 @@ public class ContainerEventListener { * * 2.容器的启动完成了表明所有的bean都已经完成了注册,而且bean之间的相互依赖也完成了 * - * 3.容器启动完成和我们定义的Application启动类极其包含的main方法完全是两个概念。前者的时间发生在前面,Application.main()的作用在于启动容器里面的应用程序(比如我们的saturn) + * 3.容器启动完成和我们定义的Application启动类极其包含的main方法完全是两个概念。前者的时间发生在前面,Application.main()的作用在于启动容器里面的应用程序 * * - * @param ContextRefreshedEvent + * @param event */ @Async @EventListener @@ -50,13 +51,13 @@ public void afterContainerStartup(ContextRefreshedEvent event) { /** * 监听所有的TestEvent类型事件 - * + * + * @Async标识方法异步执行 */ @Async @EventListener public void handleTestEvent(TestEvent event) { + log.info("我的测试事件开始执行了,测试内容:{}" , event.getEventContent()); // 可以调用本地业务处理逻辑,也可以调用远程的发送短信、邮件等服务。 - - System.out.println("我的测试事件开始执行了,测试内容:" + event.getEventContent()); } } diff --git a/star/star-biz/src/main/java/com/gui/star/biz/service/UserService.java b/star/star-biz/src/main/java/com/gui/star/biz/service/UserService.java index 0ad6364..64a2b32 100644 --- a/star/star-biz/src/main/java/com/gui/star/biz/service/UserService.java +++ b/star/star-biz/src/main/java/com/gui/star/biz/service/UserService.java @@ -13,5 +13,5 @@ public interface UserService { */ List queryList(); - void save(UserForm form); + Long save(UserForm form); } diff --git a/star/star-biz/src/main/java/com/gui/star/biz/service/impl/UserServiceImpl.java b/star/star-biz/src/main/java/com/gui/star/biz/service/impl/UserServiceImpl.java index edc4965..c128559 100644 --- a/star/star-biz/src/main/java/com/gui/star/biz/service/impl/UserServiceImpl.java +++ b/star/star-biz/src/main/java/com/gui/star/biz/service/impl/UserServiceImpl.java @@ -1,30 +1,23 @@ package com.gui.star.biz.service.impl; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.gui.star.biz.common.BaseServiceImpl; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.gui.star.biz.service.UserService; import com.gui.star.biz.vo.UserVo; import com.gui.star.common.form.UserForm; import com.gui.star.common.util.DomainUtil; import com.gui.star.common.util.ObjectUtil; -import com.gui.star.dal.common.CommonMapper; import com.gui.star.dal.mapper.UserMapper; import com.gui.star.dal.model.User; - import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; @Service @Slf4j -public class UserServiceImpl extends BaseServiceImpl implements UserService { - @Autowired - private UserMapper userMapper; - +public class UserServiceImpl extends ServiceImpl implements UserService { /** * 查询用户信息列表 */ @@ -32,7 +25,7 @@ public class UserServiceImpl extends BaseServiceImpl implements UserServic public List queryList() { List userVoList = new ArrayList(); - List userList = userMapper.selectByExample(null); + List userList = this.selectList(null); for (User user : userList) { UserVo userVo = new UserVo(); BeanUtils.copyProperties(user, userVo); @@ -41,21 +34,16 @@ public List queryList() { return userVoList; } - @Override - public CommonMapper getMapper() { - return this.userMapper; - } - /** * 保存用户信息 */ @Override - public void save(UserForm form) { + public Long save(UserForm form) { User user = ObjectUtil.source2Target(form, User.class); DomainUtil.setCommonValueForCreate(user); - userMapper.insertSelective(user); + this.insert(user); - log.info("用户ID为:{}", user.getId()); + return user.getId(); } } diff --git a/star/star-common/pom.xml b/star/star-common/pom.xml index d29e51e..8b0a2e7 100644 --- a/star/star-common/pom.xml +++ b/star/star-common/pom.xml @@ -40,5 +40,20 @@ org.apache.commons commons-lang3 + + + io.springfox + springfox-swagger-ui + + + + io.springfox + springfox-swagger2 + + + + com.alibaba + fastjson + diff --git a/star/star-common/src/main/java/com/gui/star/common/form/UserForm.java b/star/star-common/src/main/java/com/gui/star/common/form/UserForm.java index a004f78..8ccf3a5 100644 --- a/star/star-common/src/main/java/com/gui/star/common/form/UserForm.java +++ b/star/star-common/src/main/java/com/gui/star/common/form/UserForm.java @@ -1,16 +1,24 @@ package com.gui.star.common.form; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data +@ApiModel("用户对象信息封装") public class UserForm { + @ApiModelProperty(value = "ID") private Long id; + @ApiModelProperty(value = "登录名", required = true) private String loginname; + @ApiModelProperty(value = "密码", required = true) private String password; + @ApiModelProperty(value = "邮箱") private String email; + @ApiModelProperty(value = "联系电话") private String phone; } \ No newline at end of file diff --git a/star/star-common/src/main/java/com/gui/star/common/util/Result.java b/star/star-common/src/main/java/com/gui/star/common/util/Result.java index 7d67ff7..f7058b6 100644 --- a/star/star-common/src/main/java/com/gui/star/common/util/Result.java +++ b/star/star-common/src/main/java/com/gui/star/common/util/Result.java @@ -1,12 +1,11 @@ package com.gui.star.common.util; -import java.io.Serializable; - import com.gui.star.common.enums.CodeEnum; - import lombok.Data; import lombok.extern.slf4j.Slf4j; +import java.io.Serializable; + /** * * @author wuhoujian @@ -17,7 +16,6 @@ * 数据 以json格式返回客户端请求的数据 */ @Data -@SuppressWarnings("serial") @Slf4j public class Result implements Serializable { private T data; diff --git a/star/star-dal/pom.xml b/star/star-dal/pom.xml index b00ac7b..ca5d30d 100644 --- a/star/star-dal/pom.xml +++ b/star/star-dal/pom.xml @@ -22,14 +22,8 @@ - org.mybatis.spring.boot - mybatis-spring-boot-starter - - - - - tk.mybatis - mapper-spring-boot-starter + com.baomidou + mybatis-plus-boot-starter diff --git a/star/star-dal/src/main/java/com/gui/star/dal/common/CommonMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/common/CommonMapper.java deleted file mode 100644 index a506399..0000000 --- a/star/star-dal/src/main/java/com/gui/star/dal/common/CommonMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.gui.star.dal.common; - -import tk.mybatis.mapper.common.Mapper; - -public interface CommonMapper extends Mapper { - -} diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuMapper.java index 955cd81..7a96beb 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.Menu; -public interface MenuMapper extends CommonMapper{ +public interface MenuMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuRoleMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuRoleMapper.java index bf5e26d..3ad0bbd 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuRoleMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/MenuRoleMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.MenuRole; -public interface MenuRoleMapper extends CommonMapper{ +public interface MenuRoleMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionMapper.java index 1ca9775..dfde81d 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.Permission; -public interface PermissionMapper extends CommonMapper{ +public interface PermissionMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionRoleMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionRoleMapper.java index db4c4cc..47c6a9c 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionRoleMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/PermissionRoleMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.PermissionRole; -public interface PermissionRoleMapper extends CommonMapper{ +public interface PermissionRoleMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/RoleMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/RoleMapper.java index c24e061..b447cf1 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/RoleMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/RoleMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.Role; -public interface RoleMapper extends CommonMapper{ +public interface RoleMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserMapper.java index 55b6b59..29c324b 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.User; -public interface UserMapper extends CommonMapper{ +public interface UserMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserRoleMapper.java b/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserRoleMapper.java index 504e9b6..7856415 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserRoleMapper.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/mapper/UserRoleMapper.java @@ -1,8 +1,8 @@ package com.gui.star.dal.mapper; -import com.gui.star.dal.common.CommonMapper; +import com.baomidou.mybatisplus.mapper.BaseMapper; import com.gui.star.dal.model.UserRole; -public interface UserRoleMapper extends CommonMapper{ +public interface UserRoleMapper extends BaseMapper { } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/Menu.java b/star/star-dal/src/main/java/com/gui/star/dal/model/Menu.java index 5ae63be..c4857d6 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/Menu.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/Menu.java @@ -1,7 +1,10 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableName; + import java.util.Date; +@TableName() public class Menu { private Long id; diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/MenuRole.java b/star/star-dal/src/main/java/com/gui/star/dal/model/MenuRole.java index 391e00d..369e30e 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/MenuRole.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/MenuRole.java @@ -1,8 +1,16 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + import java.util.Date; +@TableName("menu_role") +@Data public class MenuRole { + @TableId(type = IdType.AUTO) private Long id; private Long menuId; @@ -14,52 +22,4 @@ public class MenuRole { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getMenuId() { - return menuId; - } - - public void setMenuId(Long menuId) { - this.menuId = menuId; - } - - public Long getRoleId() { - return roleId; - } - - public void setRoleId(Long roleId) { - this.roleId = roleId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/Permission.java b/star/star-dal/src/main/java/com/gui/star/dal/model/Permission.java index 6f2f830..6ade834 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/Permission.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/Permission.java @@ -1,8 +1,16 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + import java.util.Date; +@TableName("permission") +@Data public class Permission { + @TableId(type = IdType.AUTO) private Long id; private String name; @@ -14,52 +22,4 @@ public class Permission { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public String getResValue() { - return resValue; - } - - public void setResValue(String resValue) { - this.resValue = resValue == null ? null : resValue.trim(); - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/PermissionRole.java b/star/star-dal/src/main/java/com/gui/star/dal/model/PermissionRole.java index 811ecfc..a093883 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/PermissionRole.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/PermissionRole.java @@ -1,8 +1,16 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + import java.util.Date; +@TableName("permission_role") +@Data public class PermissionRole { + @TableId(type = IdType.AUTO) private Long id; private Long permissionId; @@ -14,52 +22,4 @@ public class PermissionRole { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getPermissionId() { - return permissionId; - } - - public void setPermissionId(Long permissionId) { - this.permissionId = permissionId; - } - - public Long getRoleId() { - return roleId; - } - - public void setRoleId(Long roleId) { - this.roleId = roleId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/Role.java b/star/star-dal/src/main/java/com/gui/star/dal/model/Role.java index 2dba157..64fe7b4 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/Role.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/Role.java @@ -1,8 +1,16 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + import java.util.Date; +@TableName("role") +@Data public class Role { + @TableId(type = IdType.AUTO) private Long id; private String name; @@ -12,44 +20,4 @@ public class Role { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/User.java b/star/star-dal/src/main/java/com/gui/star/dal/model/User.java index f55e91c..4c64aa9 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/User.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/User.java @@ -1,14 +1,16 @@ package com.gui.star.dal.model; -import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import java.util.Date; +@Data +@TableName("user") public class User { - @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @TableId(type = IdType.AUTO) private Long id; private String loginname; @@ -24,68 +26,4 @@ public class User { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getLoginname() { - return loginname; - } - - public void setLoginname(String loginname) { - this.loginname = loginname == null ? null : loginname.trim(); - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password == null ? null : password.trim(); - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email == null ? null : email.trim(); - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone == null ? null : phone.trim(); - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/java/com/gui/star/dal/model/UserRole.java b/star/star-dal/src/main/java/com/gui/star/dal/model/UserRole.java index d1a7a6e..8494317 100644 --- a/star/star-dal/src/main/java/com/gui/star/dal/model/UserRole.java +++ b/star/star-dal/src/main/java/com/gui/star/dal/model/UserRole.java @@ -1,8 +1,16 @@ package com.gui.star.dal.model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + import java.util.Date; +@TableName("user_role") +@Data public class UserRole { + @TableId(type = IdType.AUTO) private Long id; private Long userId; @@ -14,52 +22,4 @@ public class UserRole { private Date updatedAt; private Byte deleted; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } - - public Long getRoleId() { - return roleId; - } - - public void setRoleId(Long roleId) { - this.roleId = roleId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Byte getDeleted() { - return deleted; - } - - public void setDeleted(Byte deleted) { - this.deleted = deleted; - } } \ No newline at end of file diff --git a/star/star-dal/src/main/resources/generatorConfig.xml b/star/star-dal/src/main/resources/generatorConfig.xml deleted file mode 100644 index e8979c1..0000000 --- a/star/star-dal/src/main/resources/generatorConfig.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - -
- - -
- - -
- - -
- - -
-
-
\ No newline at end of file diff --git a/star/star-dal/src/main/resources/mapper/UserMapper.xml b/star/star-dal/src/main/resources/mapper/UserMapper.xml index 1344ffa..6097212 100644 --- a/star/star-dal/src/main/resources/mapper/UserMapper.xml +++ b/star/star-dal/src/main/resources/mapper/UserMapper.xml @@ -1,5 +1,14 @@ - + + + + + + + + + + \ No newline at end of file diff --git a/star/star-web/pom.xml b/star/star-web/pom.xml index 4e04819..722e818 100644 --- a/star/star-web/pom.xml +++ b/star/star-web/pom.xml @@ -34,11 +34,6 @@ spring-boot-starter-web - - org.mybatis.spring.boot - mybatis-spring-boot-starter - - org.springframework.boot spring-boot-starter-test @@ -46,7 +41,7 @@ com.alibaba - druid + druid-spring-boot-starter @@ -62,6 +57,16 @@ io.springfox springfox-swagger-ui + + + com.baomidou + mybatis-plus-boot-starter + + + + com.alibaba + fastjson + star-web diff --git a/star/star-web/src/main/java/com/gui/star/web/Application.java b/star/star-web/src/main/java/com/gui/star/web/Application.java index aaef832..1a0c1c8 100644 --- a/star/star-web/src/main/java/com/gui/star/web/Application.java +++ b/star/star-web/src/main/java/com/gui/star/web/Application.java @@ -1,13 +1,13 @@ package com.gui.star.web; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; -import tk.mybatis.spring.annotation.MapperScan; - /** * SpringBoot启动类 * @@ -19,8 +19,9 @@ @SpringBootApplication @ComponentScan(basePackages = "com.gui") @MapperScan(basePackages = "com.gui.star.dal.mapper") -@EnableAutoConfiguration @EnableScheduling +@EnableAsync +@ServletComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); diff --git a/star/star-web/src/main/java/com/gui/star/web/config/FilterConfig.java b/star/star-web/src/main/java/com/gui/star/web/config/FilterConfig.java new file mode 100644 index 0000000..609a6f9 --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/config/FilterConfig.java @@ -0,0 +1,46 @@ +package com.gui.star.web.config; + +import com.gui.star.web.filter.CustomFilter; +import com.gui.star.web.filter.CustomFollowFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * 过滤器第二种使用方式配置 + */ +@Configuration +public class FilterConfig { + @Bean + public FilterRegistrationBean filterRegistrationBean(){ + FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + + CustomFilter customFilter = new CustomFilter(); + registrationBean.setFilter(customFilter); + registrationBean.setOrder(10);//设置过滤器执行的先后顺序 + + List urlPatterns = new ArrayList(); + urlPatterns.add("/*"); + registrationBean.setUrlPatterns(urlPatterns); + + return registrationBean; + } + + @Bean + public FilterRegistrationBean filterRegistrationBean1(){ + FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + + CustomFollowFilter customFollowFilter = new CustomFollowFilter(); + registrationBean.setFilter(customFollowFilter); + registrationBean.setOrder(1); + + List urlPatterns = new ArrayList(); + urlPatterns.add("/*"); + registrationBean.setUrlPatterns(urlPatterns); + + return registrationBean; + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/config/InterceptorConfig.java b/star/star-web/src/main/java/com/gui/star/web/config/InterceptorConfig.java new file mode 100644 index 0000000..e429bdc --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/config/InterceptorConfig.java @@ -0,0 +1,26 @@ +package com.gui.star.web.config; + +import com.gui.star.web.interceptors.LogInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 拦截器配置类(实现WebMvcConfigurer接口) + */ +@Configuration +public class InterceptorConfig implements WebMvcConfigurer { + @Autowired + private LogInterceptor logInterceptor; + + /** + * 注册自定义的拦截器类 + * @param registry + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 加入自定义拦截器,这里可以根据实际需要对各个url添加不同的拦截器 + registry.addInterceptor(logInterceptor).addPathPatterns("/**/**"); + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/controller/TestController.java b/star/star-web/src/main/java/com/gui/star/web/controller/TestController.java index 4a69a2a..13f95a2 100644 --- a/star/star-web/src/main/java/com/gui/star/web/controller/TestController.java +++ b/star/star-web/src/main/java/com/gui/star/web/controller/TestController.java @@ -1,36 +1,36 @@ package com.gui.star.web.controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.gui.star.biz.event.events.TestEvent; +import com.gui.star.common.util.Result; import com.gui.star.common.util.SpringContextUtil; - +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import springfox.documentation.annotations.ApiIgnore; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; /** * 我的测试控制器 - * - * @author wuhoujian * + * @author wuhoujian */ -@ApiIgnore +@Api(value = "测试管理Api", tags = "测试相关操作") @RestController @RequestMapping("/test") public class TestController { + @ApiOperation(value = "打招呼sayHi", notes = "打招呼sayHi", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @RequestMapping(value = "/sayHi", method = RequestMethod.GET) + public Result sayHi() { + return Result.generateSuccess("Hello, SpringBoot!"); + } - @ApiOperation(value = "打招呼sayHi", notes = "打招呼sayHi") - @RequestMapping("/sayHi") - public String sayHi() { - return "Hello, SpringBoot!"; - } + @ApiOperation(value = "测试事件发布", notes = "测试事件发布", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @RequestMapping(value = "/testEvent", method = RequestMethod.POST) + public Result testEvent() { + // 发布事件 + SpringContextUtil.getApplicationContext().publishEvent(new TestEvent(this, "我的测试事件")); - @ApiOperation(value = "测试事件发布", notes = "测试事件发布") - @RequestMapping("/testEvent") - public String testEvent() { - // 发布插入登录日志事件 - SpringContextUtil.getApplicationContext().publishEvent(new TestEvent(this, "我的测试事件")); - return "事件发布成功,事件执行结果见控制台输出。"; - } + return Result.generateSuccess("事件发布成功,事件执行结果见控制台输出。"); + } } diff --git a/star/star-web/src/main/java/com/gui/star/web/controller/UserController.java b/star/star-web/src/main/java/com/gui/star/web/controller/UserController.java index 64a51e9..f1c402b 100644 --- a/star/star-web/src/main/java/com/gui/star/web/controller/UserController.java +++ b/star/star-web/src/main/java/com/gui/star/web/controller/UserController.java @@ -1,71 +1,49 @@ package com.gui.star.web.controller; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - import com.gui.star.biz.service.UserService; import com.gui.star.biz.vo.UserVo; import com.gui.star.common.form.UserForm; import com.gui.star.common.util.Result; - import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; /** * 用户管理控制器 - * - * 注解@ApiOperation用来给API增加说明 - * - * 注解@ApiImplicitParams和@ApiImplicitParam用来给参数增加说明 - * * @author wuhoujian - * */ @Api(value = "用户管理Api", tags = "用户相关操作") @RestController @RequestMapping("/user") public class UserController { - @Autowired - private UserService userService; - - @ApiOperation(value = "查看用户列表", notes = "查看所有用户信息列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - @ApiImplicitParam(name = "id", value = "用户ID", required = false, dataType = "Long") - @RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST }) - public String list() { - List userList = userService.queryList(); - if (!CollectionUtils.isEmpty(userList)) { - for (UserVo user : userList) { - System.out.println(user.getLoginname() + "===" + user.getPassword()); - } - } - - return "Hello, SpringBoot! I have " + userList.size() + "个用户!"; - } - - /** - * 保存用户信息 - * - * @param form - * @return - */ - @ApiOperation(value = "保存用户信息", notes = "保存用户信息", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - @ApiImplicitParams(value = { - @ApiImplicitParam(name = "loginname", value = "登录名", required = true, dataType = "string", paramType = "query"), - @ApiImplicitParam(name = "password", value = "登录密码", required = true, dataType = "string", paramType = "query"), - @ApiImplicitParam(name = "email", value = "邮箱", required = false, dataType = "string", paramType = "query") }) - @RequestMapping(value = "/save", method = { RequestMethod.GET, RequestMethod.POST }) - public Result save(UserForm form) { - userService.save(form); - - return Result.generateSuccess("保存成功"); - } + @Autowired + private UserService userService; + + @ApiOperation(value = "查看用户列表", notes = "查看所有用户信息列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @RequestMapping(value = "/list", method = RequestMethod.POST) + public Result> list() { + List userList = userService.queryList(); + + return Result.generateSuccess(userList); + } + + /** + * 保存用户信息 + * + * @param form + * @return + */ + @ApiOperation(value = "保存用户信息", notes = "保存用户信息", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @RequestMapping(value = "/save", method = RequestMethod.POST) + public Result save(@ModelAttribute UserForm form) { + return Result.generateSuccess(userService.save(form)); + } } diff --git a/star/star-web/src/main/java/com/gui/star/web/executor/MyExecutor.java b/star/star-web/src/main/java/com/gui/star/web/executor/MyExecutor.java index 03b48a8..dfb82e4 100644 --- a/star/star-web/src/main/java/com/gui/star/web/executor/MyExecutor.java +++ b/star/star-web/src/main/java/com/gui/star/web/executor/MyExecutor.java @@ -13,8 +13,8 @@ public class MyExecutor { // @Scheduled(cron = "0 0 1 ? * MON"),每周一凌晨1点执行 - // 每5秒执行 - @Scheduled(fixedRate = 5000) + // 每分钟执行 + @Scheduled(fixedRate = 60000) public void sayName() { System.out.println("My name is William..."); } diff --git a/star/star-web/src/main/java/com/gui/star/web/filter/AcustomFollowFilter1.java b/star/star-web/src/main/java/com/gui/star/web/filter/AcustomFollowFilter1.java new file mode 100644 index 0000000..66ba898 --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/filter/AcustomFollowFilter1.java @@ -0,0 +1,39 @@ +package com.gui.star.web.filter; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import java.io.IOException; + +/** + * 利用WebFilter注解配置,启动类要结合@ServletComponentScan注解 + */ +@WebFilter(filterName = "acustomFollowFilter1", urlPatterns = "/*") +@Slf4j +public class AcustomFollowFilter1 implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + log.info("AcustomFollowFilter1初始化..."); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + log.info("doFilter in AcustomFollowFilter1请求处理...."); + + //对request、response进行一些预处理,比如设置请求编码 + // request.setCharacterEncoding("UTF-8"); + // response.setCharacterEncoding("UTF-8"); + + //TODO 进行业务逻辑 + + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + log.info("AcustomFollowFilter1销毁..."); + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter.java b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter.java new file mode 100644 index 0000000..88ca260 --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter.java @@ -0,0 +1,33 @@ +package com.gui.star.web.filter; + +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.*; +import java.io.IOException; + +@Slf4j +public class CustomFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + log.info("CustomFilter初始化..."); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + log.info("doFilter in CustomFilter请求处理...."); + + //对request、response进行一些预处理,比如设置请求编码 + // request.setCharacterEncoding("UTF-8"); + // response.setCharacterEncoding("UTF-8"); + + //TODO 进行业务逻辑 + + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + log.info("CustomFilter销毁..."); + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter1.java b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter1.java new file mode 100644 index 0000000..505d31f --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFilter1.java @@ -0,0 +1,39 @@ +package com.gui.star.web.filter; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import java.io.IOException; + +/** + * 利用WebFilter注解配置,启动类要结合@ServletComponentScan注解 + */ +@WebFilter(filterName = "customFilter1", urlPatterns = "/*") +@Slf4j +public class CustomFilter1 implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + log.info("CustomFilter1初始化..."); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + log.info("doFilter in CustomFilter1请求处理...."); + + //对request、response进行一些预处理,比如设置请求编码 + // request.setCharacterEncoding("UTF-8"); + // response.setCharacterEncoding("UTF-8"); + + //TODO 进行业务逻辑 + + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + log.info("CustomFilter1销毁..."); + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/filter/CustomFollowFilter.java b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFollowFilter.java new file mode 100644 index 0000000..8f330b2 --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/filter/CustomFollowFilter.java @@ -0,0 +1,33 @@ +package com.gui.star.web.filter; + +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.*; +import java.io.IOException; + +@Slf4j +public class CustomFollowFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + log.info("CustomFollowFilter初始化..."); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + log.info("doFilter in CustomFollowFilter请求处理...."); + + //对request、response进行一些预处理,比如设置请求编码 + // request.setCharacterEncoding("UTF-8"); + // response.setCharacterEncoding("UTF-8"); + + //TODO 进行业务逻辑 + + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + log.info("CustomFollowFilter销毁..."); + } +} diff --git a/star/star-web/src/main/java/com/gui/star/web/interceptors/LogInterceptor.java b/star/star-web/src/main/java/com/gui/star/web/interceptors/LogInterceptor.java new file mode 100644 index 0000000..add9208 --- /dev/null +++ b/star/star-web/src/main/java/com/gui/star/web/interceptors/LogInterceptor.java @@ -0,0 +1,34 @@ +package com.gui.star.web.interceptors; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 自定义拦截器(继承HandlerInterceptorAdapter类) + */ +@Configuration +@Slf4j +public class LogInterceptor extends HandlerInterceptorAdapter { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + log.info("请求前调用:preHandle" ); + return super.preHandle(request, response, handler); + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + log.info("请求后调用:postHandle"); + super.postHandle(request, response, handler, modelAndView); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + log.info("请求调用完成后回调方法:afterCompletion"); + super.afterCompletion(request, response, handler, ex); + } +} diff --git a/star/star-web/src/main/resources/application.yml b/star/star-web/src/main/resources/application.yml index 2390eef..cf64596 100644 --- a/star/star-web/src/main/resources/application.yml +++ b/star/star-web/src/main/resources/application.yml @@ -8,7 +8,18 @@ spring: initialSize: 2 minIdle: 2 maxActive: 10 - -mybatis: - mapper-locations: classpath:mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径 - type-aliases-package: com.gui.star.dal.model # 注意:对应实体类的路径 \ No newline at end of file + +#mybatis: +# mapper-locations: classpath:mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径 +# type-aliases-package: com.gui.star.dal.model # 注意:对应实体类的路径 + +mybatis-plus: + mapper-locations: classpath:mapper/**/*.xml #注意:一定要对应mapper映射xml文件的所在路径 + type-aliases-package: com.gui.star.dal.model + configuration: + map-underscore-to-camel-case: true + # 配置slq打印日志 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +server: + port: 8700 \ No newline at end of file diff --git a/star/star-web/src/main/resources/logback-spring.xml b/star/star-web/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..c9dbac4 --- /dev/null +++ b/star/star-web/src/main/resources/logback-spring.xml @@ -0,0 +1,52 @@ + + + + + + + + ${user.home}/logs/${LOG_FILE_NAME}.log + + ${user.home}/logs/%d{yyyy-MM-dd}/${LOG_FILE_NAME}.%i.log + 100 + 50MB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${user.home}/logs/${LOG_FILE_NAME}-error.log + + ${user.home}/logs/%d{yyyy-MM-dd}/${LOG_FILE_NAME}-error.%i.log + 100 + 50MB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + ERROR + ACCEPT + DENY + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + + + + \ No newline at end of file diff --git a/star/star-web/src/main/resources/template/controller.java.vm b/star/star-web/src/main/resources/template/controller.java.vm new file mode 100644 index 0000000..d070747 --- /dev/null +++ b/star/star-web/src/main/resources/template/controller.java.vm @@ -0,0 +1,187 @@ +package ${package.Controller}; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +#if(${restControllerStyle}) +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +#else +import org.springframework.stereotype.Controller; +#end +#if(${superControllerClassPackage}) +import ${superControllerClassPackage}; +#end +import org.springframework.beans.factory.annotation.Autowired; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import ${package.Service}.${table.serviceName}; +import com.lgq.boot.util.TableJSON; +import com.lgq.boot.util.JSONResult; +import ${package.Entity}.${entity}; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import io.swagger.annotations.*; +import java.util.Date; + +/** + *code is far away from bug with the animal protecting + * ┏┓   ┏┓ + *┏┛┻━━━┛┻┓ + *┃       ┃   + *┃   ━   ┃ + *┃ ┳┛ ┗┳ ┃ + *┃       ┃ + *┃   ┻   ┃ + *┃       ┃ + *┗━┓   ┏━┛ + *  ┃   ┃神兽保佑 + *  ┃   ┃代码无BUG! + *  ┃   ┗━━━┓ + *  ┃       ┣┓ + *  ┃       ┏┛ + *  ┗┓┓┏━┳┓┏┛ + *   ┃┫┫ ┃┫┫ + *   ┗┻┛ ┗┻┛ + *   + * @description : ${entity} 控制器 + * --------------------------------- + * @author ${author} + * @since ${date} + */ +#if(${restControllerStyle}) +@RestController +#else +@Controller +#end +@Api(value="#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end", description="${entity} 控制器") +@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") +#if(${superControllerClass}) +public class ${table.controllerName} extends ${superControllerClass} { +#else +public class ${table.controllerName} { +#end + private final Logger logger = LoggerFactory.getLogger(${table.controllerName}.class); + + @Autowired + public ${table.serviceName} ${table.entityPath}Service; + + /** + * @description : 获取分页列表 + * --------------------------------- + * @author : ${author} + * @since : Create in ${date} + */ + @GetMapping("/get${entity}List") + @ApiOperation(value="/get${entity}List", notes="获取分页列表") + public TableJSON<${entity}> get${entity}List(@ApiParam(name="${entity}",value="${entity} 实体类")${entity} param , + @ApiParam(name="length",value="页大小",required=true,defaultValue = "10")Integer length, + @ApiParam(name="pageNo",value="页数",required=true,defaultValue = "1")Integer pageNo) { + TableJSON<${entity}> resJson=new TableJSON<>(); + if(param.getBeginDate() == null) { + if (param.getEndDate() == null) { + param.setBeginDate(getMonthFirstDay(new Date())); + } else { param.setBeginDate(getMonthFirstDay(param.getEndDate())); } + } + if(param.getEndDate() == null) { + param.setEndDate(getMonthLastDay(new Date())); + } + try { + Page<${entity}> page=new Page<${entity}>(pageNo,length); + ${table.entityPath}Service.selectPageWithParam(page, param); + resJson.setRecordsTotal(page.getTotal()); + resJson.setData(page.getRecords()); + resJson.setSuccess(true); + }catch (Exception e){ + resJson.setSuccess(false); + resJson.setMessage("异常信息:"+e.getClass().getName()); + logger.info("异常信息:{}",e.getMessage()); + } + return resJson; + } + + /** + * @description : 通过id获取${entity} + * --------------------------------- + * @author : ${author} + * @since : Create in ${date} + */ + @GetMapping("/get${entity}ById") + @ApiOperation(value="/get${entity}ById", notes="通过id获取${entity}") + public JSONResult<${entity}> get${entity}ById(@ApiParam(name="id",value="${entity}ID",required=true)Long id) { + JSONResult<${entity}> resJson = new JSONResult<>(); + try { + ${entity} param= ${table.entityPath}Service.selectOneByObj(id); + resJson.setData(param); + resJson.setSuccess(true); + }catch (Exception e) { + resJson.setSuccess(false); + resJson.setMessage("异常信息:"+e.getClass().getName()); + logger.info("异常信息:{}",e.getMessage()); + } + return resJson; + } + + /** + * @description : 通过id删除${entity} + * --------------------------------- + * @author : ${author} + * @since : Create in ${date} + */ + @DeleteMapping("/delete${entity}ById") + @ApiOperation(value="/delete${entity}ById", notes="通过id删除${entity}") + public JSONResult<${entity}> delete${entity}ById(@ApiParam(name="id",value="${entity}ID",required=true)Long id) { + JSONResult<${entity}> resJson = new JSONResult<>(); + try{ + resJson.setSuccess(${table.entityPath}Service.deleteById(id)); + }catch (Exception e) { + resJson.setSuccess(false); + resJson.setMessage("异常信息:"+e.getClass().getName()); + logger.info("异常信息:{}",e.getMessage()); + } + return resJson; + } + + /** + * @description : 通过id更新${entity} + * --------------------------------- + * @author : ${author} + * @since : Create in ${date} + */ + @PutMapping("/update${entity}ById") + @ApiOperation(value="/update${entity}ById", notes="通过id更新${entity}") + public JSONResult<${entity}> update${entity}ById(@ApiParam(name="${entity}",value="${entity} 实体类")${entity} param) { + JSONResult<${entity}> resJson = new JSONResult<>(); + try{ + resJson.setSuccess(${table.entityPath}Service.updateById(param)); + }catch (Exception e) { + resJson.setSuccess(false); + resJson.setMessage("异常信息:"+e.getClass().getName()); + logger.info("异常信息:{}",e.getMessage()); + } + return resJson; + } + + /** + * @description : 添加${entity} + * --------------------------------- + * @author : ${author} + * @since : Create in ${date} + */ + @PutMapping("/add${entity}") + @ApiOperation(value="/add${entity}", notes="添加${entity}") + public JSONResult<${entity}> add${entity}(@ApiParam(name="${entity}",value="${entity} 实体类")${entity} param) { + JSONResult<${entity}> resJson = new JSONResult<>(); + try{ + resJson.setSuccess(${table.entityPath}Service.insert(param)); + }catch (Exception e) { + resJson.setSuccess(false); + resJson.setMessage("异常信息:"+e.getClass().getName()); + logger.info("异常信息:{}",e.getMessage()); + } + return resJson; + } +} diff --git a/star/star-web/src/main/resources/template/entity.java.vm b/star/star-web/src/main/resources/template/entity.java.vm new file mode 100644 index 0000000..e015fdc --- /dev/null +++ b/star/star-web/src/main/resources/template/entity.java.vm @@ -0,0 +1,164 @@ +package ${package.Entity}; + +#if(${activeRecord}) +import java.io.Serializable; + +#end +#foreach($pkg in ${table.importPackages}) +import ${pkg}; +#end +#if(${entityLombokModel}) + +import com.baomidou.mybatisplus.annotations.Version; + +import lombok.Data; +import lombok.experimental.Accessors; +#end +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; +import io.swagger.annotations.ApiModelProperty; + +/** + *code is far away from bug with the animal protecting + * ┏┓   ┏┓ + *┏┛┻━━━┛┻┓ + *┃       ┃   + *┃   ━   ┃ + *┃ ┳┛ ┗┳ ┃ + *┃       ┃ + *┃   ┻   ┃ + *┃       ┃ + *┗━┓   ┏━┛ + *  ┃   ┃神兽保佑 + *  ┃   ┃代码无BUG! + *  ┃   ┗━━━┓ + *  ┃       ┣┓ + *  ┃       ┏┛ + *  ┗┓┓┏━┳┓┏┛ + *   ┃┫┫ ┃┫┫ + *   ┗┻┛ ┗┻┛ + *   + * @description : ${entity} 实体类 + * --------------------------------- + * @author ${author} + * @since ${date} + */ +#if(${entityLombokModel}) +@Data +@Accessors(chain = true) +#end +#if(${table.convert}) +@TableName("${table.name}") +#end +#if(${superEntityClass}) +public class ${entity} extends ${superEntityClass}#*#if(${activeRecord})<${entity}>#end*# { +#elseif(${activeRecord}) +public class ${entity} extends Model<${entity}> { +#else +public class ${entity} implements Serializable { +#end + + private static final long serialVersionUID = 1L; + +## ---------- BEGIN 字段循环遍历 ---------- +#foreach($field in ${table.fields}) +#if(${field.keyFlag}) +#set($keyPropertyName=${field.propertyName}) +#end +#if("$!field.comment" != "") + /** + * ${field.comment} + */ + @ApiModelProperty("${field.comment}") +#end +#if(${field.keyFlag}) +## 主键 +#if(${field.keyIdentityFlag}) + @TableId(value="${field.name}", type= IdType.AUTO) +#elseif(${field.convert}) + @TableId("${field.name}") +#end +## 普通字段 +#elseif(${field.fill}) +## ----- 存在字段填充设置 ----- +#if(${field.convert}) + @TableField(value = "${field.name}", fill = FieldFill.${field.fill}) +#else + @TableField(fill = FieldFill.${field.fill}) +#end +#elseif(${field.convert}) + @TableField("${field.name}") +#end +## 乐观锁注解 +#if(${versionFieldName}==${field.name}) + @Version +#end +## 逻辑删除注解 +#if(${logicDeleteFieldName}==${field.name}) + @TableLogic +#end +#if(${field.propertyType}=="Date") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") +#end + private ${field.propertyType} ${field.propertyName}; +#end +## ---------- END 字段循环遍历 ---------- + +#if(!${entityLombokModel}) +#foreach($field in ${table.fields}) +#if(${field.propertyType.equals("boolean")}) +#set($getprefix="is") +#else +#set($getprefix="get") +#end + + public ${field.propertyType} ${getprefix}${field.capitalName}() { + return ${field.propertyName}; + } + +#if(${entityBuilderModel}) + public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#else + public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#end + this.${field.propertyName} = ${field.propertyName}; +#if(${entityBuilderModel}) + return this; +#end + } +#end +#end + +#if(${entityColumnConstant}) +#foreach($field in ${table.fields}) + public static final String ${field.name.toUpperCase()} = "${field.name}"; + +#end +#end +#*#if(${activeRecord}) + @Override + protected Serializable pkVal() { +#if(${keyPropertyName}) + return this.${keyPropertyName}; +#else + return this.id; +#end + } + +#end*# +#if(!${entityLombokModel}) + @Override + public String toString() { + return "${entity}{" + +#foreach($field in ${table.fields}) +#if($!{velocityCount}==1) + "${field.propertyName}=" + ${field.propertyName} + +#else + ", ${field.propertyName}=" + ${field.propertyName} + +#end +#end + "}"; + } +#end +} \ No newline at end of file diff --git a/star/star-web/src/main/resources/template/mapper.java.vm b/star/star-web/src/main/resources/template/mapper.java.vm new file mode 100644 index 0000000..5fe0886 --- /dev/null +++ b/star/star-web/src/main/resources/template/mapper.java.vm @@ -0,0 +1,38 @@ +package ${package.Mapper}; + +import ${package.Entity}.${entity}; +import ${superMapperClassPackage}; +import org.springframework.stereotype.Repository; +import com.baomidou.mybatisplus.plugins.Page; + +import java.util.List; + +/** + *code is far away from bug with the animal protecting + * ┏┓   ┏┓ + *┏┛┻━━━┛┻┓ + *┃       ┃   + *┃   ━   ┃ + *┃ ┳┛ ┗┳ ┃ + *┃       ┃ + *┃   ┻   ┃ + *┃       ┃ + *┗━┓   ┏━┛ + *  ┃   ┃神兽保佑 + *  ┃   ┃代码无BUG! + *  ┃   ┗━━━┓ + *  ┃       ┣┓ + *  ┃       ┏┛ + *  ┗┓┓┏━┳┓┏┛ + *   ┃┫┫ ┃┫┫ + *   ┗┻┛ ┗┻┛ + *   + * @description : ${entity} Mapper 接口 + * --------------------------------- + * @author ${author} + * @since ${date} + */ +@Repository +public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { + +} \ No newline at end of file diff --git a/star/star-web/src/main/resources/template/mapper.xml.vm b/star/star-web/src/main/resources/template/mapper.xml.vm new file mode 100644 index 0000000..10d2df6 --- /dev/null +++ b/star/star-web/src/main/resources/template/mapper.xml.vm @@ -0,0 +1,63 @@ + + + + +#if(${enableCache}) + + + +#end +#if(${baseResultMap}) + + +#foreach($field in ${table.fields}) +#if(${field.keyFlag})##生成主键排在第一位 + +#end +#end +#foreach($field in ${table.commonFields})##生成公共字段 + +#end +#foreach($field in ${table.fields}) +#if(!${field.keyFlag})##生成普通字段 + +#end +#end + + +#end +#if(${baseColumnList}) + + +#foreach($field in ${table.commonFields}) + #if(${field.name} == ${field.propertyName})${field.name}#else${field.name} AS ${field.propertyName}#end, +#end + ${table.fieldNames} + + +#end + + + + \ No newline at end of file diff --git a/star/star-web/src/main/resources/template/service.java.vm b/star/star-web/src/main/resources/template/service.java.vm new file mode 100644 index 0000000..46670a8 --- /dev/null +++ b/star/star-web/src/main/resources/template/service.java.vm @@ -0,0 +1,33 @@ +package ${package.Service}; + +import ${package.Entity}.${entity}; +import ${superServiceClassPackage}; + +/** + *code is far away from bug with the animal protecting + * ┏┓   ┏┓ + *┏┛┻━━━┛┻┓ + *┃       ┃   + *┃   ━   ┃ + *┃ ┳┛ ┗┳ ┃ + *┃       ┃ + *┃   ┻   ┃ + *┃       ┃ + *┗━┓   ┏━┛ + *  ┃   ┃神兽保佑 + *  ┃   ┃代码无BUG! + *  ┃   ┗━━━┓ + *  ┃       ┣┓ + *  ┃       ┏┛ + *  ┗┓┓┏━┳┓┏┛ + *   ┃┫┫ ┃┫┫ + *   ┗┻┛ ┗┻┛ + *   + * @description : ${entity} 服务接口 + * --------------------------------- + * @author ${author} + * @since ${date} + */ +public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { + +} \ No newline at end of file diff --git a/star/star-web/src/main/resources/template/serviceImpl.java.vm b/star/star-web/src/main/resources/template/serviceImpl.java.vm new file mode 100644 index 0000000..e04848e --- /dev/null +++ b/star/star-web/src/main/resources/template/serviceImpl.java.vm @@ -0,0 +1,37 @@ +package ${package.ServiceImpl}; + +import ${package.Entity}.${entity}; +import ${package.Mapper}.${table.mapperName}; +import ${package.Service}.${table.serviceName}; +import ${superServiceImplClassPackage}; +import org.springframework.stereotype.Service; + +/** + *code is far away from bug with the animal protecting + * ┏┓   ┏┓ + *┏┛┻━━━┛┻┓ + *┃       ┃   + *┃   ━   ┃ + *┃ ┳┛ ┗┳ ┃ + *┃       ┃ + *┃   ┻   ┃ + *┃       ┃ + *┗━┓   ┏━┛ + *  ┃   ┃神兽保佑 + *  ┃   ┃代码无BUG! + *  ┃   ┗━━━┓ + *  ┃       ┣┓ + *  ┃       ┏┛ + *  ┗┓┓┏━┳┓┏┛ + *   ┃┫┫ ┃┫┫ + *   ┗┻┛ ┗┻┛ + *   + * @description : ${entity} 服务实现类 + * --------------------------------- + * @author ${author} + * @since ${date} + */ +@Service +public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { + +} \ No newline at end of file