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] where user_id=#{userId} username=#{username}, password=#{password}, create_time=#{createTime}, update_time=#{updateTime},
完成



