栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot-mybatis-sqlserver

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot-mybatis-sqlserver

IF EXISTS (SELECt * FROM sys.all_objects WHERe object_id = OBJECT_ID(N'[dbo].[user]') AND type IN ('U'))
	DROp TABLE [dbo].[user]
GO

CREATE TABLE [dbo].[user] (
  [user_id] int  NOT NULL,
  [username] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [password] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [create_time] datetime  NULL,
  [update_time] datetime  NULL
)
GO

ALTER TABLE [dbo].[user] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO [dbo].[user] ([user_id], [username], [password], [create_time], [update_time]) VALUES (N'1', N'6666', N'ldj', NULL, NULL)
GO


-- ----------------------------
-- Primary Key structure for table user
-- ----------------------------
ALTER TABLE [dbo].[user] ADD CONSTRAINT [PK__user__B9BE370F3901C0A2] PRIMARY KEY CLUSTERED ([user_id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
package com.example.demo_sqlserver;


import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

@MapperScan("com.example.demo_sqlserver.dao")
public class DemoSqlserverApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoSqlserverApplication.class, args);
    }

}
package com.example.demo_sqlserver.controller;


import com.example.demo_sqlserver.entity.po.User;
import com.example.demo_sqlserver.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;



@RestController
public class UserController {
    @Resource
    private IUserService userService;


    @PostMapping("updateUserData")
    public void updateUserById(@RequestBody User user) {
        userService.updateUserById(user);
    }

}
package com.example.demo_sqlserver.dao;


import com.example.demo_sqlserver.entity.po.User;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;


@Mapper
public interface UserMapper {
    int updateUserById(User user);
}
package com.example.demo_sqlserver.entity.po;

import lombok.Data;

import java.sql.Timestamp;


@Data
public class User {
    private int userId;
    private String username;
    private String password;
    private Timestamp createTime;
    private Timestamp updateTime;
}
package com.example.demo_sqlserver.service.impl;

import com.example.demo_sqlserver.dao.UserMapper;
import com.example.demo_sqlserver.entity.po.User;
import com.example.demo_sqlserver.service.IUserService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service("userService")
public class UserServiceImpl implements IUserService {
    private static final String ONE = "1";

    @Resource
    private UserMapper userMapper;

    @Override
    public void updateUserById(User user) {
        int ret = userMapper.updateUserById(user);
        System.out.println(ret);
    }

}
package com.example.demo_sqlserver.service;

import com.example.demo_sqlserver.entity.po.User;

public interface IUserService {
    void updateUserById(User user);
}
spring:
  profiles:
    active: dev

spring:
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test;integratedSecurity=false;encrypt=false;trustServerCertificate=false
    username: sa
    password: 123456
    hikari:
      minimum-idle: 5
      maximum-pool-size: 15
      auto-commit: true
      idle-timeout: 30000
      pool-name: DatebookHikariCP
      max-lifetime: 900000
      connection-timeout: 15000
      connection-test-query: SELECT 1


mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.example.demo_sqlserver.entity
  configuration:
    map-underscore-to-camel-case: true



    
        
        
        
        
        
    
    
        select user_id, username, password, create_time, update_time, ROW_NUMBER() OVER (ORDER BY user_id ASC) as rn
        from [user]
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    

    
        update [user]
        
            username=#{username},
            password=#{password},
            create_time=#{createTime},
            update_time=#{updateTime},
        
        where user_id=#{userId}
    


 

 完成

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/930813.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号