diff --git a/SpringBootMybatis/src/main/java/com/zz/App.java b/SpringBootMybatis/src/main/java/com/zz/App.java new file mode 100644 index 0000000..4dfcedb --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/App.java @@ -0,0 +1,22 @@ +package com.zz; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; +/** + * 右键--》run as application 运行正启动类的main方法,就可以启动这个springboot项目。 +SpringBoot 自带了 tomcat, 运行这个main方法 的时候,会同时启动tomcat + * @author jiyu + * + */ +@SpringBootApplication +@MapperScan("com.zz.mapper") +public class App { + + public static void main(String[] args) { + // TODO Auto-generated method stub + SpringApplication.run(App.class, args); + } + +} diff --git a/SpringBootMybatis/src/main/java/com/zz/controller/UserController.java b/SpringBootMybatis/src/main/java/com/zz/controller/UserController.java new file mode 100644 index 0000000..4a01ba6 --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/controller/UserController.java @@ -0,0 +1,52 @@ +package com.zz.controller; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + +import com.zz.util.KeyUtil; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.zz.entity.User; +import com.zz.service.UserService; + +@RestController +@RequestMapping("user") +public class UserController { + @Resource + UserService userService; + @RequestMapping("add/{name}/{pwd}") + public User add(@PathVariable("name") String uname,@PathVariable("pwd") String pwd){ + User user=new User(); + user.setPasswd(pwd); + user.setUsername(uname); + user.setId(KeyUtil.genUniqueKey()); + userService.add(user); + return user; + } + + @RequestMapping("show/{id}") + public User getById(@PathVariable("id") String id){ + return userService.selectByPrimaryKey(id); + } + + + @RequestMapping("showall") + public List getall(){ + return userService.selectAll(); + } + + @RequestMapping("showbyname/{name}") + public User getByName(@PathVariable("name") String name){ + return userService.selectByName(name); + } + + + +} diff --git a/SpringBootMybatis/src/main/java/com/zz/entity/Permission.java b/SpringBootMybatis/src/main/java/com/zz/entity/Permission.java new file mode 100644 index 0000000..58629aa --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/entity/Permission.java @@ -0,0 +1,33 @@ +package com.zz.entity; + +public class Permission { + private String id; + + private String name; + + private String url; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url == null ? null : url.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/entity/Role.java b/SpringBootMybatis/src/main/java/com/zz/entity/Role.java new file mode 100644 index 0000000..966853a --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/entity/Role.java @@ -0,0 +1,33 @@ +package com.zz.entity; + +public class Role { + private String id; + + private String detail; + + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + public String getDetail() { + return detail; + } + + public void setDetail(String detail) { + this.detail = detail == null ? null : detail.trim(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/entity/RolePermissionKey.java b/SpringBootMybatis/src/main/java/com/zz/entity/RolePermissionKey.java new file mode 100644 index 0000000..53ac10f --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/entity/RolePermissionKey.java @@ -0,0 +1,23 @@ +package com.zz.entity; + +public class RolePermissionKey { + private String rId; + + private String pId; + + public String getrId() { + return rId; + } + + public void setrId(String rId) { + this.rId = rId == null ? null : rId.trim(); + } + + public String getpId() { + return pId; + } + + public void setpId(String pId) { + this.pId = pId == null ? null : pId.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/entity/User.java b/SpringBootMybatis/src/main/java/com/zz/entity/User.java new file mode 100644 index 0000000..2be584f --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/entity/User.java @@ -0,0 +1,55 @@ +package com.zz.entity; + +import java.util.Date; + +public class User { + private String id; + + private Date createTime; + + private String passwd; + + private String status; + + private String username; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getPasswd() { + return passwd; + } + + public void setPasswd(String passwd) { + this.passwd = passwd == null ? null : passwd.trim(); + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username == null ? null : username.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/entity/UserRoleKey.java b/SpringBootMybatis/src/main/java/com/zz/entity/UserRoleKey.java new file mode 100644 index 0000000..c6f42d7 --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/entity/UserRoleKey.java @@ -0,0 +1,23 @@ +package com.zz.entity; + +public class UserRoleKey { + private String uId; + + private String rId; + + public String getuId() { + return uId; + } + + public void setuId(String uId) { + this.uId = uId == null ? null : uId.trim(); + } + + public String getrId() { + return rId; + } + + public void setrId(String rId) { + this.rId = rId == null ? null : rId.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/mapper/PermissionMapper.java b/SpringBootMybatis/src/main/java/com/zz/mapper/PermissionMapper.java new file mode 100644 index 0000000..594a46b --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/mapper/PermissionMapper.java @@ -0,0 +1,17 @@ +package com.zz.mapper; + +import com.zz.entity.Permission; + +public interface PermissionMapper { + int deleteByPrimaryKey(String id); + + int insert(Permission record); + + int insertSelective(Permission record); + + Permission selectByPrimaryKey(String id); + + int updateByPrimaryKeySelective(Permission record); + + int updateByPrimaryKey(Permission record); +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/mapper/RoleMapper.java b/SpringBootMybatis/src/main/java/com/zz/mapper/RoleMapper.java new file mode 100644 index 0000000..d3802cd --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/mapper/RoleMapper.java @@ -0,0 +1,17 @@ +package com.zz.mapper; + +import com.zz.entity.Role; + +public interface RoleMapper { + int deleteByPrimaryKey(String id); + + int insert(Role record); + + int insertSelective(Role record); + + Role selectByPrimaryKey(String id); + + int updateByPrimaryKeySelective(Role record); + + int updateByPrimaryKey(Role record); +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/mapper/RolePermissionMapper.java b/SpringBootMybatis/src/main/java/com/zz/mapper/RolePermissionMapper.java new file mode 100644 index 0000000..de2f93f --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/mapper/RolePermissionMapper.java @@ -0,0 +1,11 @@ +package com.zz.mapper; + +import com.zz.entity.RolePermissionKey; + +public interface RolePermissionMapper { + int deleteByPrimaryKey(RolePermissionKey key); + + int insert(RolePermissionKey record); + + int insertSelective(RolePermissionKey record); +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/mapper/UserMapper.java b/SpringBootMybatis/src/main/java/com/zz/mapper/UserMapper.java new file mode 100644 index 0000000..25ceece --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/mapper/UserMapper.java @@ -0,0 +1,43 @@ +package com.zz.mapper; + +import com.zz.entity.User; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface UserMapper { + int deleteByPrimaryKey(String id); + + int insert(User record); + + int insertSelective(User record); + + User selectByPrimaryKey(String id); + + List selectAll(); + + int updateByPrimaryKeySelective(User record); + + int updateByPrimaryKey(User record); + @Select("select * from t_user where username=#{name}") + User selectByName(String name); + + /** + * @Insert("insert into student(sno,sname,ssex) values(#{sno},#{name},#{sex})") + * int add(Student student); + * + * @Update("update student set sname=#{name},ssex=#{sex} where sno=#{sno}") + * int update(Student student); + * + * @Delete("delete from student where sno=#{sno}") + * int deleteBysno(String sno); + * + * @Select("select * from student where sno=#{sno}") + * @Results(id = "student",value= { + * @Result(property = "sno", column = "sno", javaType = String.class), + * @Result(property = "name", column = "sname", javaType = String.class), + * @Result(property = "sex", column = "ssex", javaType = String.class) + * }) + * Student queryStudentBySno(String sno); + */ +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/mapper/UserRoleMapper.java b/SpringBootMybatis/src/main/java/com/zz/mapper/UserRoleMapper.java new file mode 100644 index 0000000..713d44e --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/mapper/UserRoleMapper.java @@ -0,0 +1,11 @@ +package com.zz.mapper; + +import com.zz.entity.UserRoleKey; + +public interface UserRoleMapper { + int deleteByPrimaryKey(UserRoleKey key); + + int insert(UserRoleKey record); + + int insertSelective(UserRoleKey record); +} \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/service/UserService.java b/SpringBootMybatis/src/main/java/com/zz/service/UserService.java new file mode 100644 index 0000000..35858fb --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/service/UserService.java @@ -0,0 +1,31 @@ +package com.zz.service; + +import com.zz.entity.User; +import com.zz.mapper.UserMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class UserService { + @Resource + UserMapper userMapper; + + public int add(User user){ + return userMapper.insert(user); + } + public User selectByPrimaryKey(String id){ + return userMapper.selectByPrimaryKey(id); + }; + + + public List selectAll(){ + return userMapper.selectAll(); + }; + + + public User selectByName(String name){ + return userMapper.selectByName(name); + }; +} diff --git a/SpringBootMybatis/src/main/resources/application.properties b/SpringBootMybatis/src/main/resources/application.properties new file mode 100644 index 0000000..5ac51b2 --- /dev/null +++ b/SpringBootMybatis/src/main/resources/application.properties @@ -0,0 +1,10 @@ +server.port=9018 +server.servlet.context-path=/mybatisdemo +spring.datasource.url = jdbc:mysql://localhost:3306/java10?useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username = root +spring.datasource.password = Java20190713*yy +spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver + +mybatis.typeAliasesPackage=org.spring.springboot.domain +#mybatis.mapperLocations=classpath:com/zz/mapping/*.xml,com/zz/EDGE/mapping/*.xml,com/zz/jwh/mapping/*.xml,com/zz/hc/mapping/*.xml,com/zz/simpleSpade/mapping/*.xml,com/zz/lsw/mapping/*.xml,com/zz/wsq/mapping/*.xml,com/zz/zcj/mapping/*.xml +mybatis.mapperLocations=classpath:mapping/*.xml \ No newline at end of file diff --git a/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml b/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml index 54a2350..77afe29 100644 --- a/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml +++ b/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml @@ -17,6 +17,13 @@ from t_user where id = #{id,jdbcType=VARCHAR} + + delete from t_user where id = #{id,jdbcType=VARCHAR}