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>
|
||||
|
||||
|
@ -13,7 +13,7 @@ import tk.mybatis.spring.annotation.MapperScan;
|
||||
*/
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
}
|
@ -98,9 +98,10 @@ 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:
|
||||
|
@ -125,6 +125,7 @@
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -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;
|
||||
|
||||
/**
|
||||
* 程序注解配置
|
||||
|
@ -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
|
||||
* 书签管理对象 sq_bookmark 不存在的字段注解 @Transient
|
||||
*
|
||||
* @author wanghao 不存在的字段注解 @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,6 +81,20 @@ public class SqBookmark extends BaseEntity
|
||||
@Column(name = "Start")
|
||||
private Integer start;
|
||||
|
||||
/** 创建时间 */
|
||||
@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;
|
||||
|
@ -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