标签调整,优化
This commit is contained in:
@@ -8,8 +8,8 @@ import org.springframework.cache.annotation.EnableCaching;
|
||||
@EnableCaching
|
||||
public class JiccussApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JiccussApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JiccussApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,10 +49,11 @@ public class UserPageController {
|
||||
|
||||
/**
|
||||
* 用户页面
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/user")
|
||||
public String user( @RequestParam(defaultValue = "discussion") String type, ModelMap map) {
|
||||
public String user(@RequestParam(defaultValue = "discussion") String type, ModelMap map) {
|
||||
|
||||
if (type.equals("discussion")) {
|
||||
map.put("discussion", "active");
|
||||
|
||||
@@ -119,8 +119,8 @@ public class UserPostController extends BaseController {
|
||||
if (null != discussion.getTag()) {
|
||||
//执行组装标签
|
||||
String[] strArray = discussion.getTag().split(",");
|
||||
for(String str : strArray){
|
||||
DiscussionTag dtag= new DiscussionTag();
|
||||
for (String str : strArray) {
|
||||
DiscussionTag dtag = new DiscussionTag();
|
||||
dtag.setDiscussionId(saveDiscussion.getId());
|
||||
dtag.setTagId(Integer.parseInt(str));
|
||||
iDiscussionsTagsService.insert(dtag);
|
||||
@@ -201,15 +201,16 @@ public class UserPostController extends BaseController {
|
||||
|
||||
/**
|
||||
* 新建主题页
|
||||
*
|
||||
* @param request
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping({"/newDiscussionsPage"})
|
||||
public String newdiccuss( HttpServletRequest request, ModelMap map) {
|
||||
public String newdiccuss(HttpServletRequest request, ModelMap map) {
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
List<Tag> allTags = tagsService.getAllListDiscussions();
|
||||
map.put("allTags", allTags);
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
@@ -222,12 +223,13 @@ public class UserPostController extends BaseController {
|
||||
|
||||
/**
|
||||
* 新建标签页
|
||||
*
|
||||
* @param request
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping({"/newTagPage"})
|
||||
public String newtag( HttpServletRequest request, ModelMap map) {
|
||||
public String newtag(HttpServletRequest request, ModelMap map) {
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
|
||||
@@ -41,6 +41,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 首页index
|
||||
*
|
||||
* @param tag
|
||||
* @param type
|
||||
* @param pageNum
|
||||
@@ -49,8 +50,8 @@ public class UserSystemController extends BaseController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping({"/", "/main", "/index"})
|
||||
public String home(@RequestParam(defaultValue = "all") String tag, @RequestParam(defaultValue = "all") String type, @RequestParam(defaultValue = "1") Integer
|
||||
pageNum, HttpServletRequest request, ModelMap map) {
|
||||
public String home(@RequestParam(defaultValue = "all") String tag, @RequestParam(defaultValue = "all") String type,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum, HttpServletRequest request, ModelMap map) {
|
||||
logger.info(">>> index");
|
||||
logger.info(">>> tag:" + tag);
|
||||
logger.info(">>> pageNum:" + pageNum);
|
||||
@@ -64,7 +65,7 @@ public class UserSystemController extends BaseController {
|
||||
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<DiscussionCustom> newAllD = new ArrayList<>();
|
||||
|
||||
setTagAndUserList(newAllD,allDiscussions);
|
||||
setTagAndUserList(newAllD, allDiscussions);
|
||||
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
|
||||
@@ -77,6 +78,12 @@ public class UserSystemController extends BaseController {
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}", allTags);
|
||||
|
||||
if(!tag.equals("all")){
|
||||
//获取是否有子标签
|
||||
List<Tag> allChildTags = tagsService.findByParentId(tag);
|
||||
map.put("allChildTags", allChildTags);
|
||||
}
|
||||
|
||||
map.put("data", "Jiscuss 用户");
|
||||
map.put("allDiscussions", newAllD);
|
||||
map.put("allUser", usersService.getAllList());
|
||||
@@ -108,6 +115,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 组装DiscussionCustom
|
||||
*
|
||||
* @param newAllD
|
||||
* @param allDiscussions
|
||||
*/
|
||||
@@ -122,13 +130,13 @@ public class UserSystemController extends BaseController {
|
||||
Map<Integer, List<TagCustom>> tagMap = new HashMap<>();
|
||||
for (TagCustom tc : TagCustomList) {
|
||||
List<TagCustom> tagCustomListTemp = new ArrayList<>();
|
||||
if(tagMap.containsKey(tc.getDiscussionId())){
|
||||
if (tagMap.containsKey(tc.getDiscussionId())) {
|
||||
tagCustomListTemp = tagMap.get(tc.getDiscussionId());
|
||||
tagCustomListTemp.add(tc);
|
||||
tagMap.put(tc.getDiscussionId(),tagCustomListTemp);
|
||||
}else{
|
||||
tagMap.put(tc.getDiscussionId(), tagCustomListTemp);
|
||||
} else {
|
||||
tagCustomListTemp.add(tc);
|
||||
tagMap.put(tc.getDiscussionId(),tagCustomListTemp);
|
||||
tagMap.put(tc.getDiscussionId(), tagCustomListTemp);
|
||||
}
|
||||
}
|
||||
for (Discussion dd : allDiscussions) {
|
||||
@@ -162,6 +170,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 分页信息
|
||||
*
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
@@ -176,6 +185,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 登录页
|
||||
*
|
||||
* @param error
|
||||
* @param logout
|
||||
* @param map
|
||||
@@ -199,6 +209,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 注册提交
|
||||
*
|
||||
* @param username
|
||||
* @param email
|
||||
* @param password
|
||||
@@ -228,6 +239,7 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
/**
|
||||
* 注册页面
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/register")
|
||||
|
||||
@@ -21,8 +21,8 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path="/other_api",produces="application/json;charset=utf-8")
|
||||
@Api(value = "主题帖子(其他)接口管理", tags = { "主题帖子(其他)接口管理"})
|
||||
@RequestMapping(path = "/other_api", produces = "application/json;charset=utf-8")
|
||||
@Api(value = "主题帖子(其他)接口管理", tags = {"主题帖子(其他)接口管理"})
|
||||
public class RestPostController {
|
||||
private static Logger logger = LoggerFactory.getLogger(RestPostController.class);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RestPostController {
|
||||
@ApiOperation("新增主题")
|
||||
public Discussion save(@RequestBody Discussion discussion) {
|
||||
Discussion saveDiscussion = discussionsService.insert(discussion);
|
||||
if (saveDiscussion !=null) {
|
||||
if (saveDiscussion != null) {
|
||||
return saveDiscussion;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
@@ -52,7 +52,7 @@ public class RestPostController {
|
||||
@ApiOperation("获取全部主题")
|
||||
public List<Discussion> getAllDiscussions() {
|
||||
List<Discussion> allDiscussions = discussionsService.getAllList();
|
||||
logger.info("全部主题==>:{}",allDiscussions);
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
return allDiscussions;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,62 +24,62 @@ import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user_api")
|
||||
@Api(value = "用户接口管理", tags = { "用户接口管理" })
|
||||
@Api(value = "用户接口管理", tags = {"用户接口管理"})
|
||||
public class RestUserController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RestUserController.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(RestUserController.class);
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
@PostMapping("/user")
|
||||
@ApiOperation("新增用户")
|
||||
public User save(@RequestBody User user) {
|
||||
User saveUser = usersService.insert(user);
|
||||
if (saveUser!=null) {
|
||||
return saveUser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
@PostMapping("/user")
|
||||
@ApiOperation("新增用户")
|
||||
public User save(@RequestBody User user) {
|
||||
User saveUser = usersService.insert(user);
|
||||
if (saveUser != null) {
|
||||
return saveUser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
@ApiOperation("删除用户")
|
||||
public Boolean delete(@PathVariable Integer id) {
|
||||
Boolean delete = true;
|
||||
usersService.remove(id);
|
||||
if (delete) {
|
||||
return delete;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
@DeleteMapping("/user/{id}")
|
||||
@ApiOperation("删除用户")
|
||||
public Boolean delete(@PathVariable Integer id) {
|
||||
Boolean delete = true;
|
||||
usersService.remove(id);
|
||||
if (delete) {
|
||||
return delete;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/user/{id}")
|
||||
@ApiOperation("修改用户")
|
||||
public User update(@RequestBody User user, @PathVariable Integer id) {
|
||||
User updateuser = usersService.update(user, id);
|
||||
if (updateuser!=null) {
|
||||
return updateuser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
@PutMapping("/user/{id}")
|
||||
@ApiOperation("修改用户")
|
||||
public User update(@RequestBody User user, @PathVariable Integer id) {
|
||||
User updateuser = usersService.update(user, id);
|
||||
if (updateuser != null) {
|
||||
return updateuser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("获取用户")
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
User user = usersService.findOne(id);
|
||||
return user;
|
||||
}
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("获取用户")
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
User user = usersService.findOne(id);
|
||||
return user;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("获取全部用户")
|
||||
public List<User> getUser(User user) {
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info("全部用户==>:{}",userall);
|
||||
return userall;
|
||||
}
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("获取全部用户")
|
||||
public List<User> getUser(User user) {
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info("全部用户==>:{}", userall);
|
||||
return userall;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,67 +11,68 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussion")
|
||||
@Table(name = "discussion")
|
||||
public class Discussion implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", unique = true)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="title")
|
||||
private String title;
|
||||
|
||||
@Column(name="content")
|
||||
private String content;
|
||||
|
||||
@Column(name="comments_count")
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="participants_count")
|
||||
private Integer participantsCount;
|
||||
|
||||
@Column(name="number_index")
|
||||
private Integer numberIndex;
|
||||
|
||||
@Column(name="start_time")
|
||||
private Date startTime;
|
||||
|
||||
@Column(name="start_user_id")
|
||||
private Integer startUserId;
|
||||
|
||||
@Column(name="start_post_id")
|
||||
private Integer startPostId;
|
||||
|
||||
@Column(name="last_time")
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_user_id")
|
||||
private Integer lastUserId;
|
||||
|
||||
@Column(name="last_post_id")
|
||||
private Integer lastPostId;
|
||||
|
||||
@Column(name="last_post_number")
|
||||
private Integer lastPostNumber;
|
||||
|
||||
@Column(name="is_approved")
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="like_count")
|
||||
private Integer likeCount;
|
||||
|
||||
|
||||
@Column(name="ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date createTime;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", unique = true)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
|
||||
@Column(name = "content")
|
||||
private String content;
|
||||
|
||||
@Column(name = "comments_count")
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name = "participants_count")
|
||||
private Integer participantsCount;
|
||||
|
||||
@Column(name = "number_index")
|
||||
private Integer numberIndex;
|
||||
|
||||
@Column(name = "start_time")
|
||||
private Date startTime;
|
||||
|
||||
@Column(name = "start_user_id")
|
||||
private Integer startUserId;
|
||||
|
||||
@Column(name = "start_post_id")
|
||||
private Integer startPostId;
|
||||
|
||||
@Column(name = "last_time")
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name = "last_user_id")
|
||||
private Integer lastUserId;
|
||||
|
||||
@Column(name = "last_post_id")
|
||||
private Integer lastPostId;
|
||||
|
||||
@Column(name = "last_post_number")
|
||||
private Integer lastPostNumber;
|
||||
|
||||
@Column(name = "is_approved")
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name = "like_count")
|
||||
private Integer likeCount;
|
||||
|
||||
|
||||
@Column(name = "ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name = "create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,21 +5,22 @@ import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussiontag")
|
||||
public class DiscussionTag implements Serializable{
|
||||
@Table(name = "discussiontag")
|
||||
public class DiscussionTag implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
@Column(name = "discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="tag_id")
|
||||
|
||||
@Column(name = "tag_id")
|
||||
private Integer tagId;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="likecollect")
|
||||
@Table(name = "likecollect")
|
||||
public class LikeCollect implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -23,40 +23,40 @@ public class LikeCollect implements Serializable {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
@Column(name = "discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="discussion_name")
|
||||
@Column(name = "discussion_name")
|
||||
private String discussionName;
|
||||
|
||||
@Column(name="tag_id")
|
||||
@Column(name = "tag_id")
|
||||
private Integer tagId;
|
||||
|
||||
@Column(name="post_id")
|
||||
@Column(name = "post_id")
|
||||
private Integer postId;
|
||||
|
||||
@Column(name="post_content")
|
||||
@Column(name = "post_content")
|
||||
private String postContent;
|
||||
|
||||
@Column(name="user_id")
|
||||
@Column(name = "user_id")
|
||||
private Integer userId;
|
||||
|
||||
@Column(name="user_name")
|
||||
@Column(name = "user_name")
|
||||
private String userName;
|
||||
|
||||
@Column(name="type")
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
@Column(name="like_type")
|
||||
@Column(name = "like_type")
|
||||
private String likeType;
|
||||
|
||||
@Column(name="collect_type")
|
||||
@Column(name = "collect_type")
|
||||
private String collectType;
|
||||
|
||||
@Column(name="create_id")
|
||||
@Column(name = "create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,54 +14,54 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="post")
|
||||
public class Post implements Serializable{
|
||||
@Table(name = "post")
|
||||
public class Post implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
|
||||
@Column(name = "discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="number")
|
||||
|
||||
@Column(name = "number")
|
||||
private Integer number;
|
||||
|
||||
@Column(name="time")
|
||||
|
||||
@Column(name = "time")
|
||||
private Date time;
|
||||
|
||||
@Column(name="user_id")
|
||||
|
||||
@Column(name = "user_id")
|
||||
private Integer userId;
|
||||
|
||||
@Column(name="type")
|
||||
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
@Column(name="content")
|
||||
|
||||
@Column(name = "content")
|
||||
private String content;
|
||||
|
||||
@Column(name="parent_id")
|
||||
@Column(name = "parent_id")
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="edit_time")
|
||||
|
||||
@Column(name = "edit_time")
|
||||
private Date editTime;
|
||||
|
||||
@Column(name="edit_user_id")
|
||||
|
||||
@Column(name = "edit_user_id")
|
||||
private Integer editUserId;
|
||||
|
||||
@Column(name="ip_address")
|
||||
|
||||
@Column(name = "ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="copyright")
|
||||
|
||||
@Column(name = "copyright")
|
||||
private String copyright;
|
||||
|
||||
@Column(name="is_approved")
|
||||
|
||||
@Column(name = "is_approved")
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="create_id")
|
||||
|
||||
@Column(name = "create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,20 +8,20 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="setting")
|
||||
public class Setting implements Serializable{
|
||||
@Table(name = "setting")
|
||||
public class Setting implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="setting_key")
|
||||
@Column(name = "setting_key")
|
||||
private String settingKey;
|
||||
|
||||
@Column(name="setting_value")
|
||||
|
||||
@Column(name = "setting_value")
|
||||
private String settingValue;
|
||||
}
|
||||
|
||||
@@ -14,44 +14,44 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="tag")
|
||||
public class Tag implements Serializable{
|
||||
@Table(name = "tag")
|
||||
public class Tag implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="name")
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name="description")
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name="color")
|
||||
|
||||
@Column(name = "color")
|
||||
private String color;
|
||||
|
||||
@Column(name="icon")
|
||||
@Column(name = "icon")
|
||||
private String icon;
|
||||
|
||||
@Column(name="position")
|
||||
|
||||
@Column(name = "position")
|
||||
private Integer position;
|
||||
|
||||
@Column(name="parent_id")
|
||||
|
||||
@Column(name = "parent_id")
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
@Column(name = "discussions_count")
|
||||
private String discussionsCount;
|
||||
|
||||
@Column(name="last_time")
|
||||
|
||||
@Column(name = "last_time")
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_discussion_id")
|
||||
|
||||
@Column(name = "last_discussion_id")
|
||||
private Integer lastDiscussionId;
|
||||
|
||||
@Column(name="create_id")
|
||||
|
||||
@Column(name = "create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
@@ -15,62 +15,60 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="user")
|
||||
@Table(name = "user")
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="username")
|
||||
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
|
||||
@Column(name="realname")
|
||||
|
||||
@Column(name = "realname")
|
||||
private String realname;
|
||||
|
||||
@Column(name="email")
|
||||
|
||||
@Column(name = "email")
|
||||
private String email;
|
||||
|
||||
@Column(name="password")
|
||||
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
|
||||
@Column(name="join_time")
|
||||
|
||||
@Column(name = "join_time")
|
||||
private Date joinTime;
|
||||
|
||||
@Column(name="age")
|
||||
|
||||
@Column(name = "age")
|
||||
private Integer age;
|
||||
|
||||
@Column(name="gender")
|
||||
|
||||
@Column(name = "gender")
|
||||
private String gender;
|
||||
|
||||
@Column(name="avatar")
|
||||
@Column(name = "avatar")
|
||||
private String avatar;
|
||||
|
||||
@Column(name="phone")
|
||||
|
||||
@Column(name = "phone")
|
||||
private String phone;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
|
||||
@Column(name = "discussions_count")
|
||||
private Integer discussionsCount;
|
||||
|
||||
@Column(name="comments_count")
|
||||
|
||||
@Column(name = "comments_count")
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="last_seen_time")
|
||||
|
||||
@Column(name = "last_seen_time")
|
||||
private Date lastSeenTime;
|
||||
|
||||
@Column(name="flag")
|
||||
|
||||
@Column(name = "flag")
|
||||
private Integer flag;
|
||||
|
||||
@Column(name="level")
|
||||
|
||||
@Column(name = "level")
|
||||
private Integer level;
|
||||
|
||||
}
|
||||
@@ -15,74 +15,74 @@ import java.util.Set;
|
||||
* @date 2020/7/16 14:55
|
||||
*/
|
||||
@Data
|
||||
public class UserInfo implements UserDetails{
|
||||
public class UserInfo implements UserDetails {
|
||||
|
||||
private Collection<GrantedAuthority> authorities;
|
||||
private String password;
|
||||
private String username;
|
||||
private String phone;
|
||||
private Integer age;
|
||||
private Integer id;
|
||||
private String realname;
|
||||
private String email;
|
||||
private String gender;
|
||||
private Integer level;
|
||||
private Integer flag;
|
||||
private Collection<GrantedAuthority> authorities;
|
||||
private String password;
|
||||
private String username;
|
||||
private String phone;
|
||||
private Integer age;
|
||||
private Integer id;
|
||||
private String realname;
|
||||
private String email;
|
||||
private String gender;
|
||||
private Integer level;
|
||||
private Integer flag;
|
||||
|
||||
public UserInfo() {
|
||||
}
|
||||
public UserInfo() {
|
||||
}
|
||||
|
||||
public UserInfo(Collection<GrantedAuthority> authorities, Integer id, String password, String username, String phone) {
|
||||
this.authorities = authorities;
|
||||
this.id = id;
|
||||
this.password = password;
|
||||
this.username = username;
|
||||
this.phone = phone;
|
||||
}
|
||||
public UserInfo(Collection<GrantedAuthority> authorities, Integer id, String password, String username, String phone) {
|
||||
this.authorities = authorities;
|
||||
this.id = id;
|
||||
this.password = password;
|
||||
this.username = username;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"authorities=" + authorities +
|
||||
", password='" + password + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
'}';
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"authorities=" + authorities +
|
||||
", password='" + password + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,5 +36,4 @@ public class PostCustom extends Post {
|
||||
private List<PostCustom> child;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,21 +20,21 @@ import javax.persistence.GenerationType;
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
public class TagCustom {
|
||||
public class TagCustom {
|
||||
|
||||
@Column(name="name")
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name="description")
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name="color")
|
||||
@Column(name = "color")
|
||||
private String color;
|
||||
|
||||
@Column(name="icon")
|
||||
@Column(name = "icon")
|
||||
private String icon;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
@Column(name = "discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@ import lombok.EqualsAndHashCode;
|
||||
* 业务异常类,继承运行时异常,确保事务正常回滚
|
||||
*
|
||||
* @author NULL
|
||||
* @since 2019-07-16
|
||||
* @since 2019-07-16
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class BaseException extends RuntimeException{
|
||||
public class BaseException extends RuntimeException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private ResponseCode code;
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private ResponseCode code;
|
||||
|
||||
public BaseException(ResponseCode code) {
|
||||
this.code = code;
|
||||
|
||||
@@ -17,48 +17,48 @@ import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* 处理无权请求
|
||||
* @author charlie
|
||||
*
|
||||
* @author charlie
|
||||
*/
|
||||
@Component
|
||||
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
|
||||
private Logger log = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response,
|
||||
AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||
boolean isAjax = ControllerTools.isAjaxRequest(request);
|
||||
System.out.println("CustomAccessDeniedHandler handle");
|
||||
if (!response.isCommitted()) {
|
||||
if (isAjax) {
|
||||
String msg = accessDeniedException.getMessage();
|
||||
log.info("accessDeniedException.message:" + msg);
|
||||
String accessDenyMsg = "{\"code\":\"403\",\"msg\":\"没有权限\"}";
|
||||
ControllerTools.print(response, accessDenyMsg);
|
||||
} else {
|
||||
request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/403");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response,
|
||||
AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||
boolean isAjax = ControllerTools.isAjaxRequest(request);
|
||||
System.out.println("CustomAccessDeniedHandler handle");
|
||||
if (!response.isCommitted()) {
|
||||
if (isAjax) {
|
||||
String msg = accessDeniedException.getMessage();
|
||||
log.info("accessDeniedException.message:" + msg);
|
||||
String accessDenyMsg = "{\"code\":\"403\",\"msg\":\"没有权限\"}";
|
||||
ControllerTools.print(response, accessDenyMsg);
|
||||
} else {
|
||||
request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/403");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class ControllerTools {
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
}
|
||||
public static class ControllerTools {
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
}
|
||||
|
||||
public static void print(HttpServletResponse response, String msg) throws IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.write(msg);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
public static void print(HttpServletResponse response, String msg) throws IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.write(msg);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,19 +9,19 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* RBAC数据模型控制权限
|
||||
* @author charlie
|
||||
*
|
||||
* @author charlie
|
||||
*/
|
||||
@Component("rbacPermission")
|
||||
public class RbacPermission{
|
||||
public class RbacPermission {
|
||||
|
||||
private AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
private AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
|
||||
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
|
||||
Object principal = authentication.getPrincipal();
|
||||
boolean hasPermission = false;
|
||||
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
|
||||
Object principal = authentication.getPrincipal();
|
||||
boolean hasPermission = false;
|
||||
|
||||
hasPermission = true;
|
||||
hasPermission = true;
|
||||
// if (principal instanceof UserEntity) {
|
||||
// // 读取用户所拥有的权限菜单
|
||||
// List<Menu> menus = ((UserEntity) principal).getRoleMenus();
|
||||
@@ -33,6 +33,6 @@ public class RbacPermission{
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return hasPermission;
|
||||
}
|
||||
return hasPermission;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,11 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsRepository extends JpaRepository<Discussion,Integer> {
|
||||
public interface DiscussionsRepository extends JpaRepository<Discussion, Integer> {
|
||||
|
||||
@Query(value = "SELECT * from discussion where id in (\n" +
|
||||
"SELECT discussion_id from discussiontag where tag_id = ?1 ) ", nativeQuery = true)
|
||||
Page<Discussion> findByQuery(String tagId, Pageable pageable);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsTagsRepository extends JpaRepository<DiscussionTag,Integer> {
|
||||
public interface DiscussionsTagsRepository extends JpaRepository<DiscussionTag, Integer> {
|
||||
}
|
||||
|
||||
@@ -11,15 +11,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
public interface PostsRepository extends JpaRepository<Post, Integer> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dId
|
||||
* @return
|
||||
*/
|
||||
@Query("from Post where discussionId = :dId")
|
||||
List<Post> findOneBy(@Param("dId")Integer dId);
|
||||
List<Post> findOneBy(@Param("dId") Integer dId);
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
@@ -28,7 +27,7 @@ public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findPostCustomById(@Param("dId")Integer dId);
|
||||
List<Map<String, Object>> findPostCustomById(@Param("dId") Integer dId);
|
||||
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
@@ -38,7 +37,7 @@ public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId and p.parent_id is null order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNull(@Param("dId") Integer dId);
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
@@ -47,7 +46,7 @@ public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId and p.parent_id is not null order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNotNull(@Param("dId") Integer dId);
|
||||
|
||||
|
||||
// @Query("from Post where parentId is null and discussionId = :dId")
|
||||
|
||||
@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SettingsRepository extends JpaRepository<Setting,Integer> {
|
||||
public interface SettingsRepository extends JpaRepository<Setting, Integer> {
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TagsRepository extends JpaRepository<Tag,Integer> {
|
||||
public interface TagsRepository extends JpaRepository<Tag, Integer> {
|
||||
|
||||
@Query(value = "FROM Tag a, DiscussionTag b WHERE a.id = b.tagId and b.discussionId = :dId")
|
||||
List<Tag> findByDId(@Param("dId")Integer dId);
|
||||
List<Tag> findByDId(@Param("dId") Integer dId);
|
||||
|
||||
|
||||
@Query("select new com.yaoyuan.jiscuss.entity.custom.TagCustom(" +
|
||||
@@ -23,4 +23,8 @@ public interface TagsRepository extends JpaRepository<Tag,Integer> {
|
||||
"where u.id=d.tagId and d.discussionId in (:discussionIdlist)")
|
||||
List<TagCustom> findByDiscussionIdlistId(@Param(value = "discussionIdlist") List<Integer> discussionIdlist);
|
||||
|
||||
List<Tag> findByParentId(Integer tagId);
|
||||
|
||||
@Query(value = "FROM Tag a WHERE a.parentId is null")
|
||||
List<Tag> findAllIsNull();
|
||||
}
|
||||
|
||||
@@ -11,37 +11,33 @@ import com.yaoyuan.jiscuss.entity.User;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface UsersRepository extends JpaRepository<User,Integer> {
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username like %:username%")
|
||||
List<User> getByUsernameIsLike(@Param("username")String username);
|
||||
public interface UsersRepository extends JpaRepository<User, Integer> {
|
||||
/**
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username like %:username%")
|
||||
List<User> getByUsernameIsLike(@Param("username") String username);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
User getById(Integer id);
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
User getById(Integer id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username")
|
||||
User getByUsername(String username);
|
||||
/**
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username")
|
||||
User getByUsername(String username);
|
||||
|
||||
/**
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username and password = :password")
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username and password = :password")
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,20 +7,21 @@ import lombok.Data;
|
||||
|
||||
/**
|
||||
* 统一的公共响应体
|
||||
*
|
||||
* @author NULL
|
||||
* @date 2019-12-16
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ResponseResult implements Serializable {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
@@ -13,6 +13,6 @@ public interface IDiscussionsService {
|
||||
Discussion insert(Discussion discussion);
|
||||
|
||||
Discussion findOne(Integer id);
|
||||
|
||||
|
||||
Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNumNew, int pageSiz, String tag, String type);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,8 @@ public interface ITagsService {
|
||||
List<Tag> findByDId(Integer id);
|
||||
|
||||
List<TagCustom> findByDiscussionIdlistId(List<Integer> discussionIdLsit);
|
||||
|
||||
List<Tag> findByParentId(String tag);
|
||||
|
||||
List<Tag> getAllListDiscussions();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ public interface IUsersService {
|
||||
Page<User> queryAllUsersList(int pageNum, int pageSize);
|
||||
|
||||
List<User> getByUsernameIsLike(String name);
|
||||
|
||||
// @Cacheable("myCache")
|
||||
|
||||
// @Cacheable("myCache")
|
||||
User findOne(Integer id);
|
||||
|
||||
User insert(User user);
|
||||
@@ -22,10 +22,10 @@ public interface IUsersService {
|
||||
void remove(Integer id);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
User getByUsername(String username);
|
||||
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
User getByUsername(String username);
|
||||
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
User update(User user, Integer id);
|
||||
|
||||
|
||||
@@ -37,22 +37,22 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize,String tag,String type) {
|
||||
public Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize, String tag, String type) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
||||
if(type.equals("hot")){
|
||||
if (type.equals("hot")) {
|
||||
sort = new Sort(Sort.Direction.DESC, "likeCount");
|
||||
}else if(type.equals("new")){
|
||||
} else if (type.equals("new")) {
|
||||
sort = new Sort(Sort.Direction.DESC, "startTime");
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable = new PageRequest(pageNum, pageSize, sort);
|
||||
//将匹配对象封装成Example对象
|
||||
Example<Discussion> example = Example.of(discussion);
|
||||
if(null!=tag && !"all".equals(tag)){
|
||||
Page<Discussion> pageList= discussionsRepository.findByQuery(tag, pageable);
|
||||
if (null != tag && !"all".equals(tag)) {
|
||||
Page<Discussion> pageList = discussionsRepository.findByQuery(tag, pageable);
|
||||
return pageList;
|
||||
}else{
|
||||
Page<Discussion> pageList= discussionsRepository.findAll(example, pageable);
|
||||
} else {
|
||||
Page<Discussion> pageList = discussionsRepository.findAll(example, pageable);
|
||||
return pageList;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,11 @@ public class TagsServiceImpl implements ITagsService {
|
||||
|
||||
@Override
|
||||
public List<Tag> getAllList() {
|
||||
return tagsRepository.findAllIsNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getAllListDiscussions() {
|
||||
return tagsRepository.findAll();
|
||||
}
|
||||
|
||||
@@ -37,6 +42,12 @@ public class TagsServiceImpl implements ITagsService {
|
||||
public List<TagCustom> findByDiscussionIdlistId(List<Integer> discussionIdLsit) {
|
||||
return tagsRepository.findByDiscussionIdlistId(discussionIdLsit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> findByParentId(String tag){
|
||||
int tagId = Integer.parseInt(tag);
|
||||
return tagsRepository.findByParentId(tagId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
@@ -20,7 +18,7 @@ import org.springframework.cache.annotation.Cacheable;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.repository.UsersRepository;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class UsersServiceImpl implements IUsersService {
|
||||
@@ -29,6 +27,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 获取全部用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(value = "user")
|
||||
@@ -39,20 +38,22 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<User> queryAllUsersList(int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
Pageable pageable = new PageRequest(pageNum, pageSize, sort);
|
||||
return usersRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@@ -63,6 +64,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@@ -74,6 +76,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@@ -85,6 +88,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 更新修改
|
||||
*
|
||||
* @param user
|
||||
* @param id
|
||||
* @return
|
||||
@@ -97,12 +101,13 @@ public class UsersServiceImpl implements IUsersService {
|
||||
|
||||
/**
|
||||
* 移除
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@CacheEvict(value = "user", key = "#id")
|
||||
@Override
|
||||
public void remove(Integer id) {
|
||||
usersRepository.deleteById(id);
|
||||
usersRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,29 +115,31 @@ public class UsersServiceImpl implements IUsersService {
|
||||
*/
|
||||
@Override
|
||||
public void deleteAll() {
|
||||
usersRepository.deleteAll();
|
||||
usersRepository.deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称查询
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User getByUsername(String username) {
|
||||
return usersRepository.getByUsername(username);
|
||||
}
|
||||
@Override
|
||||
public User getByUsername(String username) {
|
||||
return usersRepository.getByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户名密码
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User checkByUsernameAndPassword(String username, String password) {
|
||||
return usersRepository.checkByUsernameAndPassword(username,password);
|
||||
}
|
||||
@Override
|
||||
public User checkByUsernameAndPassword(String username, String password) {
|
||||
return usersRepository.checkByUsernameAndPassword(username, password);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,23 +7,24 @@ package com.yaoyuan.jiscuss.util;
|
||||
* @Description:
|
||||
* @date 2020/8/31 20:52
|
||||
*/
|
||||
|
||||
/**
|
||||
* 去除内容页代码里的HTML标签
|
||||
*
|
||||
*/
|
||||
public class DelTagsUtil {
|
||||
/**
|
||||
* 去除html代码中含有的标签
|
||||
*
|
||||
* @param htmlStr
|
||||
* @return
|
||||
*/
|
||||
public static String delHtmlTags(String htmlStr) {
|
||||
//定义script的正则表达式,去除js可以防止注入
|
||||
String scriptRegex="<script[^>]*?>[\\s\\S]*?<\\/script>";
|
||||
String scriptRegex = "<script[^>]*?>[\\s\\S]*?<\\/script>";
|
||||
//定义style的正则表达式,去除style样式,防止css代码过多时只截取到css样式代码
|
||||
String styleRegex="<style[^>]*?>[\\s\\S]*?<\\/style>";
|
||||
String styleRegex = "<style[^>]*?>[\\s\\S]*?<\\/style>";
|
||||
//定义HTML标签的正则表达式,去除标签,只提取文字内容
|
||||
String htmlRegex="<[^>]+>";
|
||||
String htmlRegex = "<[^>]+>";
|
||||
//定义空格,回车,换行符,制表符
|
||||
String spaceRegex = "\\s*|\t|\r|\n";
|
||||
|
||||
@@ -37,21 +38,23 @@ public class DelTagsUtil {
|
||||
htmlStr = htmlStr.replaceAll(spaceRegex, "");
|
||||
return htmlStr.trim(); // 返回文本字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取HTML代码里的内容
|
||||
*
|
||||
* @param htmlStr
|
||||
* @return
|
||||
*/
|
||||
public static String getTextFromHtml(String htmlStr){
|
||||
public static String getTextFromHtml(String htmlStr) {
|
||||
//去除html标签
|
||||
htmlStr = delHtmlTags(htmlStr);
|
||||
//去除空格" "
|
||||
htmlStr = htmlStr.replaceAll(" ","");
|
||||
htmlStr = htmlStr.replaceAll(" ", "");
|
||||
return htmlStr;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
String htmlStr= "<script type>var i=1; alert(i)</script><style> .font1{font-size:12px}</style><span>少年中国说。</span>红日初升,其道大光。<h3>河出伏流,一泻汪洋。</h3>潜龙腾渊, 鳞爪飞扬。乳 虎啸 谷,百兽震惶。鹰隼试翼,风尘吸张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。纵有千古,横有" +
|
||||
public static void main(String[] args) {
|
||||
String htmlStr = "<script type>var i=1; alert(i)</script><style> .font1{font-size:12px}</style><span>少年中国说。</span>红日初升,其道大光。<h3>河出伏流,一泻汪洋。</h3>潜龙腾渊, 鳞爪飞扬。乳 虎啸 谷,百兽震惶。鹰隼试翼,风尘吸张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。纵有千古,横有" +
|
||||
"八荒。<a href=\"www.baidu.com\">前途似海,来日方长</a>。<h1>美哉我少年中国,与天不老!</h1><p>壮哉我中国少年,与国无疆!</p>";
|
||||
System.out.println(getTextFromHtml(htmlStr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user