Commit e19b6c86 authored by liboyang's avatar liboyang

Springboot+Mybatis制证项目首次提交

parent 49aa8454
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!--引入jersey作为http rest接口实现-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId> <groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
......
...@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
public class SystemUserApi { public class SystemUserApi {
......
package com.yx_project.start.entity; package com.yx_project.start.entity;
import javax.persistence.*; import javax.persistence.*;
import java.util.List;
@Entity @Entity
@Table(name = "SYSTEM_ROLE", schema = "DAHAI", catalog = "") @Table(name = "SYSTEM_ROLE", schema = "DAHAI", catalog = "")
public class SystemRoleEntity { public class SystemRoleEntity {
private long roleId; private long roleId;
private String roleName; private String roleName;
private List<SystemMenuEntity> menuEntityList;
public List<SystemMenuEntity> getMenuEntityList() {
return menuEntityList;
}
public void setMenuEntityList(List<SystemMenuEntity> menuEntityList) {
this.menuEntityList = menuEntityList;
}
@Id @Id
@Column(name = "ROLE_ID") @Column(name = "ROLE_ID")
......
package com.yx_project.start.entity; package com.yx_project.start.entity;
import javax.persistence.*; import javax.persistence.*;
import java.util.List;
@Entity @Entity
@Table(name = "SYSTEM_USER", schema = "DAHAI", catalog = "") @Table(name = "SYSTEM_USER", schema = "DAHAI", catalog = "")
...@@ -9,6 +10,15 @@ public class SystemUserEntity { ...@@ -9,6 +10,15 @@ public class SystemUserEntity {
private String username; private String username;
private String password; private String password;
private String workshop; private String workshop;
private List<SystemRoleEntity> roleEntityList;
public List<SystemRoleEntity> getRoleEntityList() {
return roleEntityList;
}
public void setRoleEntityList(List<SystemRoleEntity> roleEntityList) {
this.roleEntityList = roleEntityList;
}
@Id @Id
@Column(name = "ID") @Column(name = "ID")
......
...@@ -3,11 +3,13 @@ package com.yx_project.start.mapper; ...@@ -3,11 +3,13 @@ package com.yx_project.start.mapper;
import com.yx_project.start.entity.SystemUserEntity; import com.yx_project.start.entity.SystemUserEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
public interface SystemUserMapper { public interface SystemUserMapper {
public List<SystemUserEntity> findAll(); public List<SystemUserEntity> findAll();
public SystemUserEntity selectByUsernameAndPassword(Map<String,String> map);
} }
...@@ -3,10 +3,12 @@ package com.yx_project.start.service; ...@@ -3,10 +3,12 @@ package com.yx_project.start.service;
import com.yx_project.start.entity.SystemUserEntity; import com.yx_project.start.entity.SystemUserEntity;
import java.util.List; import java.util.List;
import java.util.Map;
public interface SystemUserService { public interface SystemUserService {
/** /**
* 根据接口查询所用的用户 * 根据接口查询所用的用户
*/ */
public List<SystemUserEntity> findAllUser(); public List<SystemUserEntity> findAllUser();
// public SystemUserEntity findUserRoleMenu(Map<String,String> map);
} }
...@@ -6,6 +6,7 @@ import com.yx_project.start.service.SystemUserService; ...@@ -6,6 +6,7 @@ import com.yx_project.start.service.SystemUserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class SystemUserServiceImpl implements SystemUserService { public class SystemUserServiceImpl implements SystemUserService {
...@@ -19,4 +20,6 @@ public class SystemUserServiceImpl implements SystemUserService { ...@@ -19,4 +20,6 @@ public class SystemUserServiceImpl implements SystemUserService {
return list; return list;
} }
} }
...@@ -10,8 +10,4 @@ spring.datasource.driver-class-name= oracle.jdbc.driver.OracleDriver ...@@ -10,8 +10,4 @@ spring.datasource.driver-class-name= oracle.jdbc.driver.OracleDriver
spring.datasource.url = jdbc:oracle:thin:@192.168.10.208:1521:GTYX spring.datasource.url = jdbc:oracle:thin:@192.168.10.208:1521:GTYX
spring.datasource.username = dahai spring.datasource.username = dahai
spring.datasource.password = dahai spring.datasource.password = dahai
spring.freemarker.cache=true
spring.freemarker.charset=utf-8
spring.freemarker.content-type=text/html
spring.freemarker.check-template-location=true
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yx_project.start.mapper.SystemUserMapper"> <mapper namespace="com.yx_project.start.mapper.SystemUserMapper">
<!--用户-->
<resultMap id="UserRoleMenuMap" type="com.yx_project.start.entity.SystemUserEntity">
<id property="id" column="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="workshop" property="workshop"/>
<!--角色集合-->
<collection property="roleEntityList" ofType="SystemRoleEntity" column="id" select="selectAllRole"/>
</resultMap>
<!--角色-->
<resultMap id="RoleMap" type="com.yx_project.start.entity.SystemRoleEntity" >
<id column="roleId" property="roleId" />
<result column="roleName" property="roleName"/>
<!--权限集合-->
<collection property="menuEntityList" ofType="SystemMenuEntity" column="id" select="selectAllMenu"/>
</resultMap>
<!--权限-->
<resultMap id="MenuMap" type="com.yx_project.start.entity.SystemMenuEntity" >
<id column="menuId" property="menuId" />
<result column="menu" property="menu"/>
<result column="menuName" property="menuName"/>
</resultMap>
<select id="findAll" resultType="SystemUserEntity"> <select id="findAll" resultType="SystemUserEntity">
select * from "SYSTEM_USER" select * from "SYSTEM_USER"
</select> </select>
<!--根据角色id查询权限(先从角色权限关联表查询角色id相等,在查询权限id,根据权限id在权限表里查询权限)-->
<select id="selectAllMenu" resultType="com.yx_project.start.entity.SystemMenuEntity" parameterType="java.lang.Integer">
select menuId,menuName from SYSTEM_MENU where menuId in (select SYSTEM_ROLE_MENU.ROLE_MENU_ID from SYSTEM_ROLE_MENU where SYSTEM_ROLE_MENU.ROLE_ID=#{id})
</select>
<!--查询所有角色-->
<select id="selectAllRole" resultMap="RoleMap" parameterType="java.lang.Integer">
select roleId,roleName from SYSTEM_ROLE where roleId in (select "SYSTEM_USER".ROLE_ID from "SYSTEM_USER" where "SYSTEM_USER".id=#{id})
</select>
<!--通过用户名密码查询用户-->
<select id="selectByUsernameAndPassword" resultMap="UserRoleMenuMap" parameterType="Map">
select * from user where username=#{username} AND password = #{password}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment