This update is mainly the Magician-Web, Magician-JDBC for a small upgrade.

The changes are as follows:

  1. Fixed Magician-Web interceptor, wildcard too rigorous issues
  2. Enhanced Magician-JDBC SQL helper

Interceptor wildcards are too strict

In previous versions, if our interface URL looked like this: [/ API /order/list, / API /order/create, / API /lottery/list]

If you want to intercept all interfaces that start with an API, you can certainly think of this configuration in the interceptor

@Interceptor(pattern = "/api/*")
public class DemoInterceptor implements MagicianInterceptor {}Copy the code

You can either configure [pattren=”/ API /order/”] to block all interfaces starting with [/ API /order/] Either configure [pattren=”/ API/Lottery/”] to intercept all interfaces that start with [/ API/Lottery /], or do so as follows

@Interceptor(pattern = "/api/*/*")
public class DemoInterceptor implements MagicianInterceptor {}Copy the code

But that’s a little bit of a problem, because it’s not flexible enough, and it limits the level of the URL, and it has to be 3, no more, no less. So the new version fixes this minor problem and can now be configured this way

@Interceptor(pattern = "/api/*")
public class DemoInterceptor implements MagicianInterceptor {}Copy the code

Enhanced Magician-JDBC SQL helper

Let me take a query, for example, and we used to have to write where conditions like this

String sql = SqlBuilder
                .select("lottery_order_list")
                .column(OrderPO.class)
                .where("user_id = #{user_id} and pay_status = #{pay_status} and lottery_status = #{lottery_status} order by create_time desc")
                .builder();
Copy the code

There are three problems with writing this way

  1. The arguments to the WHERE method are too long to read
  2. If the condition requires dynamic concatenation you have to define your own StringBuffer
  3. Group by, order by, limit, etc

So in this version, we’ve enhanced this, again, the example above, and we can change it to something like this

String sql = SqlBuilder
                .select("lottery_order_list")
                .column(OrderPO.class)
                // Where can be passed multiple times, SqlBuilder will automatically concatenate
                .where("user_id = #{user_id}")
                .where("and pay_status = #{pay_status}")
                .where("and lottery_status = #{lottery_status}")
                // Order by is separated from WHERE
                .end("order by create_time desc")
                .builder();
Copy the code

Where can be passed multiple times, and SqlBuilder will automatically concatenate these conditions, so that you can write them line by line clearly, and if you need to dynamically assemble SQL, you can do so

Select select = SqlBuilder
                .select("lottery_order_list")
                .column(OrderPO.class);
                
// If conditions are just examples. Java does not have this syntax
if(user_id is not equal tonull){
    select.where("user_id = #{user_id}");
}
if(pay_status is not equal tonull){
    select.where("and pay_status = #{pay_status}");
}
if(lottery_status is not equal tonull){
    select.where("and lottery_status = #{lottery_status}");
}           
select.end("order by create_time desc");

String sql = select.builder();
Copy the code

Here again some small episode, SQL helper to listen to the literal meaning should be able to understand, he is just a write SQL helper, not those SQL code design ideas, more not JPA that set of things. It is just a tool class to help write SQL. And only for the single table to add, delete, change, check.

Magician-JDBC from the beginning is to follow the design direction of writing SQL, all surrounding tools are to more convenient to write SQL, do not understand the deviation oh, ^_^.

The Magician’s website: www.magician-io.com