Skip to content

Commit

Permalink
fix yak version
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ll4n committed Jul 18, 2024
1 parent 8bb2d56 commit 28d8bfa
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/essential-for-syntaxflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- name: Download yak binary
run: |
wget -O yak https://aliyun-oss.yaklang.com/yak/1.3.4-beta7/yak_linux_amd64
wget -O yak https://aliyun-oss.yaklang.com/yak/1.3.4-alpha0718/yak_linux_amd64
chmod +x yak
- name: Setup PATH
Expand Down
8 changes: 8 additions & 0 deletions java-database-mapper/java-from-xml-mapper.sf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
desc(
title: "Fetch '${' from ID and check the Source from server/controller",
type: audit
)

${*.xml}.xpath("//mapper/*[contains(., '${') and @id]/@id") as $id;
$id
check $id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.controller;

import com.example.User;
import com.example.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

@Autowired
private UserMapper userMapper;

@PostMapping("/create")
public String createUser(@RequestParam String tableName, @RequestBody User user) {
userMapper.insertUser(tableName, user);
return "User created successfully!";
}

@GetMapping("/get")
public User getUser(@RequestParam String tableName, @RequestParam String columnName, @RequestParam String username) {
return userMapper.selectUserByUsername(tableName, columnName, username);
}

@PutMapping("/update")
public String updateUserEmail(@RequestParam String tableName, @RequestParam String username, @RequestParam String email) {
userMapper.updateUserEmail(tableName, email, username);
return "User email updated successfully!";
}

@DeleteMapping("/delete")
public String deleteUser(@RequestParam String tableName, @RequestParam String username) {
userMapper.deleteUser(tableName, username);
return "User deleted successfully!";
}
}
20 changes: 20 additions & 0 deletions java-database-mapper/sample/com/example/mapper/UserMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.mapper;

import com.example.User;
import org.apache.ibatis.annotations.Param;
import java.util.Map;

public interface UserMapper {
void insertUser(@Param("tableName") String tableName, @Param("user") User user);

User selectUserByUsername(@Param("tableName") String tableName,
@Param("columnName") String columnName,
@Param("value") String value);

void updateUserEmail(@Param("tableName") String tableName,
@Param("email") String email,
@Param("username") String username);

void deleteUser(@Param("tableName") String tableName,
@Param("username") String username);
}
34 changes: 34 additions & 0 deletions java-database-mapper/sample/sqlmap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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">

<mapper namespace="com.example.mapper.UserMapper">

<!-- 选择表名和插入数据的示例 -->
<insert id="insertUser" parameterType="com.example.User">
INSERT INTO ${tableName} (username, email, age)
VALUES (#{username}, #{email}, #{age})
</insert>

<!-- 使用动态表名和动态字段名查询用户信息 -->
<select id="selectUserByUsername" parameterType="map" resultType="com.example.User">
SELECT ${columnName} as username, email, age
FROM ${tableName}
WHERE ${columnName} = #{value}
</select>

<!-- 更新用户信息 -->
<update id="updateUserEmail" parameterType="map">
UPDATE ${tableName}
SET email = #{email}
WHERE username = #{username}
</update>

<!-- 删除用户 -->
<delete id="deleteUser" parameterType="map">
DELETE FROM ${tableName}
WHERE username = #{username}
</delete>

</mapper>

0 comments on commit 28d8bfa

Please sign in to comment.