{"id":39602,"date":"2025-05-24T08:06:48","date_gmt":"2025-05-24T00:06:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/39602.html"},"modified":"2025-05-24T08:06:48","modified_gmt":"2025-05-24T00:06:48","slug":"%e9%a1%b9%e7%9b%ae%ef%bc%9a%e5%9c%a8%e7%ba%bf%e9%9f%b3%e4%b9%90%e6%92%ad%e6%94%be%e6%9c%8d%e5%8a%a1%e5%99%a8-%e5%9f%ba%e4%ba%8essm%e6%a1%86%e6%9e%b6%e5%92%8cmybatis","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/39602.html","title":{"rendered":"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis"},"content":{"rendered":"<h2>\u4ecb\u7ecd\u9879\u76ee<\/h2>\n<p>\u9879\u76ee\u4e3b\u8981\u662f\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis\u8fdb\u884c\u5b9e\u73b0<\/p>\n<h2 style=\"background-color:transparent\">\u4e3b\u8981\u7684\u529f\u80fd&#xff1a;<\/h2>\n<p>\u767b\u9646\u754c\u9762&#xff0c;\u7528\u6237\u6ce8\u518c&#xff0c;\u97f3\u4e50\u7684\u64ad\u653e\u5217\u8868&#xff0c;\u5220\u9664\u6307\u5b9a\u7684\u6b4c\u66f2&#xff0c;\u6279\u91cf\u5220\u9664\u6307\u5b9a\u7684\u6b4c\u66f2&#xff0c;\u6536\u85cf\u6b4c\u66f2&#xff0c;\u67e5\u8be2\u6b4c\u66f2&#xff0c;\u4ece\u6536\u85cf\u5217\u8868\u4e2d\u5220\u9664\u6536\u85cf\u97f3\u4e50\u3002<\/p>\n<h2>\u529f\u80fd\u5c55\u793a&#xff1a;<\/h2>\n<p>\u767b\u5f55\u754c\u9762<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"959\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000640-68310d90a8f8f.png\" width=\"1895\" \/><\/p>\n<p>\u7528\u6237\u6ce8\u518c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"960\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000641-68310d9199f41.png\" width=\"1916\" \/>\u00a0<\/p>\n<p>\u97f3\u4e50\u5217\u8868<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"967\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000642-68310d92567ad.png\" width=\"1895\" \/><\/p>\n<\/p>\n<p>\u00a0\u559c\u6b22\u5217\u8868<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"950\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000643-68310d937e066.png\" width=\"1895\" \/><\/p>\n<p>\u6dfb\u52a0\u6b4c\u66f2\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"926\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000644-68310d947e7bd.png\" width=\"1898\" \/><\/p>\n<p>\u00a0<\/p>\n<p>\u9996\u5148\u521b\u5efa\u4e00\u4e2aSping Boot\u9879\u76ee<\/p>\n<p>\u518d\u521b\u5efamusicserver\u6570\u636e\u5e93<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"128\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d9531d3e.png\" width=\"271\" \/><\/p>\n<p>\u6570\u636e\u5e93\u4e00\u5171\u6709\u4e09\u4e2a\u8868&#xff1a;\u6536\u85cf\u6b4c\u66f2\u8868&#xff0c;\u6b4c\u66f2\u8868&#xff0c;\u7528\u6237\u8868<\/p>\n<p>lovemusic\u8868<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"158\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d9541917.png\" width=\"314\" \/><\/p>\n<p>music\u8868<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"272\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d9554c5e.png\" width=\"760\" \/><\/p>\n<p>user\u8868<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"141\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d9566a88.png\" width=\"1212\" \/><\/p>\n<\/p>\n<h2>\u5728.yml\u6587\u4ef6\u4e2d\u914d\u7f6e\u6570\u636e\u5e93\u548cxml<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"376\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d9583bda.png\" width=\"541\" \/><\/p>\n<p>spring:<br \/>\n  datasource:<br \/>\n    url: jdbc:mysql:\/\/127.0.0.1:3306\/musicserver?characterEncoding&#061;utf8&amp;serverTimezone&#061;UTC<br \/>\n    username: \u4f60\u81ea\u5df1\u7684\u6570\u636e\u5e93\u7528\u6237\u540d<br \/>\n    password: \u4f60\u81ea\u5df1\u7684\u6570\u636e\u5e93\u5bc6\u7801<br \/>\n    driver-class-name: com.mysql.cj.jdbc.Driver<\/p>\n<p>  servlet:<br \/>\n    multipart:<br \/>\n      max-file-size: 15MB<br \/>\n      max-request-size: 100MB<br \/>\n#\u97f3\u4e50\u4e0a\u4f20\u540e\u7684\u8def\u5f84<br \/>\n  music:<br \/>\n    local:<br \/>\n      path: E:\/music\/<\/p>\n<p>mybatis:<br \/>\n  configuration:<br \/>\n    map-underscore-to-camel-case: true<br \/>\n    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl<br \/>\n  mapper-locations: classpath:mapper\/**.xml<br \/>\nlogging:<br \/>\n  file:<br \/>\n    name: spring-book.log<\/p>\n<h2>\u521b\u5efa\u9879\u76ee\u7684\u7ed3\u6784\u76ee\u5f55\u00a0<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"596\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d95b8d62.png\" width=\"479\" \/><\/p>\n<\/p>\n<h2>\u767b\u5f55\u6a21\u5757\u7684\u8bbe\u8ba1<\/h2>\n<h3>\u521b\u5efauser\u7c7b<\/h3>\n<p>\u5bf9\u5e94\u6570\u636e\u5e93\u7684user\u8868&#xff0c;\u521b\u5efa\u7528\u6237\u7684\u5b9e\u4f53\u7c7b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"29\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d95d2be8.png\" width=\"439\" \/><\/p>\n<p>&#064;Data<br \/>\npublic class User {<br \/>\n    private Integer id;<br \/>\n    private String username;<br \/>\n    private String password;<br \/>\n} <\/p>\n<h3>\u521b\u5efaUserMapper\u63a5\u53e3<\/h3>\n<p>&#064;Mapper<br \/>\npublic interface UserMapper {<br \/>\n    User login(User loginUser);<\/p>\n<p>    User selectByName(String username);<br \/>\n} <\/p>\n<h3>\u00a0\u521b\u5efaUserMapper.xml<\/h3>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034;<br \/>\n        &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt;<br \/>\n&lt;mapper namespace&#061;&#034;com.blame.onlinemusicserver.mapper.UserMapper&#034;&gt;<\/p>\n<p>    &lt;select id&#061;&#034;login&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.User&#034; parameterType&#061;&#034;com.blame.onlinemusicserver.model.User&#034;&gt;<br \/>\n        select * from user where username&#061;#{username} and password&#061;#{password}<br \/>\n    &lt;\/select&gt;<\/p>\n<p>    &lt;select id&#061;&#034;selectByName&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.User&#034;&gt;<br \/>\n        select * from user where username&#061;#{username}<br \/>\n    &lt;\/select&gt;<\/p>\n<p>&lt;\/mapper&gt; <\/p>\n<h3>\u5b9e\u73b0\u767b\u5f55\u7684\u8bf7\u6c42\u548c\u54cd\u5e94<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"419\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d95e0074.png\" width=\"301\" \/><\/p>\n<h3>\u521b\u5efa\u54cd\u5e94\u7c7b\u7684\u5de5\u5177\u7c7b<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000645-68310d95f2d6c.png\" width=\"537\" \/><\/p>\n<p>&#064;Data<br \/>\npublic class ResponseBodyMessage&lt;T&gt; {<br \/>\n    private Integer status;<br \/>\n    private String message;<br \/>\n    private T data;<\/p>\n<p>    public ResponseBodyMessage(Integer status, String message, T data) {<br \/>\n        this.status &#061; status;<br \/>\n        this.message &#061; message;<br \/>\n        this.data &#061; data;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u521b\u5efaUserController<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#064;RequestParam&#xff1a;\u5c06\u8bf7\u6c42\u53c2\u6570\u7ed1\u5b9a\u5230\u4f60\u63a7\u5236\u5668\u7684\u2f45\u6cd5\u53c2\u6570\u4e0a&#xff0c;\u5982\u679c\u4f60\u8fd9\u4e2a\u53c2\u6570\u4e0d\u662f\u5fc5\u987b\u8981\u4f20\u7684&#xff0c;&#064;RequestParam(required &#061; false) &#xff0c;\u9ed8\u8ba4\u662ftrue<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000646-68310d961dba1.png\" width=\"655\" \/><\/p>\n<p>&#064;Slf4j<br \/>\n&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController {<\/p>\n<p>    &#064;Autowired<br \/>\n    private UserService userService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/login&#034;)<br \/>\n    public ResponseBodyMessage&lt;User&gt; login(&#064;RequestParam(&#034;username&#034;) String username,<br \/>\n                                           &#064;RequestParam(&#034;password&#034;) String password,<br \/>\n                                           HttpServletRequest request){<br \/>\n        ResponseBodyMessage&lt;User&gt; result &#061; userService.login(username, password, request);<br \/>\n        return result;<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u6211\u4eec\u5728\u767b\u5f55\u65f6\u4f7f\u7528BCrypt\u52a0\u5bc6\u8bbe\u8ba1<\/h3>\n<p>Bcrypt\u5c31\u662f\u2f00\u6b3e\u52a0\u5bc6\u2f2f\u5177&#xff0c;\u53ef\u4ee5\u2f50\u8f83\u2f45\u4fbf\u5730\u5b9e\u73b0\u6570\u636e\u7684\u52a0\u5bc6\u2f2f\u4f5c\u3002\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u5b83\u5185\u90e8\u2f83\u2f30\u5b9e\u73b0\u4e86\u968f\u673a\u52a0\u76d0\u5904\u7406<\/p>\n<p>\u6dfb\u52a0\u5176\u4f9d\u8d56<\/p>\n<p> &lt;!&#8211; security \u4f9d\u8d56\u5305&#xff08;\u52a0\u5bc6&#xff09;&#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.springframework.security&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;spring-security-web&lt;\/artifactId&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.springframework.security&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;spring-security-config&lt;\/artifactId&gt;<br \/>\n        &lt;\/dependency&gt; <\/p>\n<p>\u5728\u9879\u76ee\u7684\u542f\u52a8\u7c7b\u4e2d\u6dfb\u52a0&#064;SpringBootApplication(exclude &#061; \u00a0 \u00a0 \u00a0 \u00a0 {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})<\/p>\n<p>\/\/\u5728&#064;SpringBootApplication\u6ce8\u89e3\u540e\u6dfb\u52a0(exclude &#061;<br \/>\n\/\/{org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})\u7684\u4f5c\u7528&#xff1a;<br \/>\n\/\/\u6211\u4eec\u867d\u7136\u5f15\u7528\u4e86 security\u7684\u4f9d\u8d56&#xff0c;\u4f46\u662f\u6211\u4eec\u53ea\u662f\u4f7f\u7528\u4e86\u5b83\u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u7c7b&#xff0c;\u4e0d\u9002\u7528\u5176\u4ed6\u7684&#xff0c;\u5982\u679c\u4e0d\u6dfb\u52a0\u8fd9\u4e2a\u7684\u8bdd&#xff0c;SpringSecurity\u2f63\u6548\u4e86\u7684&#xff0c;<br \/>\n\/\/\u6b64\u65f6\u7684\u63a5\u2f1d\u90fd\u662f\u88ab\u4fdd\u62a4\u7684&#xff0c;\u6211\u4eec\u9700\u8981\u901a\u8fc7\u9a8c\u8bc1\u624d\u80fd\u6b63\u5e38\u7684\u8bbf\u95ee&#xff0c;\u5bfc\u81f4\u6211\u4eec\u65e0\u6cd5\u767b\u5f55<br \/>\n&#064;SpringBootApplication(exclude &#061;<br \/>\n        {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})<br \/>\npublic class OnlineMusicServerApplication {<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        SpringApplication.run(OnlineMusicServerApplication.class, args);<br \/>\n    }<\/p>\n<p>}<\/p>\n<h3>\u521b\u5efaAppConfig<\/h3>\n<p>\u5b9a\u4e49config\u5305&#xff0c;\u521b\u5efaAppConfig&#xff0c;\u4f7f\u7528&#064;Configuration\u6ce8\u89e3<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"155\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000646-68310d9640aee.png\" width=\"555\" \/><\/p>\n<p>&#064;Configuration<br \/>\npublic class AppConfig implements WebMvcConfigurer {<\/p>\n<p>    &#064;Bean<br \/>\n    public BCryptPasswordEncoder getbCryptPasswordEncoder(){<br \/>\n        return new BCryptPasswordEncoder();<br \/>\n    }<br \/>\n}<\/p>\n<h3 style=\"background-color:transparent\">\u521b\u5efaUserService\u00a0<\/h3>\n<p>request.getSession(),\u83b7\u53d6\u8fd9\u6b21\u8bf7\u6c42\u7684session\u5bf9\u8c61<\/p>\n<p>.setAttribute()\u5c06\u7528\u6237\u4fe1\u606f\u5b58\u50a8\u5230session\u4e2d<\/p>\n<p>\u56e0\u4e3a\u00a0 USERINFO_SESSION_KEY\u00a0 \u8fd9\u4e2a\u5e38\u91cf\u5bb9\u6613\u62fc\u9519&#xff0c;\u6240\u4ee5\u6211\u4eec\u5c06\u5176\u5b9a\u4e49\u5728\u5e38\u91cf\u4fe1\u606f\u4e2d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"376\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000646-68310d9652422.png\" width=\"612\" \/><\/p>\n<p>&#064;Service<br \/>\npublic class UserService {<br \/>\n    &#064;Autowired<br \/>\n    private UserMapper userMapper;<\/p>\n<p>    &#064;Autowired<br \/>\n    private BCryptPasswordEncoder bCryptPasswordEncoder;<\/p>\n<p>    public ResponseBodyMessage&lt;User&gt; login(String username,<br \/>\n                      String password,<br \/>\n                      HttpServletRequest request) {<br \/>\n        User loginUser&#061;new User();<br \/>\n        loginUser.setUsername(username);<br \/>\n        loginUser.setPassword(password);<br \/>\n        User user&#061;userMapper.selectByName(username);<br \/>\n        if(user&#061;&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;,loginUser);<br \/>\n        }<br \/>\n        if(!bCryptPasswordEncoder.matches(password,user.getPassword())){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u5bc6\u7801\u9519\u8bef&#xff0c;\u8bf7\u91cd\u65b0\u767b\u5f55&#034;,loginUser);<br \/>\n        }else {<br \/>\n            request.getSession().setAttribute(Constant.USERINFO_SESSION_KEY,user);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u767b\u9646\u6210\u529f&#034;,loginUser);<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<\/p>\n<p>public class Constant {<br \/>\n    public static final  String USERINFO_SESSION_KEY&#061;&#034;USERINFO_SESSION_KEY&#034;;<br \/>\n}<\/p>\n<p>\u00a0\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"952\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000646-68310d96a9c0f.png\" width=\"1906\" \/><\/p>\n<p>\u00a0<\/p>\n<h2 style=\"background-color:transparent\">\u65b0\u589e\u529f\u80fd&#xff1a;\u6ce8\u518c\u7528\u6237\u529f\u80fd\u7684\u5b9e\u73b0<\/h2>\n<p>\u4fee\u6539\u6570\u636e\u5e93&#xff0c;\u5728user\u8868\u4e2d\u6dfb\u52a0email<\/p>\n<p>ALTER TABLE user<br \/>\nADD COLUMN email VARCHAR(100) NOT NULL;<\/p>\n<h3>UserMapper<\/h3>\n<p>void insertUser(User user);<br \/>\n &lt;insert id&#061;&#034;insertUser&#034;&gt;<br \/>\n        insert into user (username, password, email) VALUES (#{username}, #{password}, #{email})<br \/>\n    &lt;\/insert&gt; <\/p>\n<h3>UserService<\/h3>\n<h3><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000647-68310d976ba4b.png\" width=\"574\" \/><\/h3>\n<p>public ResponseBodyMessage&lt;Boolean&gt; register(String username,String password,String email){<br \/>\n        User existUser&#061;userMapper.selectByName(username);<br \/>\n        if(existUser!&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u8be5\u7528\u6237\u5b58\u5728&#034;,false);<br \/>\n        }<br \/>\n\/\/        \u5c06\u6ce8\u518c\u7684\u5bc6\u7801\u8fdb\u884c\u52a0\u5bc6<br \/>\n        String encoderPassword&#061;bCryptPasswordEncoder.encode(password);<br \/>\n        User user&#061;new User();<br \/>\n        user.setUsername(username);<br \/>\n        user.setPassword(encoderPassword);<br \/>\n        user.setEmail(email);<br \/>\n        userMapper.insertUser(user);<br \/>\n        return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6ce8\u518c\u6210\u529f&#034;,true);<br \/>\n} <\/p>\n<h3 style=\"background-color:transparent\">UserController<\/h3>\n<p>\u4f7f\u7528&#064;Valid\u6765\u6821\u9a8c\u53c2\u6570<\/p>\n<p>\u4f7f\u7528&#064;Valid\u8bb0\u5f97\u6dfb\u52a0\u5176\u4f9d\u8d56<\/p>\n<p>        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;jakarta.validation&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;jakarta.validation-api&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;3.0.2&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.hibernate.validator&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;hibernate-validator&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;8.0.0.Final&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt; <\/p>\n<p>\u5b9a\u4e49RequestRegister\u6765\u8fdb\u884c\u8bf7\u6c42\u6570\u636e\u7684\u5c01\u88c5<\/p>\n<p>&#064;Data<br \/>\npublic class RequestRegister {<\/p>\n<p>    &#064;Size(min &#061; 3, max &#061; 20, message &#061; &#034;\u7528\u6237\u540d\u957f\u5ea6\u5e94\u57283\u523020\u4e2a\u5b57\u7b26\u4e4b\u95f4&#034;)<br \/>\n    &#064;NotBlank(message &#061; &#034;username\u4e0d\u80fd\u4e3a\u7a7a&#034;)<br \/>\n    private String username;<\/p>\n<p>    &#064;NotBlank(message &#061; &#034;password\u4e0d\u80fd\u4e3a\u7a7a&#034;)<br \/>\n    private String password;<\/p>\n<p>    &#064;Email(message &#061; &#034;\u90ae\u7bb1\u683c\u5f0f\u4e0d\u6b63\u786e&#034;)<br \/>\n    &#064;NotBlank(message &#061; &#034;email\u4e0d\u80fd\u4e3a\u7a7a&#034;)<br \/>\n    private String email;<br \/>\n}<\/p>\n<p>&#064;RequestMapping(&#034;\/register&#034;)<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; register(&#064;Valid &#064;RequestBody RequestRegister requestRegister){<br \/>\n        return userService.register(requestRegister.getUsername(), requestRegister.getPassword(), requestRegister.getEmail());<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0<\/p>\n<h2 style=\"background-color:transparent\">\u4e0a\u4f20\u97f3\u4e50\u6a21\u5757\u7684\u5b9e\u73b0\u00a0<\/h2>\n<h3>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"331\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000647-68310d978ab9e.png\" width=\"306\" \/><\/p>\n<h3>\u5b9a\u4e49music\u5b9e\u4f53\u7c7b<\/h3>\n<p>\u5bf9\u5e94\u6570\u636e\u5e93\u4e2d\u7684music\u8868\u7684\u5b57\u6bb5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"90\" src=\"2025-05-24ikns3b3a0tj.png\" width=\"812\" \/><\/p>\n<p>&#064;Data<br \/>\npublic class Music {<br \/>\n    private Integer id;<br \/>\n    private String title;<br \/>\n    private String singer;<br \/>\n    private String time;<br \/>\n    private String url;<br \/>\n    private Integer userid;<\/p>\n<p>} <\/p>\n<h3>\u5b9a\u4e49MusicController<\/h3>\n<p>\u5c06\u97f3\u4e50\u6587\u4ef6\u4e0a\u4f20\u5230\u8fd9\u4e2a\u8def\u5f84<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"80\" src=\"2025-05-24a3zu2xypbi5.png\" width=\"455\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"140\" src=\"2025-05-244bv0ow0obtz.png\" width=\"513\" \/><\/p>\n<p>Slf4j<br \/>\n&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/music&#034;)<br \/>\npublic class MusicController {<\/p>\n<p>    &#064;Autowired<br \/>\n    private MusicService musicService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/upload&#034;)<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; insertMusic(&#064;RequestParam String singer,<br \/>\n                                                    &#064;RequestParam(&#034;filename&#034;) MultipartFile file,<br \/>\n                                                    HttpServletRequest request,<br \/>\n                                                    HttpServletResponse response){<br \/>\n        return  musicService.insertMusic(singer, file, request, response);<\/p>\n<p>    }<br \/>\n} <\/p>\n<h3>\u5b9a\u4e49MusicService<\/h3>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"137\" src=\"2025-05-24ozig4k3dzft.png\" width=\"653\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"294\" src=\"2025-05-24kbgldmqmlsm.png\" width=\"651\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"305\" src=\"2025-05-24mhyz2g4eaic.png\" width=\"468\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"270\" src=\"2025-05-24djo1d3pcsan.png\" width=\"577\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"337\" src=\"2025-05-24b20hv3zvmxa.png\" width=\"1138\" \/><\/p>\n<p>&#064;Slf4j<br \/>\n&#064;Service<br \/>\npublic class MusicService {<\/p>\n<p>    &#064;Value(&#034;${spring.music.local.path}&#034;)<br \/>\n    private String SAVE_PATH;<\/p>\n<p>    &#064;Autowired<br \/>\n    private MusicMapper mapper;<\/p>\n<p>    &#064;Autowired<br \/>\n    private LoveMusicMapper loveMusicMapper;<\/p>\n<p>    \/\/\u6dfb\u52a0\u97f3\u4e50<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; insertMusic(String singer,<br \/>\n                                                     MultipartFile file,<br \/>\n                                                     HttpServletRequest request,<br \/>\n                                                     HttpServletResponse response){<br \/>\n        \/\/1.\u68c0\u67e5\u767b\u5f55<br \/>\n        HttpSession session&#061;request.getSession(false);<br \/>\n        if(session&#061;&#061;null || session.getAttribute(Constant.USERINFO_SESSION_KEY)&#061;&#061;null){<br \/>\n            log.error(&#034;\u672a\u767b\u5f55&#xff0c;\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6ca1\u6709\u767b\u5f55&#034;,false);<\/p>\n<p>        }<br \/>\n        \/\/2.\u68c0\u67e5\u6570\u6570\u636e\u5e93\u4e2d\u662f\u5426\u6709\u6b64\u97f3\u4e50<\/p>\n<p>        \/\/\u5f97\u5230\u6587\u4ef6\u7684\u540d\u5b57\u548c\u7c7b\u578b<br \/>\n        String fileNameAndType&#061;file.getOriginalFilename();<br \/>\n        System.out.println(&#034;fileNameAndType&#034;&#043;fileNameAndType);<br \/>\n        \/\/\u4ee5 . \u5c06\u540d\u5b57\u548c\u7c7b\u578b\u5206\u5f00&#xff0c;\u5f97\u5230title<br \/>\n        if(fileNameAndType&#061;&#061;null || !fileNameAndType.contains(&#034;.&#034;)){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6587\u4ef6\u4e0d\u5408\u6cd5&#xff0c;\u5fc5\u987b\u5305\u542b\u62d3\u5c55\u540d&#034;,false);<br \/>\n        }<br \/>\n        String title&#061;fileNameAndType.substring(0,fileNameAndType.lastIndexOf(&#034;.&#034;));<\/p>\n<p>        log.info(&#034;Checking if music exists: title &#061; {}, singer &#061; {}&#034;, title, singer);<br \/>\n        \/\/\u5224\u65ad\u6570\u636e\u5e93\u4e2d\u662f\u5426\u6709\u6b64\u6b4c\u66f2<br \/>\n        Integer exist&#061; mapper.selectByTitleAndSinger(title,singer);<br \/>\n        if(exist!&#061;null &amp;&amp; exist&gt;0){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6570\u636e\u5e93\u4e2d\u5df2\u7ecf\u5b58\u5728\u6b64\u97f3\u4e50&#034;,false);<br \/>\n        }<\/p>\n<p>        \/\/3..\u4e0a\u4f20\u97f3\u4e50\u5230\u670d\u52a1\u5668<br \/>\n        String path&#061;SAVE_PATH &#043; fileNameAndType;<br \/>\n        File dest&#061;new File(path);<br \/>\n        System.out.println(&#034;dest&#034;&#043;dest.getPath());<br \/>\n        if(!dest.exists()){<\/p>\n<p>            dest.mkdirs();<br \/>\n        }<br \/>\n        \/\/\u4e0a\u4f20\u6587\u4ef6\u5230\u76ee\u6807<br \/>\n        try {<br \/>\n            file.transferTo(dest);<br \/>\n            log.info(&#034;\u670d\u52a1\u5668\u4e0a\u4f20\u6210\u529f&#034;);<br \/>\n        } catch (IOException e) {<br \/>\n            throw new RuntimeException(e);<br \/>\n        }<\/p>\n<p>        \/\/\u5c06\u6b4c\u66f2\u4e0a\u4f20\u5230\u6570\u636e\u5e93<br \/>\n        SimpleDateFormat sf&#061;new SimpleDateFormat(&#034;yyyy-MM-dd&#034;);<br \/>\n        String time&#061;sf.format(new Date());<\/p>\n<p>        String url&#061;&#034;music\/get?path&#061;&#034;&#043;title;<br \/>\n        User user&#061;(User) session.getAttribute(Constant.USERINFO_SESSION_KEY);<br \/>\n        int userId&#061;user.getId();<\/p>\n<p>        try {<br \/>\n            int ret&#061; mapper.insert(title,singer,time,url,userId);<\/p>\n<p>            if(ret&#061;&#061;1){<br \/>\n                response.sendRedirect(&#034;\/list.html&#034;);<br \/>\n                return new ResponseBodyMessage&lt;&gt;(1,&#034;\u6570\u636e\u5e93\u4e0a\u4f20\u6210\u529f&#034;,true);<br \/>\n            }else {<\/p>\n<p>                return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u6570\u636e\u5e93\u4e0a\u4f20\u5931\u8d25&#034;,false);<br \/>\n            }<br \/>\n        }catch (BindingException e){<br \/>\n            boolean delete&#061; dest.delete();<br \/>\n            if(delete){<br \/>\n                log.info(&#034;\u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25&#xff0c;\u5df2\u6210\u529f\u5220\u9664\u670d\u52a1\u5668\u4e0a\u7684\u97f3\u4e50\u6587\u4ef6&#034;);<br \/>\n            }else{<br \/>\n                log.warn(&#034;\u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25&#xff0c;\u672a\u5220\u9664\u670d\u52a1\u5668\u4e0a\u7684\u97f3\u4e50\u6587\u4ef6&#xff0c;\u53ef\u80fd\u9700\u8981\u624b\u52a8\u5220\u9664:{}&#034;,dest.getAbsolutePath());<br \/>\n            }<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u6570\u636e\u5e93\u4e0a\u4f20\u5931\u8d25,\u5728\u670d\u52a1\u5668\u4e2d\u5220\u9664\u97f3\u4e50&#034;,false);<br \/>\n        } catch (IOException e) {<br \/>\n            throw new RuntimeException(e);<br \/>\n        }<br \/>\n    } <\/p>\n<h3>\u65b0\u589e\u65b9\u6cd5&#xff1a;\u5224\u65ad\u4e0a\u4f20\u7684\u6587\u4ef6\u662f\u5426\u662fMP3\u7684\u5f62\u5f0f<\/h3>\n<p>\u6211\u4eec\u9700\u8981\u5bf9\u4e0a\u4f20\u7684\u6587\u4ef6\u8fdb\u884cMP3\u6587\u4ef6\u7c7b\u578b\u68c0\u6d4b&#xff0c;\u5305\u62ec\u6587\u4ef6\u6269\u5c55\u540d\u548cMIME\u7c7b\u578b\u7684\u4e24\u79cd\u68c0\u67e5<\/p>\n<p>\u6587\u4ef6\u62d3\u5c55\u540d\u662f\u6587\u4ef6\u540d\u79f0\u7684\u4e00\u90e8\u5206&#xff0c;\u5b83\u53ef\u4ee5\u8f7b\u6613\u88ab\u4fee\u6539&#xff0c;\u4ece\u800c\u4f2a\u88c5\u6210\u53e6\u4e00\u79cd\u6587\u4ef6<\/p>\n<p>MIME\u7c7b\u578b\u662f\u4e00\u79cd\u8868\u793a\u6587\u4ef6\u7c7b\u578b\u548c\u683c\u5f0f\u7684\u6807\u51c6&#xff0c;\u6bd4\u62d3\u5c55\u540d\u66f4\u52a0\u53ef\u9760<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"33\" src=\"2025-05-24mfhhcle4kf2.png\" width=\"437\" \/><\/p>\n<p>        \/\/\u6839\u636e\u6587\u4ef6\u7684\u62d3\u5c55\u540d\u6765\u5224\u65ad\u662f\u5426\u4e3a.MP3\u6587\u4ef6<br \/>\n      String extension&#061;fileNameAndType.substring(fileNameAndType.lastIndexOf(&#034;.&#034;)).toLowerCase();<br \/>\n        if(!extension.equals(&#034;.mp3&#034;)){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-0,&#034;\u53ea\u652f\u6301MP3\u6587\u4ef6\u4e0a\u4f20&#034;,false);<br \/>\n        }<br \/>\n        \/\/\u6839\u636eMINE\u5224\u65ad<br \/>\n        try {<br \/>\n            String mimeType&#061;file.getContentType();<br \/>\n            log.info(&#034;\u6587\u4ef6\u7684MINI\u7c7b\u578b:{}&#034;,mimeType);<br \/>\n            if(mimeType&#061;&#061;null || !mimeType.equals(&#034;audio\/mpeg&#034;)){<br \/>\n                return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6587\u4ef6\u683c\u5f0f\u4e0d\u6b63\u786e,\u53ea\u652f\u6301MP3\u97f3\u9891\u4e0a\u4f20&#034;,false);<br \/>\n            }<br \/>\n        }catch (Exception e){<br \/>\n            log.error(&#034;\u6587\u4ef6\u68c0\u9a8c\u5f02\u5e38:{}&#034;,e.getMessage());<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6587\u4ef6\u7c7b\u578b\u68c0\u9a8c\u5f02\u5e38&#034;,false);<\/p>\n<p>        } <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"352\" src=\"2025-05-24xtf5u5wunfs.png\" width=\"431\" \/>\u00a0<\/p>\n<h3>\u4e0a\u4f20\u6570\u636e\u5e93\u7684\u5b9e\u73b0<\/h3>\n<p>&#064;Mapper<br \/>\npublic interface MusicMapper {<\/p>\n<p>    Integer insert(String title,String singer,String time,String url,Integer userid);<br \/>\n}<br \/>\n&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034;<br \/>\n        &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt;<br \/>\n&lt;mapper namespace&#061;&#034;com.blame.onlinemusicserver.mapper.MusicMapper&#034;&gt;<\/p>\n<p>    &lt;insert id&#061;&#034;insert&#034;&gt;<br \/>\n        insert into music (title,singer,time,url,userid) values (#{title},#{singer},#{time},#{url},#{userid})<br \/>\n    &lt;\/insert&gt; <\/p>\n<p>\u6d4b\u8bd5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"407\" src=\"2025-05-24pwlqkls3jq2.png\" width=\"1166\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"246\" src=\"2025-05-24k3xcehtq341.png\" width=\"810\" \/><\/p>\n<\/p>\n<h2>\u64ad\u653e\u2fb3\u4e50\u6a21\u5757\u8bbe\u8ba1\u00a0<\/h2>\n<h3 style=\"background-color:transparent\">\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"254\" src=\"2025-05-244y1g3le21bg.png\" width=\"404\" \/><\/p>\n<h3>\u5728MusicController\u4e2d\u65b0\u589eget\u65b9\u6cd5<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"37\" src=\"2025-05-24alimoelltnk.png\" width=\"231\" \/><\/p>\n<p>\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u6784\u5efaHttp\u54cd\u5e94\u7684\u5bf9\u8c61<\/p>\n<p>\u8fd9\u91cc\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5b57\u8282\u6570\u7ec4&#xff0c;\u901a\u5e38\u7528\u4e8e\u4f20\u8f93\u4e8c\u8fdb\u5236\u7684\u6570\u636e&#xff0c;\u56fe\u7247&#xff0c;\u97f3\u9891<\/p>\n<p>\u6211\u4eec\u5728\u8fd9\u65f6\u4f20\u5165\u7684\u662f\u97f3\u9891<\/p>\n<p>    &#064;GetMapping(&#034;\/get&#034;)<br \/>\n    public ResponseEntity&lt;byte[]&gt; get(&#064;RequestParam String path){<br \/>\n        return musicService.get(path);<br \/>\n    }<\/p>\n<h3 style=\"background-color:transparent\">MsuicService<\/h3>\n<p>ResponseEntity\u5bf9\u8c61\u662fSpring\u5bf9\u8bf7\u6c42\u54cd\u5e94\u7684\u5c01\u88c5\u3002\u5b83\u7ee7\u627f\u4e86HttpEntity\u5bf9\u8c61&#xff0c;\u5305\u542b\u4e86Http\u7684\u54cd\u5e94\u7801 &#xff08;httpstatus&#xff09;\u3001\u54cd\u5e94\u5934&#xff08;header&#xff09;\u3001\u54cd\u5e94\u4f53(body)\u4e09\u4e2a\u90e8\u5206\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"436\" src=\"2025-05-245ag42k2scff.png\" width=\"1116\" \/><\/p>\n<p>\/\/\u64ad\u653e\u97f3\u4e50<br \/>\n    public ResponseEntity&lt;byte[]&gt; get(String path){<br \/>\n        File file&#061;new File(SAVE_PATH&#043;path);<br \/>\n        if(!file.exists()){<br \/>\n            return ResponseEntity.notFound().build();<br \/>\n        }<br \/>\n        try {<br \/>\n            byte[] bytes&#061; Files.readAllBytes(file.toPath());<br \/>\n            HttpHeaders headers&#061;new HttpHeaders();<br \/>\n            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);<br \/>\n            headers.setContentLength(bytes.length);<br \/>\n            return ResponseEntity.ok().headers(headers).body(bytes);<br \/>\n        } catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n            return ResponseEntity.internalServerError().build();<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u00a0\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"376\" src=\"2025-05-24y1nj2q053oy.png\" width=\"616\" \/><\/p>\n<\/p>\n<h2 style=\"background-color:transparent\">\u5220\u9664\u2fb3\u4e50\u6a21\u5757\u8bbe\u8ba1<\/h2>\n<h3>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"262\" src=\"2025-05-24sdyus1ev1lh.png\" width=\"340\" \/><\/p>\n<h3>\u5b9e\u73b0MusicMapper<\/h3>\n<p>   Integer deleteMusicById(Integer musicId);<\/p>\n<p>    Music selectMusicById(Integer musicId);<br \/>\n    &lt;delete id&#061;&#034;deleteMusicById&#034;&gt;<br \/>\n        delete from music where id&#061;#{id}<br \/>\n    &lt;\/delete&gt;<\/p>\n<p>    &lt;select id&#061;&#034;selectMusicById&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.Music&#034;&gt;<br \/>\n        select * from music where id&#061;#{id}<br \/>\n    &lt;\/select&gt; <\/p>\n<h3>\u5b9e\u73b0MusicController<\/h3>\n<p>\u6839\u636eId\u6765\u8fdb\u884c\u5220\u9664<\/p>\n<p>    &#064;RequestMapping(&#034;\/delete&#034;)<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; deleteMusicById(&#064;RequestParam Integer id){<br \/>\n        return musicService.deleteMusicById(id);<br \/>\n    } <\/p>\n<h3>\u5b9e\u73b0MusicService\u00a0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"128\" src=\"2025-05-24yle1d4l5wnm.png\" width=\"1038\" \/><\/p>\n<p>\u5982\u679c\u8981\u5c06\u4e00\u4e2a\u6b4c\u66f2\u5220\u9664&#xff0c;\u9700\u8981\u5224\u65ad\u5b83\u662f\u5426\u5728\u6536\u85cf\u6b4c\u66f2\u4e2d&#xff0c;\u5982\u679c\u5728&#xff0c;\u5219\u9700\u8981\u5c06\u5176\u4ece\u6536\u85cf\u97f3\u4e50\u4e2d\u5220\u9664\u00a0<\/p>\n<p> Boolean deleteLoveMusicByMusicId(Integer musicId);<\/p>\n<p> Boolean selectLoveMusicByMusicId(Integer musicId); <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"199\" src=\"2025-05-24rfa3mp15uw0.png\" width=\"1003\" \/><\/p>\n<p>\u5224\u65ad\u5220\u9664\u662f\u5426\u6210\u529f<\/p>\n<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"218\" src=\"2025-05-24p5ztd2i4i0k.png\" width=\"640\" \/><\/p>\n<p>    \/\/\u5220\u9664\u97f3\u4e50<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; deleteMusicById(Integer id){<br \/>\n        Music music&#061;mapper.selectMusicById(id);<br \/>\n        if(music&#061;&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u8be5\u97f3\u4e50\u4e0d\u5b58\u5728&#xff0c;\u65e0\u6cd5\u5220\u9664&#034;,false);<br \/>\n        }<br \/>\n        \/\/\u6b64\u65f6integer\u8868\u793a\u5220\u9664\u7684\u884c\u6570&#xff0c;\u5982\u679c\u884c\u6570\u53c80\u53d8\u4e3a1\u5219\u8868\u793a\u5df2\u7ecf\u8fdb\u884c\u4e86\u5220\u9664\u7684\u6b65\u9aa4<br \/>\n        Integer integer &#061; mapper.deleteMusicById(id);<br \/>\n        Boolean isLoved &#061; loveMusicMapper.selectLoveMusicByMusicId(id);<br \/>\n        if (isLoved !&#061; null &amp;&amp; isLoved) {<br \/>\n            \/\/ \u5982\u679c\u5728\u6536\u85cf\u4e2d&#xff0c;\u5220\u9664\u6536\u85cf\u8bb0\u5f55<br \/>\n            loveMusicMapper.deleteLoveMusicByMusicId(id);<br \/>\n        } else {<br \/>\n            log.info(&#034;\u6b4c\u66f2\u4e0d\u5728\u6536\u85cf\u97f3\u4e50\u4e2d&#034;);<br \/>\n        }<br \/>\n        if(integer&#061;&#061;1){<br \/>\n            String title&#061;music.getTitle();<br \/>\n            File file&#061;new File(SAVE_PATH&#043;File.separator&#043; title&#043;&#034;.mp3&#034;);<br \/>\n            boolean delete&#061;file.delete();<\/p>\n<p>            if(delete){<br \/>\n                log.info(&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u6210\u529f&#034;);<br \/>\n                return new ResponseBodyMessage&lt;&gt;(1,&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u6210\u529f&#034;,true);<br \/>\n            }else {<br \/>\n                log.error(&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u5931\u8d25&#034;);<br \/>\n                return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u5931\u8d25&#034;,false);<br \/>\n            }<br \/>\n        }<br \/>\n        return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u97f3\u4e50\u5220\u9664\u5931\u8d25&#034;,false);<br \/>\n    } <\/p>\n<p>\u00a0\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"434\" src=\"2025-05-24j4okuzvkbzx.png\" width=\"580\" \/><\/p>\n<h2>\u6279\u91cf\u5220\u9664\u9009\u4e2d\u7684\u2fb3\u4e50<\/h2>\n<h3>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"288\" src=\"2025-05-24ie4kbcogtro.png\" width=\"352\" \/><\/p>\n<p>\u5b9e\u73b0MusicController<\/p>\n<p>\u53ea\u9700\u8981\u5148\u521a\u521a\u5355\u9996\u6b4c\u66f2\u5220\u9664\u7684\u57fa\u7840\u4e0a&#xff0c;\u5728\u5916\u5c42\u5957\u4e00\u5c42for\u5faa\u73af&#xff0c;\u4f9d\u6b21\u8fdb\u884c\u5220\u9664&#xff0c;\u77e5\u9053for\u5faa\u73af\u7ed3\u675f&#xff0c;\u5220\u9664\u5168\u90e8\u7684\u6b4c\u66f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"184\" src=\"2025-05-24djdsp03pdsk.png\" width=\"978\" \/><\/p>\n<p>public ResponseBodyMessage&lt;Boolean&gt; deleteMusicByIdMany(List&lt;Integer&gt; id){<br \/>\n        System.out.println(&#034;\u6240\u6709\u7684Id: &#034; &#043; id);<br \/>\n        int sum&#061;0;<br \/>\n        for (int i &#061; 0; i &lt; id.size(); i&#043;&#043;) {<br \/>\n            int musicId&#061;id.get(i);<br \/>\n            Music music&#061;mapper.selectMusicById(musicId);<br \/>\n            Boolean isLoved &#061; loveMusicMapper.selectLoveMusicByMusicId(musicId);<br \/>\n            if (isLoved !&#061; null &amp;&amp; isLoved) {<br \/>\n                \/\/ \u5982\u679c\u5728\u6536\u85cf\u4e2d&#xff0c;\u5220\u9664\u6536\u85cf\u8bb0\u5f55<br \/>\n                loveMusicMapper.deleteLoveMusicByMusicId(musicId);<br \/>\n            } else {<br \/>\n                log.info(&#034;\u6b4c\u66f2\u4e0d\u5728\u6536\u85cf\u97f3\u4e50\u4e2d&#034;);<br \/>\n            }<br \/>\n            System.out.println(&#034;\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684 ID: &#034; &#043; id);<br \/>\n            if(music&#061;&#061;null){<br \/>\n                log.error(&#034;\u8be5\u6b4c\u66f2\u4e0d\u5b58\u5728&#034;);<br \/>\n                continue;<br \/>\n            }<br \/>\n            \/\/\u6b64\u65f6integer\u8868\u793a\u5220\u9664\u7684\u884c\u6570&#xff0c;\u5982\u679c\u884c\u6570\u53c80\u53d8\u4e3a1\u5219\u8868\u793a\u5df2\u7ecf\u8fdb\u884c\u4e86\u5220\u9664\u7684\u6b65\u9aa4<br \/>\n            Integer integer &#061; mapper.deleteMusicById(musicId);<br \/>\n            if(integer&#061;&#061;1){<br \/>\n                String title&#061;music.getTitle();<br \/>\n                File file&#061;new File(SAVE_PATH&#043;File.separator&#043; title&#043;&#034;.mp3&#034;);<br \/>\n                boolean delete&#061;file.delete();<br \/>\n                if(delete){<br \/>\n                    sum&#043;&#061;integer;<br \/>\n                    log.info(&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u6210\u529f&#034;);<br \/>\n                }else {<br \/>\n                    log.error(&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u5220\u9664\u5931\u8d25&#034;);<br \/>\n                }<br \/>\n            }else {<br \/>\n                log.error(&#034;\u6570\u636e\u5e93\u5220\u9664\u5931\u8d25&#034;);<br \/>\n            }<br \/>\n        }<br \/>\n        if(sum&#061;&#061;id.size()){<br \/>\n            log.info(&#034;\u6279\u91cf\u5220\u9664\u6210\u529f&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(1,&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u6279\u91cf\u5220\u9664\u6210\u529f&#034;,true);<br \/>\n        }else {<br \/>\n            log.info(&#034;\u6279\u91cf\u5220\u9664\u5931\u8d25&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u670d\u52a1\u5668\u4e2d\u97f3\u4e50\u6279\u91cf\u5220\u9664\u5931\u8d25&#034;,false);<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"274\" src=\"2025-05-24cheijnuv2fz.png\" width=\"578\" \/><\/p>\n<p>\u67e5\u8be2\u2fb3\u4e50\u6a21\u5757\u8bbe\u8ba1<\/p>\n<p>\u529f\u80fd&#xff1a;\u652f\u6301\u6a21\u7cca\u67e5\u8be2&#xff0c;\u652f\u6301\u8f93\u5165\u7684\u53c2\u6570\u4e3a\u7a7a<\/p>\n<p>\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a\u65f6&#xff0c;\u67e5\u51fa\u6240\u6709\u7684\u6b4c\u66f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"640\" src=\"2025-05-244iafoswrh15.png\" width=\"541\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"318\" src=\"2025-05-24xrguqwao5k3.png\" width=\"421\" \/><\/p>\n<h3>MusicMapper<\/h3>\n<p>\u4e00\u4e2a\u662f\u6839\u636e\u6b4c\u540d\u8fdb\u884c\u67e5\u8be2&#xff0c;\u53e6\u4e00\u4e2a\u662f\u67e5\u8be2\u5168\u90e8\u7684\u6b4c\u66f2<\/p>\n<p>    List&lt;Music&gt; findMusicByTitle(String name);<\/p>\n<p>    List&lt;Music&gt; findMusic(); <\/p>\n<h3>MusicController\u00a0<\/h3>\n<p>&#064;RequestParam\u4e0d\u4f20\u9012\u53c2\u6570\u65f6\u5019&#xff0c;\u53ef\u4ee5\u4e3a\u7a7a\u00a0<\/p>\n<p>    &#064;RequestMapping(&#034;\/findmusic&#034;)<br \/>\n    public ResponseBodyMessage&lt;List&lt;Music&gt;&gt; findMusic(&#064;RequestParam(required &#061; false) String musicName){<br \/>\n        return  musicService.findMusic(musicName);<br \/>\n    } <\/p>\n<h3>MusicService\u00a0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"469\" src=\"2025-05-243bexelnkcrk.png\" width=\"1172\" \/><\/p>\n<p> public ResponseBodyMessage&lt;List&lt;Music&gt;&gt; findMusic(String musicName){<br \/>\n        List&lt;Music&gt; musics&#061;null;<br \/>\n        \/\/musicName!&#061;null\u662f\u5224\u65ad\u4f20\u5165\u7684\u6b4c\u66f2\u540d\u662f\u5426\u4e3a\u7a7a<br \/>\n        \/\/musicName.trim().isEmpty()\u662f\u53bb\u6389\u524d\u540e\u7684\u7a7a\u683c&#xff0c;\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a&#xff0c;\u52a0\u4e0a\u8fd9\u4e2a\u66f4\u52a0\u7684\u4e25\u8c28<br \/>\n        if(musicName!&#061;null &amp;&amp; !musicName.trim().isEmpty()){<br \/>\n            log.info(&#034;\u5df2\u627e\u5230\u8be5\u6b4c\u66f2&#034;);<br \/>\n            musics&#061;mapper.findMusicByTitle(musicName);<br \/>\n            if(musics.isEmpty()){<br \/>\n                return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u6ca1\u6709\u627e\u5230\u8be5\u6b4c\u66f2&#034;,musics);<br \/>\n            }<br \/>\n            return new ResponseBodyMessage&lt;&gt;(1,&#034;\u6210\u529f\u627e\u5230\u8be5\u6b4c\u66f2&#034;,musics);<br \/>\n        }else {<br \/>\n            log.info(&#034;\u627e\u5230\u5168\u90e8\u7684\u6b4c\u66f2&#034;);<br \/>\n            musics&#061;mapper.findMusic();<br \/>\n            return new ResponseBodyMessage&lt;&gt;(1,&#034;\u6210\u529f\u627e\u5230\u5168\u90e8\u7684\u6b4c\u66f2&#034;,musics);<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u9a8c\u8bc1<\/p>\n<p>\u8f93\u5165\u4e3a\u7a7a&#xff0c;\u67e5\u8be2\u5168\u90e8\u7684\u6b4c\u66f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"387\" src=\"2025-05-24rpcfij4zo15.png\" width=\"634\" \/><\/p>\n<p>\u8f93\u5165\u4e0d\u4e3a\u7a7a&#xff0c;\u67e5\u8be2\u5355\u4e2a\u6b4c\u66f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"444\" src=\"2025-05-24hbpyagfadsi.png\" width=\"619\" \/><\/p>\n<p>\u00a0<\/p>\n<h2>\u6dfb\u52a0\u2fb3\u4e50\u2f84\u559c\u6b22\u7684\u5217\u8868\u6a21\u5757\u8bbe\u8ba1\u00a0<\/h2>\n<h3>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"273\" src=\"2025-05-245pshw5q1eop.png\" width=\"240\" \/><\/p>\n<h3>LoveMusicMapper<\/h3>\n<p>&#064;Mapper<br \/>\npublic interface LoveMusicMapper {<\/p>\n<p>    \/\/\u68c0\u67e5\u8be5\u97f3\u4e50\u662f\u5426\u5df2\u7ecf\u88ab\u6536\u85cf<br \/>\n    Music selectMusicIsExist(Integer userId,Integer musicId);<\/p>\n<p>    \/\/\u5c06\u8be5\u97f3\u4e50\u52a0\u5165\u6536\u85cf\u5939<br \/>\n    Boolean insertLoveMusic(Integer userId,Integer musicId);<br \/>\n}<br \/>\n&lt;select id&#061;&#034;selectMusicIsExist&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.Music&#034;&gt;<br \/>\n        select * from lovemusic where user_id&#061;#{userId} and music_id&#061;#{musicId}<br \/>\n    &lt;\/select&gt;<\/p>\n<p>    &lt;insert id&#061;&#034;insertLoveMusic&#034;&gt;<br \/>\n        insert into lovemusic (user_id,music_id) values (#{userId},#{musicId})<br \/>\n    &lt;\/insert&gt; <\/p>\n<p>\u00a0<\/p>\n<h3>LoveMusicController<\/h3>\n<p>&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/lovemusic&#034;)<br \/>\npublic class LoveMusicController {<\/p>\n<p>    &#064;Autowired<br \/>\n    private LoveMusicService loveMusicService;<\/p>\n<p>    &#064;RequestMapping(&#034;addLikeMusic&#034;)<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; addLikeMusic(&#064;RequestParam String id,HttpServletRequest request){<br \/>\n        return loveMusicService.addLikeMusic(id,request);<br \/>\n    }<br \/>\n} <\/p>\n<h3>LoveMusicService<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"306\" src=\"2025-05-243jvx3ok40ww.png\" width=\"1086\" \/><\/p>\n<p>&#064;Slf4j<br \/>\n&#064;Service<br \/>\npublic class LoveMusicService {<\/p>\n<p>    &#064;Autowired<br \/>\n    private LoveMusicMapper loveMusicMapper;<\/p>\n<p>    \/\/\u6dfb\u52a0\u6536\u85cf<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; addLikeMusic(String id,HttpServletRequest request){<\/p>\n<p>        Integer musicId&#061;Integer.parseInt(id);<br \/>\n        System.out.println(&#034;musicId&#034;&#043;musicId);<\/p>\n<p>        \/\/1.\u68c0\u67e5\u767b\u5f55<br \/>\n        HttpSession session&#061;request.getSession(false);<br \/>\n        if(session&#061;&#061;null || session.getAttribute(Constant.USERINFO_SESSION_KEY)&#061;&#061;null){<br \/>\n            log.error(&#034;\u672a\u767b\u5f55&#xff0c;\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6ca1\u6709\u767b\u5f55&#034;,false);<br \/>\n        }<br \/>\n        User user &#061;(User) session.getAttribute(Constant.USERINFO_SESSION_KEY);<\/p>\n<p>        Integer userId&#061;user.getId();<br \/>\n        System.out.println(&#034;userId&#034;&#043;userId);<\/p>\n<p>        Music music&#061;loveMusicMapper.selectMusicIsExist(userId,musicId);<\/p>\n<p>        if(music!&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u8be5\u97f3\u4e50\u5df2\u7ecf\u52a0\u5165\u4e86\u6536\u85cf\u5939&#034;,false);<br \/>\n        }<br \/>\n        Boolean successAdd&#061;loveMusicMapper.insertLoveMusic(userId,musicId);<br \/>\n        if(successAdd){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(1,&#034;\u97f3\u4e50\u52a0\u5165\u6536\u85cf\u5939\u6210\u529f&#034;,true);<br \/>\n        }<br \/>\n        return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u97f3\u4e50\u52a0\u5165\u6536\u85cf\u5939\u5931\u8d25&#034;,false);<br \/>\n    } <\/p>\n<p>\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"386\" src=\"2025-05-24mwlwygq22vz.png\" width=\"451\" \/><\/p>\n<h2>\u67e5\u8be2\u559c\u6b22\u7684\u2fb3\u4e50\u6a21\u5757\u8bbe\u8ba1<\/h2>\n<p>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"464\" src=\"2025-05-24ibyilxobnzw.png\" width=\"454\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"334\" src=\"2025-05-24pf3hos4svhh.png\" width=\"354\" \/><\/p>\n<h3>LoveMusicMapper<\/h3>\n<p>    \/\/\u6839\u636e\u7528\u6237\u4fe1\u606f\u67e5\u8be2\u6536\u85cf\u7684\u6b4c\u66f2&#xff0c;\u652f\u6301\u6a21\u7cca\u67e5\u8be2<br \/>\n    List&lt;Music&gt; findLoveMusicByUserId(Integer userId);<\/p>\n<p>    \/\/\u6839\u636e\u7528\u6237\u4fe1\u606f\u6765\u67e5\u8be2\u60f3\u8981\u67e5\u8be2\u7684\u6536\u85cf\u7684\u6b4c\u66f2<br \/>\n    List&lt;Music&gt; findLoveMusicByUserIdAndMusicId(Integer userId,String musicName);<br \/>\n &lt;select id&#061;&#034;findLoveMusicByUserId&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.Music&#034;&gt;<br \/>\n        select m.* from lovemusic lm,music m where lm.music_id&#061;m.id and lm.user_id&#061;#{userId}<br \/>\n    &lt;\/select&gt;<\/p>\n<p>    &lt;select id&#061;&#034;findLoveMusicByUserIdAndMusicId&#034; resultType&#061;&#034;com.blame.onlinemusicserver.model.Music&#034;&gt;<br \/>\n        select m.* from lovemusic lm,music m where lm.music_id&#061;m.id and lm.user_id&#061;#{userId} and title like concat(&#039;%&#039;,#{musicName},&#039;%&#039;)<br \/>\n    &lt;\/select&gt; <\/p>\n<h3>LoveMusicController<\/h3>\n<p>&#064;RequestMapping(&#034;\/findlovemusic&#034;)<br \/>\n    public ResponseBodyMessage&lt;List&lt;Music&gt;&gt; findLoveMusic(HttpServletRequest request,&#064;RequestParam(required &#061; false)<br \/>\n                                                          String musicName){<br \/>\n        return loveMusicService.findLoveMusic(request, musicName);<br \/>\n    } <\/p>\n<h3>\u00a0LoveMusicService<\/h3>\n<p>public ResponseBodyMessage&lt;List&lt;Music&gt;&gt; findLoveMusic(HttpServletRequest request,String musicName){<br \/>\n        \/\/\u5224\u65ad\u662f\u5426\u767b\u5f55<br \/>\n        HttpSession session&#061; request.getSession(false);<br \/>\n        if(session&#061;&#061;null || session.getAttribute(Constant.USERINFO_SESSION_KEY)&#061;&#061;null){<br \/>\n            log.error(&#034;\u672a\u767b\u5f55&#xff0c;\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6ca1\u6709\u767b\u5f55&#034;,null);<br \/>\n        }<br \/>\n        User user&#061;(User) session.getAttribute(Constant.USERINFO_SESSION_KEY);<br \/>\n        Integer userId&#061;user.getId();<br \/>\n        System.out.println(&#034;userId&#034;&#043;userId);<br \/>\n        List&lt;Music&gt; musics&#061;null;<br \/>\n        if(userId&#061;&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;,null);<br \/>\n        }<br \/>\n        log.info(&#034;\u5df2\u7ecf\u627e\u5230\u8be5\u7528\u6237&#034;);<br \/>\n        \/\/\u67e5\u8be2\u7528\u6237\u7684\u5168\u90e8\u6536\u85cf\u97f3\u4e50<br \/>\n        if(musicName&#061;&#061;null){<br \/>\n            musics&#061; loveMusicMapper.findLoveMusicByUserId(userId);<br \/>\n            \/\/\u5224\u65ad musics \u4e0d\u4e3a\u7a7a\u4e14\u4e0d\u4e3a null<br \/>\n            if(!CollectionUtils.isEmpty(musics)){<br \/>\n                return new ResponseBodyMessage&lt;&gt;(0,&#034;\u5df2\u7ecf\u627e\u5230\u7528\u6237\u7684\u5168\u90e8\u6536\u85cf\u97f3\u4e50&#034;,musics);<br \/>\n            }else {<br \/>\n                return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u7528\u6237\u7684\u6536\u85cf\u97f3\u4e50\u4e3a\u7a7a&#034;,null);<br \/>\n            }<br \/>\n        }else {   \/\/\u6839\u636e\u7528\u6237\u4fe1\u606f\u6765\u67e5\u8be2\u60f3\u8981\u67e5\u8be2\u7684\u6536\u85cf\u7684\u6b4c\u66f2<br \/>\n            System.out.println(&#034;musicName&#034;&#043;musicName);<br \/>\n            musics&#061;loveMusicMapper.findLoveMusicByUserIdAndMusicId(userId,musicName);<br \/>\n            \/\/\u5224\u65ad musics \u4e0d\u4e3a\u7a7a\u4e14\u4e0d\u4e3a null<br \/>\n            if(!CollectionUtils.isEmpty(musics)){<br \/>\n                return new ResponseBodyMessage&lt;&gt;(0,&#034;\u5df2\u7ecf\u627e\u5230\u7528\u6237\u67e5\u8be2\u7684\u6536\u85cf\u6b4c\u66f2&#034;,musics);<br \/>\n            }else {<br \/>\n                return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u7528\u6237\u6ca1\u6709\u6536\u85cf\u6b64\u97f3\u4e50&#034;,null);<br \/>\n            }<\/p>\n<p>        }<br \/>\n    } <\/p>\n<p>\u9a8c\u8bc1\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"395\" src=\"2025-05-24sfsfh12dmuu.png\" width=\"614\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"448\" src=\"2025-05-24k4akarp01uc.png\" width=\"611\" \/><\/p>\n<h2 style=\"background-color:transparent\">\u79fb\u9664\u559c\u6b22\u7684\u2fb3\u4e50\u6a21\u5757\u8bbe\u8ba1\u00a0<\/h2>\n<h3>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"271\" src=\"2025-05-24i0fo4k2tbot.png\" width=\"307\" \/><\/p>\n<h3>LoveMusicMapper<\/h3>\n<p> Boolean deleteLoveMusic(Integer userId,Integer musicId);<br \/>\n    &lt;delete id&#061;&#034;deleteLoveMusic&#034;&gt;<br \/>\n        delete from lovemusic where user_id&#061;#{userId} and music_id&#061;#{musicId}<br \/>\n    &lt;\/delete&gt; <\/p>\n<h3>LoveMusicController<\/h3>\n<p>    &#064;RequestMapping(&#034;deleteLikeMusic&#034;)<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; deleteLikeMusic(&#064;RequestParam String id,HttpServletRequest request){<br \/>\n        return loveMusicService.deleteLikeMusic(id,request);<br \/>\n    } <\/p>\n<h3 style=\"background-color:transparent\">LoveMusicService<\/h3>\n<p>    \/\/\u53d6\u6d88\u6536\u85cf<br \/>\n    public ResponseBodyMessage&lt;Boolean&gt; deleteLikeMusic(String id,HttpServletRequest request){<br \/>\n        Integer musicId&#061;Integer.parseInt(id);<br \/>\n        System.out.println(&#034;musicId&#034;&#043;musicId);<\/p>\n<p>        \/\/\u68c0\u67e5\u767b\u5f55<br \/>\n        HttpSession session&#061;request.getSession(false);<br \/>\n        if(session&#061;&#061;null || session.getAttribute(Constant.USERINFO_SESSION_KEY)&#061;&#061;null){<br \/>\n            log.error(&#034;\u672a\u767b\u5f55&#xff0c;\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&#034;);<br \/>\n            return new ResponseBodyMessage&lt;&gt;(0,&#034;\u6ca1\u6709\u767b\u5f55&#034;,false);<br \/>\n        }<br \/>\n        User user &#061;(User) session.getAttribute(Constant.USERINFO_SESSION_KEY);<\/p>\n<p>        Integer userId&#061;user.getId();<br \/>\n        System.out.println(&#034;userId&#034;&#043;userId);<br \/>\n        Music music&#061;loveMusicMapper.selectMusicIsExist(userId,musicId);<br \/>\n        if(music&#061;&#061;null){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u8be5\u97f3\u4e50\u4e0d\u5728\u6536\u85cf\u5939\u5185&#034;,false);<br \/>\n        }<br \/>\n        Boolean successDelete&#061;loveMusicMapper.deleteLoveMusic(userId,musicId);<br \/>\n        if(successDelete){<br \/>\n            return new ResponseBodyMessage&lt;&gt;(1,&#034;\u97f3\u4e50\u5df2\u7ecf\u4ece\u6536\u85cf\u5939\u4e2d\u5220\u9664&#034;,true);<br \/>\n        }<br \/>\n        return new ResponseBodyMessage&lt;&gt;(-1,&#034;\u97f3\u4e50\u4ece\u6536\u85cf\u5939\u4e2d\u5220\u9664\u5931\u8d25&#034;,false);<br \/>\n    } <\/p>\n<p>\u9a8c\u8bc1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"370\" src=\"2025-05-2441c25f4pfpv.png\" width=\"460\" \/><\/p>\n<h2>\u5b9e\u73b0\u5ba2\u6237\u7aef\u7684\u4ee3\u7801<\/h2>\n<h3 style=\"background-color:transparent\">\u767b\u5f55\u754c\u9762<\/h3>\n<p>&lt;script&gt;<br \/>\n    $(function () {<br \/>\n      $(&#034;#submit&#034;).click(function () {<br \/>\n        var username &#061; $(&#034;#user&#034;).val().trim();<br \/>\n        var password &#061; $(&#034;#password&#034;).val().trim();<\/p>\n<p>        if (username &#061;&#061;&#061; &#034;&#034; || password &#061;&#061;&#061; &#034;&#034;) {<br \/>\n          $(&#034;#message&#034;).text(&#034;\u8bf7\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801&#xff01;&#034;);<br \/>\n          $(&#034;#messageBox&#034;).fadeIn();<br \/>\n          return;<br \/>\n        }<\/p>\n<p>        $.ajax({<br \/>\n          url: &#034;\/user\/login&#034;,<br \/>\n          type: &#034;post&#034;,<br \/>\n          dataType: &#034;json&#034;,<br \/>\n          data: {<br \/>\n            username: username,<br \/>\n            password: password<br \/>\n          },<br \/>\n          success: function (result) {<br \/>\n            if (result.status &#061;&#061;&#061; 0) {<br \/>\n              alert(&#034;\u767b\u5f55\u6210\u529f&#xff01;&#034;);<br \/>\n              window.location.href &#061; &#034;list.html&#034;;<br \/>\n            } else {<br \/>\n              $(&#034;#message&#034;).text(&#034;\u8d26\u53f7\u6216\u5bc6\u7801\u9519\u8bef&#xff0c;\u8bf7\u91cd\u8bd5&#xff01;&#034;);<br \/>\n              $(&#034;#messageBox&#034;).fadeIn();<br \/>\n              $(&#034;#user&#034;).val(&#034;&#034;);<br \/>\n              $(&#034;#password&#034;).val(&#034;&#034;);<br \/>\n            }<br \/>\n          },<br \/>\n          error: function () {<br \/>\n            $(&#034;#message&#034;).text(&#034;\u670d\u52a1\u5668\u8fde\u63a5\u5931\u8d25&#xff0c;\u8bf7\u7a0d\u540e\u91cd\u8bd5&#xff01;&#034;);<br \/>\n            $(&#034;#messageBox&#034;).fadeIn();<br \/>\n          }<br \/>\n        });<br \/>\n      });<br \/>\n    });<br \/>\n  &lt;\/script&gt; <\/p>\n<h3 style=\"background-color:transparent\">\u6ce8\u518c\u754c\u9762<\/h3>\n<p>&lt;script&gt;<br \/>\n    $(function () {<br \/>\n        $(&#034;#registerBtn&#034;).click(function () {<br \/>\n            var username &#061; $(&#034;#regUser&#034;).val().trim();<br \/>\n            var email &#061; $(&#034;#regEmail&#034;).val().trim();<br \/>\n            var password &#061; $(&#034;#regPassword&#034;).val().trim();<\/p>\n<p>            if (username &#061;&#061;&#061; &#034;&#034; || email &#061;&#061;&#061; &#034;&#034; || password &#061;&#061;&#061; &#034;&#034;) {<br \/>\n                $(&#034;#regMessage&#034;).text(&#034;\u8bf7\u5b8c\u5584\u6ce8\u518c\u4fe1\u606f&#xff01;&#034;);<br \/>\n                $(&#034;#regMessageBox&#034;).fadeIn();<br \/>\n                return;<br \/>\n            }<\/p>\n<p>            $.ajax({<br \/>\n                url: &#034;\/user\/register&#034;,<br \/>\n                type: &#034;post&#034;,<br \/>\n                dataType: &#034;json&#034;,<br \/>\n                contentType: &#034;application\/json&#034;,<br \/>\n                data: JSON.stringify({<br \/>\n                    username: username,<br \/>\n                    password: password,<br \/>\n                    email: email<br \/>\n                }),<br \/>\n                success: function (result) {<br \/>\n                    if (result.status &#061;&#061;&#061; 0) {<br \/>\n                        alert(&#034;\u6ce8\u518c\u6210\u529f&#xff01;&#034;);<br \/>\n                        window.location.href &#061; &#034;login.html&#034;;<br \/>\n                    } else {<br \/>\n                        $(&#034;#regMessage&#034;).text(result.message);<br \/>\n                        $(&#034;#regMessageBox&#034;).fadeIn();<br \/>\n                    }<br \/>\n                },<br \/>\n                error: function () {<br \/>\n                    $(&#034;#regMessage&#034;).text(&#034;\u670d\u52a1\u5668\u8fde\u63a5\u5931\u8d25&#xff0c;\u8bf7\u7a0d\u540e\u91cd\u8bd5&#xff01;&#034;);<br \/>\n                    $(&#034;#regMessageBox&#034;).fadeIn();<br \/>\n                }<br \/>\n            });<br \/>\n        });<br \/>\n    });<br \/>\n&lt;\/script&gt; <\/p>\n<h3>\u97f3\u4e50\u5217\u8868\u754c\u9762<\/h3>\n<p> &lt;script type&#061;&#034;text\/javascript&#034;&gt;<br \/>\n        $(function() {<br \/>\n            load(); \/\/ \u9875\u9762\u52a0\u8f7d\u65f6\u9ed8\u8ba4\u52a0\u8f7d\u6240\u6709\u6b4c\u66f2<br \/>\n        });<\/p>\n<p>        function load(musicName) {<br \/>\n            $.ajax({<br \/>\n                url: &#034;\/music\/findmusic&#034;,<br \/>\n                data: { musicName: musicName },<br \/>\n                type: &#034;get&#034;,<br \/>\n                dataType: &#034;json&#034;,<br \/>\n                success: function(result) {<br \/>\n                    var data &#061; result.data;<br \/>\n                    var s &#061; &#039;&#039;;<br \/>\n                    for (var i &#061; 0; i &lt; data.length; i&#043;&#043;) {<br \/>\n                        var musicUrl &#061; data[i].url &#043; &#034;.mp3&#034;;<br \/>\n                        s &#043;&#061; &#039;&lt;tr&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;th&gt; &lt;input id&#061;&#034;&#039; &#043; data[i].id &#043; &#039;&#034; type&#061;&#034;checkbox&#034;&gt; &lt;\/th&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;td&gt;&#039; &#043; data[i].title &#043; &#039;&lt;\/td&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;td&gt;&#039; &#043; data[i].singer &#043; &#039;&lt;\/td&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;td&gt;&lt;button class&#061;&#034;btn&#034; onclick&#061;&#034;playerSong(\\\\&#039;&#039; &#043; musicUrl &#043; &#039;\\\\&#039;)&#034;&gt;\u64ad\u653e\u6b4c\u66f2&lt;\/button&gt;&lt;\/td&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;td&gt;&lt;button class&#061;&#034;btn&#034; onclick&#061;&#034;deleteInfo(&#039; &#043; data[i].id &#043; &#039;)&#034;&gt;\u5220\u9664&lt;\/button&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;button class&#061;&#034;btn&#034; onclick&#061;&#034;loveInfo(&#039; &#043; data[i].id &#043; &#039;)&#034;&gt;\u559c\u6b22&lt;\/button&gt;&lt;\/td&gt;&#039;;<br \/>\n                        s &#043;&#061; &#039;&lt;\/tr&gt;&#039;;<br \/>\n                    }<br \/>\n                    $(&#034;#info&#034;).html(s);  \/\/ \u66f4\u65b0\u8868\u683c<br \/>\n                }<br \/>\n            });<br \/>\n        }<\/p>\n<p>        function playerSong(musicUrl) {<br \/>\n            var name &#061; musicUrl.substring(musicUrl.lastIndexOf(&#039;\/&#039;) &#043; 1);  \/\/ \u83b7\u53d6\u97f3\u4e50\u540d\u79f0<br \/>\n            SewisePlayer.toPlay(musicUrl, name, 0, true);  \/\/ \u64ad\u653e\u6b4c\u66f2<br \/>\n        }<\/p>\n<p>        function deleteInfo(musicId) {<br \/>\n            $.ajax({<br \/>\n                url: &#034;\/music\/delete&#034;,<br \/>\n                data: { id: musicId },<br \/>\n                type: &#034;post&#034;,<br \/>\n                dataType: &#034;json&#034;,<br \/>\n                success: function(result) {<br \/>\n                    if (result.data) {<br \/>\n                        alert(&#034;\u5220\u9664\u6210\u529f&#034;);<br \/>\n                        window.location.href &#061; &#034;list.html&#034;;  \/\/ \u9875\u9762\u8df3\u8f6c<br \/>\n                    } else {<br \/>\n                        alert(&#034;\u5220\u9664\u5931\u8d25&#034;);<br \/>\n                    }<br \/>\n                }<br \/>\n            });<br \/>\n        }<br \/>\n        $(function(){<br \/>\n            $(&#034;#submit1&#034;).click( function(){<br \/>\n                var name &#061; $(&#034;#exampleInputName2&#034;).val();<br \/>\n                load(name);<br \/>\n            });<\/p>\n<p>            $.when(load).done(function(){<br \/>\n                $(&#034;#delete&#034;).click(function(){<br \/>\n                    var id &#061; new Array();<br \/>\n                    var i &#061; 0;\/\/\u6570\u7ec4\u7684\u5c0f\u6807<br \/>\n                    \/\/<br \/>\n                    $(&#034;input:checkbox&#034;).each(function(){<br \/>\n                        \/\/\u5982\u679c\u88ab\u9009\u4e2d,this\u4ee3\u8868\u53d1\u751f\u4e8b\u4ef6\u7684dom\u5143\u7d20&#xff0c;&lt;input&gt;<br \/>\n                        if( $(this).is(&#034;:checked&#034;)) {<br \/>\n                            id[i] &#061; $(this).attr(&#034;id&#034;);<br \/>\n                            i&#043;&#043;;<br \/>\n                        }<br \/>\n                    });<\/p>\n<p>                    console.log(id);<\/p>\n<p>                    $.ajax({<br \/>\n                        url:&#034;\/music\/deleteSel&#034;,<br \/>\n                        data:{&#034;id&#034;:id},<br \/>\n                        dataType:&#034;json&#034;,<br \/>\n                        type:&#034;post&#034;,<\/p>\n<p>                        success:function(obj){<br \/>\n                            if(obj.data &#061;&#061; true) {<br \/>\n                                alert(&#034;\u5220\u9664\u6210\u529f&#xff01;&#034;);<br \/>\n                                window.location.href &#061; &#034;list.html&#034;;<br \/>\n                            }else{<br \/>\n                                alert(&#034;\u5220\u9664\u5931\u8d25&#xff01;&#034;);<br \/>\n                            }<br \/>\n                        }<br \/>\n                    });<br \/>\n                });<br \/>\n            });<br \/>\n        });<br \/>\n        function loveInfo(musicId) {<br \/>\n            $.ajax({<br \/>\n                url: &#034;lovemusic\/addLikeMusic&#034;,<br \/>\n                data: { &#034;id&#034;: musicId },<br \/>\n                type: &#034;post&#034;,<br \/>\n                dataType: &#034;json&#034;,<br \/>\n                success: function(result) {<br \/>\n                    if (result.data) {<br \/>\n                        alert(&#034;\u6dfb\u52a0\u6536\u85cf\u6210\u529f&#034;);<br \/>\n                        window.location.href &#061; &#034;list.html&#034;;  \/\/ \u9875\u9762\u8df3\u8f6c<br \/>\n                    } else {<br \/>\n                        alert(&#034;\u6dfb\u52a0\u6536\u85cf\u5931\u8d25&#034;);<br \/>\n                    }<br \/>\n                }<br \/>\n            });<br \/>\n        }<br \/>\n    &lt;\/script&gt; <\/p>\n<h3>\u6536\u85cf\u97f3\u4e50\u754c\u9762<\/h3>\n<p>&lt;script&gt;<br \/>\n    $(function() {<br \/>\n      load();<\/p>\n<p>      $(&#034;#submit1&#034;).click(function() {<br \/>\n        var name &#061; $(&#034;#exampleInputName2&#034;).val();<br \/>\n        load(name);<br \/>\n      });<br \/>\n    });<\/p>\n<p>    function load(musicName) {<br \/>\n      $.ajax({<br \/>\n        url: &#034;\/lovemusic\/findlovemusic&#034;,<br \/>\n        data: {&#034;musicName&#034;: musicName},<br \/>\n        type: &#034;GET&#034;,<br \/>\n        dataType: &#034;json&#034;,<br \/>\n        success: function(obj) {<br \/>\n          var data &#061; obj.data;<br \/>\n          var s &#061; &#039;&#039;;<br \/>\n          for (var i &#061; 0; i &lt; data.length; i&#043;&#043;) {<br \/>\n            var musicUrl &#061; data[i].url &#043; &#034;.mp3&#034;;<br \/>\n            s &#043;&#061; &#039;&lt;tr&gt;&#039;;<br \/>\n            s &#043;&#061; &#039;&lt;td&gt;&#039; &#043; data[i].title &#043; &#039;&lt;\/td&gt;&#039;;<br \/>\n            s &#043;&#061; &#039;&lt;td&gt;&#039; &#043; data[i].singer &#043; &#039;&lt;\/td&gt;&#039;;<br \/>\n            s &#043;&#061; &#039;&lt;td&gt;&lt;audio src&#061;&#034;&#039; &#043; musicUrl &#043; &#039;&#034; controls preload&#061;&#034;none&#034; loop&gt;&lt;\/audio&gt;&lt;\/td&gt;&#039;;<br \/>\n            s &#043;&#061; &#039;&lt;td&gt;&lt;button class&#061;&#034;btn btn-primary&#034; onclick&#061;&#034;deleteInfo(&#039; &#043; data[i].id &#043; &#039;)&#034;&gt;\u79fb\u9664&lt;\/button&gt;&lt;\/td&gt;&#039;;<br \/>\n            s &#043;&#061; &#039;&lt;\/tr&gt;&#039;;<br \/>\n          }<br \/>\n          $(&#034;#info&#034;).html(s);<br \/>\n        }<br \/>\n      });<br \/>\n    }<\/p>\n<p>    function deleteInfo(id) {<br \/>\n      $.ajax({<br \/>\n        url: &#034;\/lovemusic\/deleteLikeMusic&#034;,<br \/>\n        type: &#034;POST&#034;,<br \/>\n        data: {&#034;id&#034;: id},<br \/>\n        dataType: &#034;json&#034;,<br \/>\n        success: function(val) {<br \/>\n          if (val.data &#061;&#061; true) {<br \/>\n            alert(&#034;\u5220\u9664\u6210\u529f&#xff01;,\u91cd\u65b0\u52a0\u8f7d\u5f53\u524d\u9875\u9762&#xff01;&#034;);<br \/>\n            window.location.href &#061; &#034;list.html&#034;;<br \/>\n          } else {<br \/>\n            alert(&#034;\u5220\u9664\u5931\u8d25&#xff01;&#034;);<br \/>\n          }<br \/>\n        }<br \/>\n      });<br \/>\n    }<br \/>\n  &lt;\/script&gt; <\/p>\n<h3>\u4e0a\u4f20\u97f3\u4e50\u754c\u9762<\/h3>\n<p>  &lt;form method&#061;&#034;POST&#034; enctype&#061;&#034;multipart\/form-data&#034; action&#061;&#034;\/music\/upload&#034;&gt;<br \/>\n      &lt;div class&#061;&#034;form-group&#034;&gt;<br \/>\n        &lt;label for&#061;&#034;file&#034;&gt;&#x1f3b6; \u97f3\u4e50\u6587\u4ef6&lt;\/label&gt;<br \/>\n        &lt;input type&#061;&#034;file&#034; id&#061;&#034;file&#034; name&#061;&#034;filename&#034; required \/&gt;<br \/>\n      &lt;\/div&gt;<br \/>\n      &lt;div class&#061;&#034;form-group&#034;&gt;<br \/>\n        &lt;label for&#061;&#034;singer&#034;&gt;&#x1f464; \u6b4c\u624b\u540d&lt;\/label&gt;<br \/>\n        &lt;input type&#061;&#034;text&#034; id&#061;&#034;singer&#034; name&#061;&#034;singer&#034; placeholder&#061;&#034;\u8bf7\u8f93\u5165\u6b4c\u624b\u540d&#034; required \/&gt;<br \/>\n      &lt;\/div&gt;<br \/>\n      &lt;input type&#061;&#034;submit&#034; value&#061;&#034;&#x1f4e4; \u4e0a\u4f20&#034; \/&gt;<br \/>\n    &lt;\/form&gt; <\/p>\n<p><span style=\"color:#fe2c24\">\u00a0\u5728\u8fd9\u91cc\u7684\u64ad\u653e\u97f3\u4e50\u7684\u5de5\u5177&#xff0c;\u6211\u4eec\u4f7f\u7528\u7684\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u64ad\u653e\u5de5\u5177<\/span><\/p>\n<p>demos\/\u4f8b\u5b50\u8bf4\u660e.md \u00b7 Jack Zhang\/sewise-player &#8211; Gitee.com<\/p>\n<p> &lt;div style&#061;&#034;width: 180px; height: 140px; position: absolute; bottom: 10px; right: 10px;&#034;&gt;<br \/>\n        &lt;script type&#061;&#034;text\/javascript&#034; src&#061;&#034;player\/sewise.player.min.js&#034;&gt;&lt;\/script&gt;<br \/>\n        &lt;script type&#061;&#034;text\/javascript&#034;&gt;<br \/>\n            SewisePlayer.setup({<br \/>\n                server: &#034;vod&#034;,<br \/>\n                type: &#034;mp3&#034;,<br \/>\n                videourl: &#034;http:\/\/jackzhang1204.github.io\/materials\/where_did_time_go.mp3&#034;,<br \/>\n                skin: &#034;vodWhite&#034;,<br \/>\n                autostart: &#034;false&#034;,<br \/>\n            });<br \/>\n        &lt;\/script&gt;<br \/>\n    &lt;\/div&gt; <\/p>\n<h3>\u5b9e\u73b0\u64ad\u653e<\/h3>\n<p>        function playerSong(musicUrl) {<br \/>\n            var name &#061; musicUrl.substring(musicUrl.lastIndexOf(&#039;\/&#039;) &#043; 1);  \/\/ \u83b7\u53d6\u97f3\u4e50\u540d\u79f0<br \/>\n            SewisePlayer.toPlay(musicUrl, name, 0, true);  \/\/ \u64ad\u653e\u6b4c\u66f2<br \/>\n        } <\/p>\n<h2 style=\"background-color:transparent\">\u00a0\u914d\u7f6e\u62e6\u622a\u5668<\/h2>\n<h3>\u81ea\u5b9a\u4e49\u62e6\u622a\u5668<\/h3>\n<p>&#064;Component<br \/>\npublic class LoginInterceptor implements HandlerInterceptor {<br \/>\n    &#064;Override<br \/>\n    public boolean preHandle(HttpServletRequest request,<br \/>\n                             HttpServletResponse response,<br \/>\n                             Object handler) throws Exception {<br \/>\n        HttpSession session &#061; request.getSession(false);<br \/>\n        if (session !&#061; null &amp;&amp; session.getAttribute(Constant.USERINFO_SESSION_KEY) !&#061; null) {<br \/>\n            return true;<br \/>\n        }<br \/>\n        \/\/ \u672a\u767b\u5f55\u63d0\u793a<br \/>\n        \/\/\u662f\u544a\u8bc9\u6d4f\u89c8\u5668\u5185\u5bb9\u662f JSON&#xff0c;\u5e76\u4e14\u662f UTF-8 \u7f16\u7801&#xff1b;<br \/>\n        response.setContentType(&#034;application\/json;charset&#061;utf-8&#034;);<br \/>\n        \/\/\u624b\u52a8\u8fd4\u56de\u4e00\u6bb5json\u6570\u636e&#xff0c;\u8fdb\u884c\u9519\u8bef\u63d0\u793a<br \/>\n        response.getWriter().write(&#034;{\\\\&#034;code\\\\&#034;:401,\\\\&#034;msg\\\\&#034;:\\\\&#034;\u672a\u767b\u5f55&#xff0c;\u8bf7\u5148\u767b\u5f55\\\\&#034;}&#034;);<br \/>\n        return false;<br \/>\n    }<br \/>\n}<\/p>\n<h3 style=\"background-color:transparent\">\u4f7f\u7528\u62e6\u622a\u5668<\/h3>\n<p>\u53ea\u91ca\u653e\u9759\u6001\u8d44\u6e90\u548c\u767b\u5f55\u63a5\u53e3<\/p>\n<p>&#064;Configuration<br \/>\npublic class AppConfig implements WebMvcConfigurer {<\/p>\n<p>    &#064;Override<br \/>\n    public void addInterceptors(InterceptorRegistry registry) {<br \/>\n        LoginInterceptor loginInterceptor &#061; new LoginInterceptor();<br \/>\n        registry.addInterceptor(loginInterceptor)<br \/>\n                .addPathPatterns(&#034;\/**&#034;) \/\/ \u62e6\u622a\u6240\u6709\u8bf7\u6c42<br \/>\n                .excludePathPatterns(<br \/>\n                        &#034;\/js\/**&#034;,<br \/>\n                        &#034;\/css\/**&#034;,<br \/>\n                        &#034;\/images\/**&#034;,<br \/>\n                        &#034;\/fonts\/**&#034;,<br \/>\n                        &#034;\/player\/**&#034;,<br \/>\n                        &#034;\/login.html&#034;,<br \/>\n                        &#034;\/user\/login&#034;<br \/>\n                ); \/\/ \u653e\u884c\u9759\u6001\u8d44\u6e90\u548c\u767b\u5f55\u63a5\u53e3<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0\u9879\u76ee\u5728\u6b64\u5168\u90e8\u7ed3\u675f&#xff0c;\u53ef\u4ee5\u5c06\u9879\u76ee\u90e8\u7f72\u5230\u4e91\u670d\u52a1\u5668\u4e0a<\/p>\n<\/p>\n<p style=\"text-align:center\">\u5e0c\u671b\u80fd\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9&#xff01;&#xff01;&#xff01;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"248\" src=\"2025-05-240q032k05v2e.jpg\" width=\"219\" \/><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb766\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u5bf9\u5e94\u6570\u636e\u5e93\u4e2d\u7684music\u8868\u7684\u5b57\u6bb5@Data\u5c06\u97f3\u4e50\u6587\u4ef6\u4e0a\u4f20\u5230\u8fd9\u4e2a\u8def\u5f84Slf4j@Autowired@Slf4j@Service@Autowired@Autowired\/\/\u6dfb\u52a0\u97f3\u4e50\/\/1.\u68c0\u67e5\u767b\u5f55log.error(&quot;\u672a\u767b\u5f55\uff0c\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&quot;);return new ResponseBodyMessage&lt;&gt;(0,&quot;\u6ca1\u6709\u767b\u5f55&quot;,false);\/\/2.\u68c0\u67e5\u6570\u6570\u636e\u5e93\u4e2d\u662f\u5426\u6709\u6b64\u97f3\u4e50\/\/\u5f97\u5230\u6587\u4ef6\u7684\u540d\u5b57\u548c\u7c7b\u578b\/\/\u4ee5 . \u5c06\u540d\u5b57\u548c\u7c7b\u578b\u5206\u5f00\uff0c\u5f97\u5230title\u3002<\/p>\n","protected":false},"author":2,"featured_media":39582,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1769,190],"topic":[],"class_list":["post-39602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-mybatis","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/39602.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb766\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u5bf9\u5e94\u6570\u636e\u5e93\u4e2d\u7684music\u8868\u7684\u5b57\u6bb5@Data\u5c06\u97f3\u4e50\u6587\u4ef6\u4e0a\u4f20\u5230\u8fd9\u4e2a\u8def\u5f84Slf4j@Autowired@Slf4j@Service@Autowired@Autowired\/\/\u6dfb\u52a0\u97f3\u4e50\/\/1.\u68c0\u67e5\u767b\u5f55log.error(&quot;\u672a\u767b\u5f55\uff0c\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&quot;);return new ResponseBodyMessage&lt;&gt;(0,&quot;\u6ca1\u6709\u767b\u5f55&quot;,false);\/\/2.\u68c0\u67e5\u6570\u6570\u636e\u5e93\u4e2d\u662f\u5426\u6709\u6b64\u97f3\u4e50\/\/\u5f97\u5230\u6587\u4ef6\u7684\u540d\u5b57\u548c\u7c7b\u578b\/\/\u4ee5 . \u5c06\u540d\u5b57\u548c\u7c7b\u578b\u5206\u5f00\uff0c\u5f97\u5230title\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/39602.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-24T00:06:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000640-68310d90a8f8f.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39602.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/39602.html\",\"name\":\"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-24T00:06:48+00:00\",\"dateModified\":\"2025-05-24T00:06:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/39602.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/39602.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39602.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/39602.html","og_locale":"zh_CN","og_type":"article","og_title":"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb766\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u5bf9\u5e94\u6570\u636e\u5e93\u4e2d\u7684music\u8868\u7684\u5b57\u6bb5@Data\u5c06\u97f3\u4e50\u6587\u4ef6\u4e0a\u4f20\u5230\u8fd9\u4e2a\u8def\u5f84Slf4j@Autowired@Slf4j@Service@Autowired@Autowired\/\/\u6dfb\u52a0\u97f3\u4e50\/\/1.\u68c0\u67e5\u767b\u5f55log.error(&quot;\u672a\u767b\u5f55\uff0c\u8bf7\u5148\u8fdb\u884c\u767b\u5f55&quot;);return new ResponseBodyMessage&lt;&gt;(0,&quot;\u6ca1\u6709\u767b\u5f55&quot;,false);\/\/2.\u68c0\u67e5\u6570\u6570\u636e\u5e93\u4e2d\u662f\u5426\u6709\u6b64\u97f3\u4e50\/\/\u5f97\u5230\u6587\u4ef6\u7684\u540d\u5b57\u548c\u7c7b\u578b\/\/\u4ee5 . \u5c06\u540d\u5b57\u548c\u7c7b\u578b\u5206\u5f00\uff0c\u5f97\u5230title\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/39602.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-24T00:06:48+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250524000640-68310d90a8f8f.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"16 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/39602.html","url":"https:\/\/www.wsisp.com\/helps\/39602.html","name":"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-24T00:06:48+00:00","dateModified":"2025-05-24T00:06:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/39602.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/39602.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/39602.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u9879\u76ee\uff1a\u5728\u7ebf\u97f3\u4e50\u64ad\u653e\u670d\u52a1\u5668\u2014\u2014\u57fa\u4e8eSSM\u6846\u67b6\u548cmybatis"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=39602"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39602\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/39582"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=39602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=39602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=39602"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=39602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}