创建数据库及数据表
![]()
添加CSMD 相关文件代码:Controller
package com.ruoyi.web.controller.system; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.system.domain.User; import com.ruoyi.system.service.impl.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/system") public class HelloController extends BaseController { @Autowired private UserService userService; @GetMapping("/hello") public List<User> hello() { return userService.findAll(); } }
添加CSMD 相关文件代码:Service
package com.ruoyi.system.service.impl; import com.ruoyi.system.domain.User; import com.ruoyi.system.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserService { @Autowired private UserMapper userMapper; public List<User> findAll() { return userMapper.findAll(); } }
添加CSMD 相关文件代码:Mapper
package com.ruoyi.system.mapper; import com.ruoyi.system.domain.User; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import java.util.List; @Mapper public interface UserMapper { @Select("SELECT * FROM user") List<User> findAll(); }
添加CSMD 相关文件代码:Domain
package com.ruoyi.system.domain; public class User { private Integer id; private String name; private Integer age; private Integer sex; private String createTime; public User() { } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public String getCreateTime() { return createTime; } public void setCreateTime(String createTime) { this.createTime = createTime; } }
屏蔽新加接口安全防护策略
.antMatchers("/login", "/register", "/captchaImage", "/system/hello").anonymous() .antMatchers("/system/user/*").anonymous() .antMatchers("/hello").anonymous()
Postman 测试新接口
![]()