4.0.0commybatis_demo0.0.1-SNAPSHOTmybatis_demoDemo project for Spring Boot1.8UTF-8UTF-82.3.7.RELEASEorg.springframework.bootspring-boot-starter-weborg.mybatis.spring.bootmybatis-spring-boot-starter2.1.4mysqlmysql-connector-javaruntimeorg.projectlomboklombokorg.springframework.bootspring-boot-starter-testtestorg.junit.vintagejunit-vintage-engineorg.springframework.bootspring-boot-dependencies${spring-boot.version}pomimportorg.apache.maven.pluginsmaven-compiler-plugin3.8.11.81.8UTF-8org.springframework.bootspring-boot-maven-plugin2.3.7.RELEASEcom.mybatis_demo.MybatisDemoApplicationrepackagerepackage
package com.mybatis_demo.mapper;
import com.mybatis_demo.pojo.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* @author lv
* @date 2022年11月6日21点00分
* 在使用Mybatis持久层框架来操作数据库时,我们可以使用@Mapper注解和@MapperScan注解来将Mapper接口类交给Sprinig进行管理(注入bean到spring容器)
* @Mapper映射一个数据层接口类操作数据库,而@MapperScan配置在启动类上映射一个包下的所有数据层接口类操作数据库
*/
//@Mapper
public interface UserMapper {
@Select("select * from users")
public List selectAll();
//@Select("select * from users where id=#{id}")
public User selectOne(Integer id);
@Insert("insert into users(id,username,password,nickname,addtime) values(#{id},#{username},#{password},#{nickname},NOW())")
public int adduser(User user);
@Delete("delete from users where id=#{id}")
public int del(Integer id);
@Update("update users set username=#{username} where id=#{id}")
public int update(User user);
}
5.建立service层,业务处理层
UserService.java
package com.mybatis_demo.service;
import com.mybatis_demo.pojo.User;
import java.util.List;
/**
* @author lv
* @date 2022年11月6日21点00分
* 业务层接口类
*/
public interface UserService {
public List selectAll();
public User selectOne(Integer id);
public boolean adduser(User user);
public boolean del(Integer id);
public boolean update(User user);
}
UserServiceImpl.java
package com.mybatis_demo.service.impl;
import com.mybatis_demo.mapper.UserMapper;
import com.mybatis_demo.pojo.User;
import com.mybatis_demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author lv
* @date 2022年11月6日21点00分
* 业务层接口类实现,使用@Service这个注解
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List selectAll() {
return userMapper.selectAll();
}
@Override
public User selectOne(Integer id) {
return userMapper.selectOne(id);
}
@Override
public boolean adduser(User user) {
int add = userMapper.adduser(user);
if(add>0){
return true;
}
return false;
}
@Override
public boolean del(Integer id) {
int del = userMapper.del(id);
if(del>0){
return true;
}
return false;
}
@Override
public boolean update(User user) {
int update = userMapper.update(user);
if(update>0){
return true;
}
return false;
}
}
6.建立RestController请求控制层
package com.mybatis_demo.controller;
import com.mybatis_demo.pojo.User;
import com.mybatis_demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author lv
* @date 2022年11月6日21点00分
* rest控制层,使用了不同的动词请求方法(@RequestMapping,@GetMapping,@PostMapping,@DeleteMapping,@PutMapping)
* https://blog.csdn.net/weixin_45266846/article/details/120180991
*/
@RestController
@RequestMapping("/user")
public class UserController {
//自动装配
@Autowired
private UserService userService;
@RequestMapping("/hi")
public String hello(){
return "hello!";
}
@GetMapping("/userAll")
public List all(){
return userService.selectAll();
}
@PostMapping("/userAdd")
public String adduser(@RequestBody User user){
String str=null;
boolean flag = userService.adduser(user);
if(flag){
str="添加成功";
}else{
str="添加失败!";
}
return str;
}
@DeleteMapping("/userDel/{id}")
public String del(@PathVariable int id){
String str=null;
boolean del = userService.del(id);
if(del){
str="添加成功";
}else{
str="添加失败!";
}
return str;
}
@PutMapping("/update")
public boolean update(@RequestBody User user){
return userService.update(user);
}
/**
* 根据id查询单个用户,采用的mybatis数据接口层 XML文件实现SQL语句
* @param id
* @return
*/
@GetMapping("/selOneUser/{id}")
public User selOneUser(@PathVariable int id){
return userService.selectOne(id);
}
}
7.在启动引导类添加@MapperScan注解
package com.mybatis_demo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
//扫描你的mapper接口所在的包
@MapperScan("com.mybatis_demo.mapper")
public class MybatisDemoApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisDemoApplication.class, args);
}
}
<script language="javascript">
$(function (){
var i = 4;$(window).bind("scroll", function (event){
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.s
包冲突是开发过程中很常见的问题:
其表现有:
1.明明在eclipse中能够索引到某个类,运行时却报出找不到类。
2.明明在eclipse中能够索引到某个类的方法,运行时却报出找不到方法。
3.类及方法都有,以正确编译成了.class文件,在本机跑的好好的,发到测试或者正式环境就
抛如下异常:
java.lang.NoClassDefFoundError: Could not in
NAME: gpasswd - administer the /etc/group file
SYNOPSIS:
gpasswd group
gpasswd -a user group
gpasswd -d user group
gpasswd -R group
gpasswd -r group
gpasswd [-A user,...] [-M user,...] g
enquiry mysql version in centos linux
yum list installed | grep mysql
yum -y remove mysql-libs.x86_64
enquiry mysql version in yum repositoryyum list | grep mysql oryum -y list mysql*
install mysq
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
select p.spid,c.object_name,b.session_id,b.oracle_username,b.os_user_name from v$process p,v$session a, v$locked_object b,all_objects c where p.addr=a.paddr and a.process=b.process and c.object_id=b.