1.通用mapper集成 2.单元测试
This commit is contained in:
parent
0f4d4f68ca
commit
d75969cf9a
@ -72,6 +72,23 @@
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-generator</artifactId>
|
||||
</dependency>
|
||||
<!-- 单元测试-->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13</version>
|
||||
<!--<scope>test</scope>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.1.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -8,12 +8,12 @@ import tk.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||
@MapperScan(basePackages = "com.ruoyi.bookmark.mapper")
|
||||
@MapperScan(basePackages = { "com.ruoyi.**.mapper" })
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
@ -40,7 +40,7 @@ public class SqBookmarkController extends BaseController
|
||||
* 测试通用mapper
|
||||
*/
|
||||
@GetMapping("/selectByID")
|
||||
public TableDataInfo selectByID(Long userID) {
|
||||
public TableDataInfo selectByID( Long userID) {
|
||||
List<SqBookmark> list = sqBookmarkService.selectByID(userID);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -51,6 +51,7 @@ public class SqBookmarkController extends BaseController
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectBymenuIdUserID")
|
||||
@PreAuthorize("@ss.hasPermi('bookmark:bookmark:list')")
|
||||
public TableDataInfo selectBymenuIdUserID(Long menuID, Long userID) {
|
||||
startPage();
|
||||
List<SqBookmark> list = sqBookmarkService.selectBymenuIdUserID(menuID,userID);
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
* @Date: 2020/08/08 19:10
|
||||
* 功能描述:
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@WebAppConfiguration
|
||||
public class BaseSpringBootTest {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(BaseSpringBootTest.class);
|
||||
@Before
|
||||
public void init() {
|
||||
logger.info("开始测试...");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
logger.info("测试结束...");
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
|
||||
import com.ruoyi.web.controller.yunbookmark.SqBookmarkController;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
* @Date: 2020/08/08 18:51
|
||||
* 功能描述: SqBookmark 测试类
|
||||
*/
|
||||
public class SqBookmarkTest extends BaseSpringBootTest{
|
||||
|
||||
|
||||
@Autowired
|
||||
private SqBookmarkController sqBookmarkController;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(sqBookmarkController).build();
|
||||
logger.info("setup().........");
|
||||
}
|
||||
@Test
|
||||
public void demo() throws Exception {
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/bookmark/bookmark/2"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andReturn();
|
||||
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
}
|
@ -42,7 +42,7 @@ spring:
|
||||
messages:
|
||||
# 国际化资源文件路径
|
||||
basename: i18n/messages
|
||||
profiles:
|
||||
profiles:
|
||||
active: druid
|
||||
# 文件上传
|
||||
servlet:
|
||||
@ -63,7 +63,7 @@ spring:
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
# 密码
|
||||
password:
|
||||
password:
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
@ -85,7 +85,7 @@ token:
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 300
|
||||
|
||||
|
||||
# MyBatis配置
|
||||
mybatis:
|
||||
# 搜索指定包别名
|
||||
@ -98,16 +98,17 @@ mybatis:
|
||||
#mappers 多个接口时逗号隔开
|
||||
|
||||
mapper:
|
||||
mappers: com.ruoyi.common.mybatisMapper.MyMapper
|
||||
not-empty: false
|
||||
identity: MYSQL
|
||||
mappers:
|
||||
- com.ruoyi.common.mybatisMapper.MyMapper
|
||||
not-empty: true
|
||||
identity: mysql
|
||||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
reasonable: true
|
||||
supportMethodsArguments: true
|
||||
params: count=countSql
|
||||
params: count=countSql
|
||||
|
||||
# Swagger配置
|
||||
swagger:
|
||||
@ -117,7 +118,7 @@ swagger:
|
||||
pathMapping: /dev-api
|
||||
|
||||
# 防止XSS攻击
|
||||
xss:
|
||||
xss:
|
||||
# 过滤开关
|
||||
enabled: true
|
||||
# 排除链接(多个用逗号分隔)
|
||||
|
@ -52,7 +52,7 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- JSON工具类 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@ -125,6 +125,7 @@
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* Entity基类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class BaseEntity implements Serializable
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import java.util.TimeZone;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import tk.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
/**
|
||||
* 程序注解配置
|
||||
|
@ -24,7 +24,7 @@ import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Mybatis支持*匹配扫描包
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
@ -105,4 +105,4 @@ public class MyBatisConfig
|
||||
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
|
||||
return sessionFactory.getObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,28 @@
|
||||
package com.ruoyi.bookmark.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 书签管理对象 sq_bookmark
|
||||
*
|
||||
* @author wanghao 不存在的字段注解 @Transient
|
||||
* 书签管理对象 sq_bookmark 不存在的字段注解 @Transient
|
||||
*
|
||||
* @author wanghao
|
||||
* @date 2020-08-02
|
||||
* @GeneratedValue让通用mapper在执行insert操作之后将自动生成的主键值回写到当前实体对象对应的属性当中
|
||||
*/
|
||||
@Table(name="sq_bookmark")
|
||||
public class SqBookmark extends BaseEntity
|
||||
public class SqBookmark
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(generator = "JDBC")//返回自增长主键
|
||||
@Column(name = "bookmark_id")
|
||||
/** $column.columnComment */
|
||||
private Long bookmarkId;
|
||||
|
||||
@ -80,111 +81,125 @@ public class SqBookmark extends BaseEntity
|
||||
@Column(name = "Start")
|
||||
private Integer start;
|
||||
|
||||
public void setBookmarkId(Long bookmarkId)
|
||||
/** 创建时间 */
|
||||
@Transient
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public void setBookmarkId(Long bookmarkId)
|
||||
{
|
||||
this.bookmarkId = bookmarkId;
|
||||
}
|
||||
|
||||
public Long getBookmarkId()
|
||||
public Long getBookmarkId()
|
||||
{
|
||||
return bookmarkId;
|
||||
}
|
||||
public void setUserid(Long userid)
|
||||
public void setUserid(Long userid)
|
||||
{
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public Long getUserid()
|
||||
public Long getUserid()
|
||||
{
|
||||
return userid;
|
||||
}
|
||||
public void setTitle(String title)
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
public void setUrl(String url)
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
public void setUrls(String urls)
|
||||
public void setUrls(String urls)
|
||||
{
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public String getUrls()
|
||||
public String getUrls()
|
||||
{
|
||||
return urls;
|
||||
}
|
||||
public void setDescription(String description)
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
public void setImage(String image)
|
||||
public void setImage(String image)
|
||||
{
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getImage()
|
||||
public String getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
public void setLabel(String label)
|
||||
public void setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
public String getLabel()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
public void setMenuId(Long menuId)
|
||||
public void setMenuId(Long menuId)
|
||||
{
|
||||
this.menuId = menuId;
|
||||
}
|
||||
|
||||
public Long getMenuId()
|
||||
public Long getMenuId()
|
||||
{
|
||||
return menuId;
|
||||
}
|
||||
public void setZcount(Long zcount)
|
||||
public void setZcount(Long zcount)
|
||||
{
|
||||
this.zcount = zcount;
|
||||
}
|
||||
|
||||
public Long getZcount()
|
||||
public Long getZcount()
|
||||
{
|
||||
return zcount;
|
||||
}
|
||||
public void setIdelete(Integer idelete)
|
||||
public void setIdelete(Integer idelete)
|
||||
{
|
||||
this.idelete = idelete;
|
||||
}
|
||||
|
||||
public Integer getIdelete()
|
||||
public Integer getIdelete()
|
||||
{
|
||||
return idelete;
|
||||
}
|
||||
public void setStart(Integer start)
|
||||
public void setStart(Integer start)
|
||||
{
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public Integer getStart()
|
||||
public Integer getStart()
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package com.ruoyi.bookmark.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.bookmark.domain.SqBookmark;
|
||||
import com.ruoyi.common.mybatisMapper.MyMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 书签管理Mapper接口
|
||||
*
|
||||
* @author wanghao
|
||||
* @date 2020-08-02
|
||||
* @date 2020-08-02F
|
||||
*/
|
||||
public interface SqBookmarkMapper extends MyMapper<SqBookmark>
|
||||
{
|
||||
@ -20,7 +22,7 @@ public interface SqBookmarkMapper extends MyMapper<SqBookmark>
|
||||
* @param userID 用户ID
|
||||
* @return 书签管理
|
||||
*/
|
||||
public List<SqBookmark> selectBymenuIdUserID(@Param("menuID") Long menuID,@Param("userID") Long userID);
|
||||
public List<SqBookmark> selectBymenuIdUserID(@Param("menuID") Long menuID, @Param("userID") Long userID);
|
||||
/**
|
||||
* 查询书签管理
|
||||
*
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.bookmark.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.bookmark.mapper.SqBookmarkMapper;
|
||||
@ -23,7 +24,7 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
|
||||
@Override
|
||||
public List<SqBookmark> selectByID(Long userID) {
|
||||
|
||||
return sqBookmarkMapper.selectByExample(userID);
|
||||
return sqBookmarkMapper.selectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user